-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make logback access logging work with Jetty 12
- Loading branch information
Showing
22 changed files
with
731 additions
and
435 deletions.
There are no files selected for viewing
67 changes: 0 additions & 67 deletions
67
logback-access/src/main/java/ch/qos/logback/access/jetty/JettyModernServerAdapter.java
This file was deleted.
Oops, something went wrong.
186 changes: 186 additions & 0 deletions
186
logback-access/src/main/java/ch/qos/logback/access/jetty/JettyNoServletApiServerAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
/** | ||
* Logback: the reliable, generic, fast and flexible logging framework. | ||
* Copyright (C) 1999-2024, QOS.ch. All rights reserved. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* or (per the licensee's choosing) | ||
* <p> | ||
* 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 ch.qos.logback.access.spi.ServerAdapter; | ||
import jakarta.servlet.http.Cookie; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.eclipse.jetty.http.HttpField; | ||
import org.eclipse.jetty.http.HttpHeader; | ||
import org.eclipse.jetty.server.Request; | ||
import org.eclipse.jetty.server.Response; | ||
import org.eclipse.jetty.server.Session; | ||
|
||
import java.util.Collections; | ||
import java.util.Enumeration; | ||
import java.util.stream.Collectors; | ||
|
||
public class JettyNoServletApiServerAdapter implements ServerAdapter { | ||
|
||
private final Request request; | ||
private final Response response; | ||
|
||
public JettyNoServletApiServerAdapter(Request jettyRequest, Response jettyResponse) { | ||
this.request = jettyRequest; | ||
this.response = jettyResponse; | ||
} | ||
|
||
@Override | ||
public long getResponseContentLength() { | ||
return Response.getContentBytesWritten(response); | ||
} | ||
|
||
@Override | ||
public int getStatusCode() { | ||
return Response.getOriginalResponse(response).getStatus(); | ||
} | ||
|
||
@Override | ||
public String getContentType() { | ||
return request.getHeaders().get(HttpHeader.CONTENT_TYPE); | ||
} | ||
|
||
@Override | ||
public String getRequestURI() { | ||
return request.getHttpURI().getCanonicalPath(); | ||
} | ||
|
||
@Override | ||
public String getQueryString() { | ||
return request.getHttpURI().getQuery(); | ||
} | ||
|
||
@Override | ||
public String getMethod() { | ||
return request.getMethod(); | ||
} | ||
|
||
@Override | ||
public String getProtocol() { | ||
return request.getConnectionMetaData().getProtocol(); | ||
} | ||
|
||
@Override | ||
public String getRemoteHost() { | ||
return Request.getRemoteAddr(request); | ||
} | ||
|
||
@Override | ||
public String getRemoteUser() { | ||
return request.getHttpURI().getUser(); | ||
} | ||
|
||
@Override | ||
public String getSessionId() { | ||
Session session = request.getSession(false); | ||
if (session != null) { | ||
return session.getId(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Object getSessionAttribute(String key) { | ||
Session session = request.getSession(false); | ||
if (session != null) { | ||
return session.getAttribute(key); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public int getLocalPort() { | ||
return Request.getLocalPort(request); | ||
} | ||
|
||
@Override | ||
public String getServerName() { | ||
return Request.getServerName(request); | ||
} | ||
|
||
@Override | ||
public String getRemoteAddr() { | ||
return Request.getRemoteAddr(request); | ||
} | ||
|
||
@Override | ||
public Enumeration<String> getHeaderNames() { | ||
return Collections.enumeration(request.getHeaders().stream().map(HttpField::getName).collect(Collectors.toList())); | ||
} | ||
|
||
@Override | ||
public String getHeader(String key) { | ||
return request.getHeaders().get(key); | ||
} | ||
|
||
@Override | ||
public Enumeration<String> getParameterNames() { | ||
try { | ||
return Collections.enumeration(Request.getParameters(request).getNames()); | ||
} catch (Exception e) { | ||
// We don't want to fail the logging due to exceptions on getting the parameters | ||
e.printStackTrace(); | ||
return Collections.emptyEnumeration(); | ||
} | ||
} | ||
|
||
@Override | ||
public String[] getParameterValues(String key) { | ||
try { | ||
return Request.getParameters(request).get(key).getValues().toArray(new String[0]); | ||
} catch (Exception e) { | ||
// We don't want to fail the logging due to exceptions on getting the parameters | ||
e.printStackTrace(); | ||
return new String[0]; | ||
} | ||
} | ||
|
||
@Override | ||
public Enumeration<String> getAttributeNames() { | ||
return Collections.enumeration(request.getConnectionMetaData().getAttributeNameSet()); | ||
} | ||
|
||
@Override | ||
public Object getAttribute(String key) { | ||
return request.getConnectionMetaData().getAttribute(key); | ||
} | ||
|
||
@Override | ||
public Cookie[] getCookies() { | ||
return Request.getCookies(request).stream().map(cookie -> new Cookie(cookie.getName(), cookie.getValue())).toArray(Cookie[]::new); | ||
} | ||
|
||
@Override | ||
public String getResponseType() { | ||
return response.getHeaders().get(HttpHeader.CONTENT_TYPE); | ||
} | ||
|
||
@Override | ||
public long getRequestTimestamp() { | ||
return Request.getTimeStamp(request); | ||
} | ||
|
||
@Override | ||
public HttpServletRequest getRequest() { | ||
// not available for recent jetty versions | ||
return null; | ||
} | ||
|
||
@Override | ||
public HttpServletResponse getResponse() { | ||
// not available for recent jetty versions | ||
return null; | ||
} | ||
} |
70 changes: 0 additions & 70 deletions
70
logback-access/src/main/java/ch/qos/logback/access/jetty/JettyServerAdapter.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.