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.common.spi.ServerAdapter;
17  import org.eclipse.jetty.server.Request;
18  import org.eclipse.jetty.server.Response;
19  
20  import java.util.Map;
21  
22  import static ch.qos.logback.access.jetty.HeaderUtil.buildHeaderMap;
23  
24  /**
25   * A jetty specific implementation of the {@link ServerAdapter} interface.
26   *
27   * @author Sébastien Pennec
28   * @author Ceki Gulcu
29   */
30  public class JettyServerAdapter implements ServerAdapter {
31  
32      Request request;
33      Response response;
34  
35      public JettyServerAdapter(Request jettyRequest, Response jettyResponse) {
36          this.request = jettyRequest;
37          this.response = jettyResponse;
38      }
39  
40      @Override
41      public long getContentLength() {
42          return Response.getContentBytesWritten(response);
43      }
44  
45      @Override
46      public int getStatusCode() {
47          return response.getStatus();
48      }
49  
50      @Override
51      public long getRequestTimestamp() {
52          return Request.getTimeStamp(request);
53      }
54  
55      @Override
56      public Map<String, String> buildResponseHeaderMap() {
57          return buildHeaderMap(response.getHeaders());
58      }
59  
60  }