how to log resteasy client request

﹥>﹥吖頭↗ 提交于 2020-01-17 04:18:18

问题


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:


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 {...}


来源:https://stackoverflow.com/questions/31240026/how-to-log-resteasy-client-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!