/
JettyServerAdapter.java
66 lines (55 loc) · 1.79 KB
/
JettyServerAdapter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2013, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
package ch.qos.logback.access.jetty;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
import ch.qos.logback.access.spi.ServerAdapter;
/**
* A jetty specific implementation of the {@link ServerAdapter} interface.
*
* @author Sébastien Pennec
* @author Ceki Gulcu
*/
public class JettyServerAdapter implements ServerAdapter {
Request request;
Response response;
public JettyServerAdapter(Request jettyRequest, Response jettyResponse) {
this.request = jettyRequest;
this.response = jettyResponse;
}
public long getContentLength() {
return response.getContentCount();
}
public int getStatusCode() {
return response.getStatus();
}
public long getRequestTimestamp() {
return request.getTimeStamp();
}
public Map<String, String> buildResponseHeaderMap() {
Map<String, String> responseHeaderMap = new HashMap<String, String>();
HttpFields httpFields = response.getHttpFields();
Enumeration e = httpFields.getFieldNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String value = response.getHeader(key);
responseHeaderMap.put(key, value);
}
return responseHeaderMap;
}
}