Reputation: 51
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
Upvotes: 3
Views: 920
Reputation: 51
Managed to find the solution myself.
new ByteBuddy( )
.withAttribute( new TypeAttributeAppender.ForInstrumentedType( AnnotationAppender.ValueFilter.AppendDefaults.INSTANCE ) )
.withDefaultMethodAttributeAppender( new MethodAttributeAppender.ForInstrumentedMethod(AnnotationAppender.ValueFilter.AppendDefaults.INSTANCE ) )
will do the trick.
Br, Paci
Upvotes: 2