View Javadoc
1   package info.ejava.examples.secureping.client;
2   
3   import javax.ws.rs.client.ClientRequestContext;
4   import javax.ws.rs.client.ClientResponseContext;
5   import javax.ws.rs.client.ClientResponseFilter;
6   import javax.ws.rs.core.Response.StatusType;
7   
8   import org.slf4j.Logger;
9   import org.slf4j.LoggerFactory;
10  
11  public class LoggingFilter implements ClientResponseFilter {
12      private final Logger logger;
13      
14      public LoggingFilter(Logger logger) {
15          this.logger = logger;
16      }
17      public LoggingFilter() {
18          this(LoggerFactory.getLogger(LoggingFilter.class));
19      }
20      
21      @Override
22      public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) {
23          String method = requestContext.getMethod();
24          String uri = requestContext.getUri().toString();
25          StatusType status = responseContext.getStatusInfo();
26          logger.debug("{} {}, returned {}/{}\nhdrs sent: {}\nhdrs rcvd: {}", 
27                  method, uri, status.getStatusCode(), status, 
28                  requestContext.getStringHeaders(), 
29                  responseContext.getHeaders());
30      }
31  }