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.jetty;
15  
16  import ch.qos.logback.access.spi.ServerAdapter;
17  
18  import org.eclipse.jetty.http.HttpFields;
19  import org.eclipse.jetty.server.Request;
20  import org.eclipse.jetty.server.Response;
21  
22  import java.util.Enumeration;
23  import java.util.HashMap;
24  import java.util.Map;
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      @Override
43      public long getContentLength() {
44          return response.getContentCount();
45      }
46  
47      @Override
48      public int getStatusCode() {
49          return response.getStatus();
50      }
51  
52      @Override
53      public long getRequestTimestamp() {
54          return request.getTimeStamp();
55      }
56  
57      @Override
58      public Map<String, String> buildResponseHeaderMap() {
59          Map<String, String> responseHeaderMap = new HashMap<String, String>();
60          HttpFields httpFields = response.getHttpFields();
61          Enumeration<String> e = httpFields.getFieldNames();
62          while (e.hasMoreElements()) {
63              String key = (String) e.nextElement();
64              String value = response.getHeader(key);
65              responseHeaderMap.put(key, value);
66          }
67          return responseHeaderMap;
68      }
69  
70  }