![](/img/trans.png)
[英]How can I instrument/intercept Method.invoke in a ByteBuddy agent?
[英]How do I instrument HttpURLConnection using Bytebuddy?
我正在使用Bytebuddy攔截HttpURLConnection的某些方法並添加跟蹤。 我編寫了以下代碼:
File temp = Files.createTempDirectory("tmp").toFile();
new AgentBuilder.Default().ignore(none())
.enableBootstrapInjection(inst, temp)
.type(hasSuperType(is(HttpURLConnection.class)))
.transform(new AgentBuilder.Transformer.ForAdvice()
.include(HttpURLConnection.class.getClassLoader())
.advice(named("setRequestMethod"), HttpURLIntercept.class.getName()))
.installOn(inst);
但是,該方法從未使用過。
我知道HttpURLConnection加載在引導程序上。 我如何仍可以對其進行檢測?
默認情況下,Byte Buddy忽略引導類加載器。 定義一個不包含HttpUrlConnection的其他忽略匹配器,以避免此排斥。 請注意,JVM本身定義了成千上萬個類,這些類全部加載到引導加載程序中,如果您沒有有效地排除大多數引導類,則JVM stsrtup會變得非常慢。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.