View Javadoc

1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2011, 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 java.util.HashMap;
17  import java.util.Map;
18  
19  import org.apache.catalina.connector.Request;
20  import org.apache.catalina.connector.Response;
21  
22  import ch.qos.logback.access.spi.ServerAdapter;
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    public long getContentLength() {
40      return response.getContentLength();
41    }
42  
43    public int getStatusCode() {
44      return response.getStatus();
45    }
46  
47    
48    public Map<String, String> buildResponseHeaderMap() {
49      Map<String, String> responseHeaderMap = new HashMap<String, String>();
50      for (String key : response.getHeaderNames()) {
51        String value = response.getHeader(key);
52        responseHeaderMap.put(key, value);
53      }
54      return responseHeaderMap;
55    }
56  }