jersey.api.client.WebResource - how to debug/log the request headers
I a开发者_开发知识库m using jersey to generate http requests and I would like to be able to see the request before it is sent (for debugging purposes).
For example:
WebResource resource = client.resource(url);
resource.header("aa", "bb");
resource.getHeaders(); // Error: how can I do it?
thanks
You can use LoggingFilter, as shown here
You need to add init-params and then implement ContainerRequestFilter
Put it in your web.xml
Please note that com.az.jersey.server.AuthFilter
is your class that has implemented mentioned above interface.
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
<param-value>com.sun.jersey.api.container.filter.LoggingFilter;com.az.jersey.server.AuthFilter</param-value>
</init-param>
public class AuthFilter implements ContainerRequestFilter {
/**
* Apply the filter : check input request, validate or not with user auth
*
* @param containerRequest
* The request from Tomcat server
*/
@Override
public ContainerRequest filter(ContainerRequest containerRequest) throws WebApplicationException {
//GET, POST, PUT, DELETE, ...
String method = containerRequest.getMethod();
// myresource/get/56bCA for example
String path = containerRequest.getPath(true);
return containerRequest;
}
精彩评论