我正在使用jersey生成http请求,我希望能够在发送之前看到请求(出于调试目的)。
例如:
WebResource resource = client.resource(url);
resource.header("aa", "bb");
resource.getHeaders(); // Error: how can I do it?
感谢
答案 0 :(得分:9)
您可以使用LoggingFilter,如图所示here
答案 1 :(得分:-2)
您需要添加init-params,然后实现ContainerRequestFilter
将其放入web.xml
请注意,com.az.jersey.server.AuthFilter
是您已经实施上述接口的课程。
<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;
}