ASM ByteCodeライブラリを使用して、HttpUrlConnection icが作成されたときにリクエストヘッダー(UUID)を追加します。以下は私のコードです-出力も取得しています===>これはHttp CONNECTメソッドです!。しかし、ヘッダーを追加する方法がわかりませんか?
package com.eg.agent;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
public class EgHttpMethodVisitorAdapter extends MethodVisitor {
private String methodName;
private String className;
private String description;
public EgHttpMethodVisitorAdapter(MethodVisitor mv , String methodName , String description , String className) {
super(Opcodes.ASM4, mv);
this.methodName = methodName;
this.className = className;
this.description = description;
}
public void visitCode() {
super.visitCode();
System.out.println("\t [HTTP URL CONNECTION - Method Name]"+methodName +" Class NAME: "+className + " DESC :"+description);
boolean isConnect = false;
if(methodName.equals("connect") && description.equals("()V"))
isConnect = true;
if(isConnect) {
mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
mv.visitLdcInsn (" ====> This is Http CONNECT Method!");
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream","println", "(Ljava/lang/String;)V");
}
}
public void visitMaxs(int maxStack, int maxLocals) {
super.visitMaxs(maxStack + 4, maxLocals);
}
}