how to log resteasy client request

2019-09-03 04:31发布

I need to know what is exactly the REST message body before sending it to client and also its response before processing, so I try to use Interceptors but unfortunately it is NOT working.

        @NameBinding
        public @interface DoIt {}

        @DoIt
        public class MyFilter implements ContainerRequestFilter {...}

        @Path("/root")
        public class MyResource {

           @GET
           @DoIt
           public String get() {...}
        }

I can not use wireshark to capture http messages because my server only accept Https requests.

I searched a lot and find many ways to logging, in Resteasy but most of them are old and deprecated and the new way as above is not working. anyone know how to solve the problem?

RestEasy 3.0.9

JBoss EAP 6.3 with updated restEasy to 3.0.9

Thanks

Edit:

I test @Privider for ContainerRequestFilter too.

also for my interface

@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(value = RetentionPolicy.RUNTIME)
@NameBinding

and also add this to web.xml

<context-param>
    <param-name>resteasy.providers</param-name>
    <param-value>com.mypackage.RequestMessageLogger</param-value>
</context-param>

still filter is not called.

1条回答
走好不送
2楼-- · 2019-09-03 05:17

Your ContainerRequestFilter is missing the @Provider annotation. From the api-docs:

Filters implementing this interface must be annotated with @Provider to be discovered by the JAX-RS runtime.

This should work:

@DoIt
@Provider
public class MyFilter implements ContainerRequestFilter {...}
查看更多
登录 后发表回答