我尝试截取或通知构造函数调用,如下所示:
new AgentBuilder.Default()
//.disableClassFormatChanges()
.with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
.with(AgentBuilder.TypeStrategy.Default.REDEFINE)
.type(ElementMatchers.nameMatches("org.openqa.selenium.firefox.FirefoxDriver"))
.transform((builder, typeDescription, classLoader, module) -> builder
.constructor(ElementMatchers.any())
.intercept(SuperMethodCall.INSTANCE.andThen(MethodDelegation.to(FirefoxDriverInterceptor.class))))
//.intercept(SuperMethodCall.INSTANCE.andThen(Advice.to(FirefoxDriverConstructorAdvice.class))))拦截器:
@RuntimeType
public static void intercept(@Origin Constructor<?> constructor) {
System.out.println("Intercepted: " + constructor.getName());
}建议:
@Advice.OnMethodExit
public static void after(//@Advice.This Object thisObject,
@Advice.Origin String method,
@Advice.AllArguments Object[] args
) {
logger.info("<----- instantiated firefoxwebdriver: {}", method);
}在尝试拦截器或通知时,异常抛出是:
java.lang.IllegalStateException: Cannot call super (or default) method for public org.openqa.selenium.firefox.FirefoxDriver(org.openqa.selenium.firefox.GeckoDriverService,org.openqa.selenium.Capabilities)
at net.bytebuddy.implementation.SuperMethodCall$Appender.apply(SuperMethodCall.java:102)
at net.bytebuddy.implementation.bytecode.ByteCodeAppender$Compound.apply(ByteCodeAppender.java:134)请让我知道反对的意见。谢谢你的帮助。
发布于 2021-07-13 04:16:35
你在这里混合了Advice和MethodDelegation,它们是不相关的。它们有一些共同的概念,但您不能混合注释。
但是,您可以围绕委托提供建议:
Advice.to(...).wrap(MethodDelegation.to(...))https://stackoverflow.com/questions/68234353
复制相似问题