我使用球衣來生成http請求,我希望能夠在發送(出於調試目的)之前看到請求。jersey.api.client.WebResource - 如何調試/記錄請求標頭
例如:
WebResource resource = client.resource(url);
resource.header("aa", "bb");
resource.getHeaders(); // Error: how can I do it?
感謝
我使用球衣來生成http請求,我希望能夠在發送(出於調試目的)之前看到請求。jersey.api.client.WebResource - 如何調試/記錄請求標頭
例如:
WebResource resource = client.resource(url);
resource.header("aa", "bb");
resource.getHeaders(); // Error: how can I do it?
感謝
您需要添加的init-PARAMS,然後實現ContainerRequestFilter
把它放在你web.xml
請注意,com.az.jersey.server.AuthFilter
是你的班級實施了提名d以上界面。的
<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;
}
可能重複的[澤西:打印實際的請求(http://stackoverflow.com/questions/6860661/jersey-print-the-actual-request) – mateuscb