Skip to content

Commit fdda8c8

Browse files
committed
Fix jakartaee#407 add identifiers for debug logging
1 parent 10adb52 commit fdda8c8

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (c) 2021 Contributors to the Eclipse Foundation.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
package jakarta.servlet;
17+
18+
/**
19+
* Provides information about the connection made to the Servlet container. This interface is intended primarily for
20+
* debugging purposes and as such provides the raw information as seen by the container. Unless explicitly stated
21+
* otherwise in the Javadoc for a method, no adjustment is made for the presence of reverse proxies or similar
22+
* configurations.
23+
*
24+
* @since Servlet 6.0
25+
*/
26+
public interface ServletConnection {
27+
28+
/**
29+
* Obtain a unique (within the lifetime of the JVM) identifier string for the network connection to the JVM that is
30+
* being used for the {@code ServletRequest} from which this {@code ServletConnection} was obtained.
31+
* <p>
32+
* There is no defined format for this string. The format is implementation dependent.
33+
*
34+
* @return A unique identifier for the network connection
35+
*/
36+
String getConnectionId();
37+
38+
/**
39+
* Obtain a unique (within the lifetime of the JVM) identifier string for the {@code ServletRequest} from which this
40+
* {@code ServletConnection} was obtained.
41+
* <p>
42+
* There is no defined format for this string. The format is implementation dependent.
43+
*
44+
* @return A unique identifier for the servlet request
45+
*/
46+
String getRequestId();
47+
48+
/**
49+
* Obtain the name of the protocol as presented to the JVM after the removal, if present, of any TLS encryption. This
50+
* may not be the same as the protocol seen by the application. For example, a reverse proxy may present AJP whereas the
51+
* application will see HTTP 1.1.
52+
* <p>
53+
* If the protocol has an entry in the <a href=
54+
* "https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids">IANA
55+
* registry for ALPN names then the identification sequence, in string form, must be returned. Registered identification
56+
* sequences MUST only be used for the associated protocol. Return values for other protocols are implementation
57+
* dependent. Unknown protocols should return the string "unknown".
58+
*
59+
* @return The name of the protocol presented to the JVM after decryption of TLS, if any.
60+
*/
61+
String getProtocol();
62+
63+
/**
64+
* Obtain the connection identifier for the network connection to the JVM that is being used for the
65+
* {@code ServletRequest} from which this {@code ServletConnection} was obtained as defined by the protocol in use. Note
66+
* that some protocols do not define such an identifier.
67+
*
68+
* @return The connection identifier if one is defined, otherwise an empty string
69+
*/
70+
String getProtocolConnectionId();
71+
72+
/**
73+
* Obtain the request identifier for the {@code ServletRequest} from which this {@code ServletConnection} was obtained
74+
* as defined by the protocol in use. Note that some protocols do not define such an identifier.
75+
*
76+
* @return The request identifier if one is defined, otherwise an empty string
77+
*/
78+
String getProtocolRequestId();
79+
80+
/**
81+
* Determine whether or not the incoming network connection to the JVM used TLS or not. Note that where a reverse proxy
82+
* is used, the application may have a different view as to whether TLS is being used due to the use of headers like
83+
* {@code X-Forwarded-Proto}
84+
*
85+
* @return {@code true} if the incoming network connection used TLS, otherwise {@code false}
86+
*/
87+
boolean getTLS();
88+
}

api/src/main/java/jakarta/servlet/ServletRequest.java

+10
Original file line numberDiff line numberDiff line change
@@ -576,4 +576,14 @@ public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse se
576576
*/
577577
public DispatcherType getDispatcherType();
578578

579+
/**
580+
* Obtain details of the network connection to the Servlet container that is being used by this request. The information
581+
* presented may differ from information presented elsewhere in the Servlet API as raw information is presented without
582+
* adjustments for, example, use of reverse proxies that may be applied elsewhere in the Servlet API.
583+
*
584+
* @return The network connection details.
585+
*
586+
* @since Servlet 6.0
587+
*/
588+
ServletConnection getServletConnection();
579589
}

api/src/main/java/jakarta/servlet/ServletRequestWrapper.java

+11
Original file line numberDiff line numberDiff line change
@@ -491,4 +491,15 @@ public DispatcherType getDispatcherType() {
491491
return request.getDispatcherType();
492492
}
493493

494+
/**
495+
* Gets the connection information for the wrapped request.
496+
*
497+
* @return the connection information for the wrapped request
498+
*
499+
* @since Servlet 6.0
500+
*/
501+
@Override
502+
public ServletConnection getServletConnection() {
503+
return request.getServletConnection();
504+
}
494505
}

0 commit comments

Comments
 (0)