简体   繁体   English

如何使用Bytebuddy检测HttpURLConnection?

[英]How do I instrument HttpURLConnection using Bytebuddy?

I'm using Bytebuddy to intercept some method of HttpURLConnection and add tracing. 我正在使用Bytebuddy拦截HttpURLConnection的某些方法并添加跟踪。 I've written the following code: 我编写了以下代码:

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);

But the method is never instrumented. 但是,该方法从未使用过。

I know that HttpURLConnection is loaded on bootstrap. 我知道HttpURLConnection加载在引导程序上。 How can I still instrument it? 我如何仍可以对其进行检测?

By default, Byte Buddy ignores the bootstrap class loader. 默认情况下,Byte Buddy忽略引导类加载器。 Define a different ignore matcher that does not include HttpUrlConnection to avoid this exclusion. 定义一个不包含HttpUrlConnection的其他忽略匹配器,以避免此排斥。 Note that the JVM defines mant thousand classes itself that are all loaded on the bootstrap loader where JVM stsrtup becomes very slow if you do not exclude most bootstrap classes efficiently. 请注意,JVM本身定义了成千上万个类,这些类全部加载到引导加载程序中,如果您没有有效地排除大多数引导类,则JVM stsrtup会变得非常慢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM