2011-08-22 39 views
5

Tôi đang sử dụng áo để tạo yêu cầu http và tôi muốn có thể xem yêu cầu trước khi gửi (cho mục đích gỡ lỗi).jersey.api.client.WebResource - cách gỡ lỗi/ghi nhật ký yêu cầu

Ví dụ:

WebResource resource = client.resource(url); 
resource.header("aa", "bb"); 
resource.getHeaders(); // Error: how can I do it? 

nhờ

+0

thể trùng lặp của [Jersey: In theo yêu cầu thực tế] (http://stackoverflow.com/questions/6860661/jersey-print-the-actual-request) – mateuscb

Trả lời

9

Bạn có thể sử dụng LoggingFilter, như here

+0

Đây là đứng về phía khách hàng. Làm thế nào nó có thể được thực hiện trên phía máy chủ? –

-2

Bạn cần phải thêm init-params và sau đó thực hiện ContainerRequestFilter

Đặt nó trong bạn web.xml Xin lưu ý rằng com.az.jersey.server.AuthFilter là lớp học của bạn đã thực hiện đề cập đến d trên giao diện.

<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; 
    } 
Các vấn đề liên quan