3

I have a bunch of WebServices running on plain JDK and I need to intercept all public methods in order to do something. Some methods are using @WebParam annotation. Subclassing the WebService with ByteBuddy drops the @WebParam annotation from the overriding method and the service doesn't work anymore as expected.

Here's a sample signature

public Something fetch( @WebParam( name="Query" ) QueryCriteria query )

And here's how I'm using ByteBuddy

new ByteBuddy( )
    .subclass( implementationClass )
    .method( isPublic( ).and( isDeclaredBy( implementationClass ) ) )
    .intercept( 
            MethodDelegation.to( new WebServiceInterceptor( ) )
            .andThen( SuperMethodCall.INSTANCE ) )
    .annotateType( implementationClass.getAnnotations( ) )
    .make( )

I know there's a way to annotate parameters, but it requires special knowledge about the method parameters (because only some params are annotated). What I'd would like to do is just to ask ByteBuddy to annotate my class exactly the same way as superclass including all parameters of all overridden methods.

subclass( implementationClass )
.annotateType( LIKE_SUPERCLASS )
.method( )
.intercept( ... )
.annotateMethod( LIKE_SUPER_INCLUDING_PARAMS )

Any ideas?

BR, Paci

4

1 回答 1

2

设法自己找到解决方案。

new ByteBuddy( )
    .withAttribute( new TypeAttributeAppender.ForInstrumentedType( AnnotationAppender.ValueFilter.AppendDefaults.INSTANCE ) )
    .withDefaultMethodAttributeAppender( new MethodAttributeAppender.ForInstrumentedMethod(AnnotationAppender.ValueFilter.AppendDefaults.INSTANCE ) )

会成功的。

兄弟,帕西

于 2015-10-15T17:26:20.180 回答