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.jetty;
15  
16  import java.util.Enumeration;
17  import java.util.HashMap;
18  import java.util.Map;
19  
20  import org.eclipse.jetty.http.HttpFields;
21  import org.eclipse.jetty.server.Request;
22  import org.eclipse.jetty.server.Response;
23  
24  import ch.qos.logback.access.spi.ServerAdapter;
25  
26  /**
27   * A jetty specific implementation of the {@link ServerAdapter} interface.
28   * 
29   * @author Sébastien Pennec
30   * @author Ceki Gulcu
31   */
32  public class JettyServerAdapter implements ServerAdapter {
33  
34    Request request;
35    Response response;
36    
37    public JettyServerAdapter(Request jettyRequest, Response jettyResponse) {
38      this.request = jettyRequest;
39      this.response = jettyResponse;
40    }
41  
42    public long getContentLength() {
43      return response.getContentCount();
44    }
45  
46    public int getStatusCode() {
47      return response.getStatus();
48    }
49  
50    public Map<String, String> buildResponseHeaderMap() {
51      Map<String, String> responseHeaderMap = new HashMap<String, String>();
52      HttpFields httpFields = response.getHttpFields();
53      Enumeration e = httpFields.getFieldNames();
54      while (e.hasMoreElements()) {
55        String key = (String) e.nextElement();
56        String value = response.getHeader(key);
57        responseHeaderMap.put(key, value);
58      }
59      return responseHeaderMap;
60    }
61    
62  }