Skip to content

Commit ca0cf17

Browse files
authored
Merge pull request #532 from joakime/fix-jetty-requestlog
Fixing behavior of logback-access in the modern era
2 parents e31609b + 453f597 commit ca0cf17

File tree

5 files changed

+296
-90
lines changed

5 files changed

+296
-90
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 java.util.HashMap;
17+
import java.util.Iterator;
18+
import java.util.Map;
19+
20+
import ch.qos.logback.access.spi.ServerAdapter;
21+
import org.eclipse.jetty.http.HttpField;
22+
import org.eclipse.jetty.server.Request;
23+
import org.eclipse.jetty.server.Response;
24+
25+
/**
26+
* A Jetty 9.4.x and 10.0.x specific implementation of the {@link ServerAdapter} interface.
27+
*
28+
* @author Sébastien Pennec
29+
* @author Ceki Gulcu
30+
* @author Joakim Erdfelt
31+
*/
32+
public class JettyModernServerAdapter extends JettyServerAdapter
33+
{
34+
public JettyModernServerAdapter(Request jettyRequest, Response jettyResponse) {
35+
super(jettyRequest, jettyResponse);
36+
}
37+
38+
@Override
39+
public long getContentLength() {
40+
return response.getHttpChannel().getBytesWritten();
41+
}
42+
43+
@Override
44+
public int getStatusCode() {
45+
return response.getCommittedMetaData().getStatus();
46+
}
47+
48+
@Override
49+
public long getRequestTimestamp() {
50+
return request.getTimeStamp();
51+
}
52+
53+
@Override
54+
public Map<String, String> buildResponseHeaderMap() {
55+
Map<String, String> responseHeaderMap = new HashMap<String, String>();
56+
Iterator<HttpField> httpFieldIter = response.getHttpFields().iterator();
57+
while (httpFieldIter.hasNext()) {
58+
HttpField httpField = httpFieldIter.next();
59+
String key = httpField.getName();
60+
String value = httpField.getValue();
61+
responseHeaderMap.put(key, value);
62+
}
63+
return responseHeaderMap;
64+
}
65+
66+
}

0 commit comments

Comments
 (0)