View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.access.tomcat;
15  
16  import ch.qos.logback.access.spi.ServerAdapter;
17  
18  import org.apache.catalina.connector.Request;
19  import org.apache.catalina.connector.Response;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  /**
25   * A tomcat specific implementation of the {@link ServerAdapter} interface.
26   *
27   * @author Sébastien Pennec
28   */
29  public class TomcatServerAdapter implements ServerAdapter {
30  
31      Request request;
32      Response response;
33  
34      public TomcatServerAdapter(Request tomcatRequest, Response tomcatResponse) {
35          this.request = tomcatRequest;
36          this.response = tomcatResponse;
37      }
38  
39      @Override
40      public long getContentLength() {
41          return response.getContentLength();
42      }
43  
44      @Override
45      public int getStatusCode() {
46          return response.getStatus();
47      }
48  
49      @Override
50      public long getRequestTimestamp() {
51          return request.getCoyoteRequest().getStartTime();
52      }
53  
54      @Override
55      public Map<String, String> buildResponseHeaderMap() {
56          Map<String, String> responseHeaderMap = new HashMap<String, String>();
57          for (String key : response.getHeaderNames()) {
58              String value = response.getHeader(key);
59              responseHeaderMap.put(key, value);
60          }
61          return responseHeaderMap;
62      }
63  }