You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2025/02/24 13:51:42 UTC

(tomcat) branch main updated (e3d05323c5 -> 3cfc9bc048)

This is an automated email from the ASF dual-hosted git repository.

markt pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


    from e3d05323c5 Add specific test for TE parsing
     new 987f737afe Add connection ID to the ExtendedAccessLogValve
     new 3cfc9bc048 Add ConnectionID to AccessLogValve

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../catalina/valves/AbstractAccessLogValve.java    | 61 ++++++++++++++++++++--
 .../catalina/valves/ExtendedAccessLogValve.java    |  8 +++
 webapps/docs/changelog.xml                         |  7 +++
 webapps/docs/config/valve.xml                      |  3 ++
 4 files changed, 74 insertions(+), 5 deletions(-)


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


(tomcat) 01/02: Add connection ID to the ExtendedAccessLogValve

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 987f737afe4f08da939d870b5b1ec4b96010d926
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Feb 24 12:25:31 2025 +0000

    Add connection ID to the ExtendedAccessLogValve
---
 java/org/apache/catalina/valves/ExtendedAccessLogValve.java | 8 ++++++++
 webapps/docs/changelog.xml                                  | 6 ++++++
 webapps/docs/config/valve.xml                               | 1 +
 3 files changed, 15 insertions(+)

diff --git a/java/org/apache/catalina/valves/ExtendedAccessLogValve.java b/java/org/apache/catalina/valves/ExtendedAccessLogValve.java
index 28e6d2e5c6..819096df0e 100644
--- a/java/org/apache/catalina/valves/ExtendedAccessLogValve.java
+++ b/java/org/apache/catalina/valves/ExtendedAccessLogValve.java
@@ -70,6 +70,7 @@ import org.apache.tomcat.util.ExceptionUtils;
  * <li>For any of the x-H(...) the following method will be called from the HttpServletRequest object</li>
  * <li><code>x-H(authType)</code>: getAuthType</li>
  * <li><code>x-H(characterEncoding)</code>: getCharacterEncoding</li>
+ * <li><code>x-H(connectionId)</code>: getConnectionId</li>
  * <li><code>x-H(contentLength)</code>: getContentLength</li>
  * <li><code>x-H(locale)</code>: getLocale</li>
  * <li><code>x-H(protocol)</code>: getProtocol</li>
@@ -767,6 +768,13 @@ public class ExtendedAccessLogValve extends AccessLogValve {
                     buf.append(wrap("" + request.getContentLengthLong()));
                 }
             };
+        } else if ("connectionId".equals(parameter)) {
+            return new AccessLogElement() {
+                @Override
+                public void addElement(CharArrayWriter buf, Date date, Request request, Response response, long time) {
+                    buf.append(wrap("" + request.getServletConnection().getConnectionId()));
+                }
+            };
         } else if ("characterEncoding".equals(parameter)) {
             return new AccessLogElement() {
                 @Override
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index e24c2e8cc3..b9188c4249 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -159,6 +159,12 @@
         <code>HttpServletRequest.login(String username, String password)</code>
         when the realm is configured to use GSSAPI authentication. (markt)
       </fix>
+      <add>
+        Add support for logging the connection ID (as returned by
+        <code>ServletRequest.getServletConnection().getConnectionId()</code>)
+        with the <code>ExtendedAccessLogValve</code>. Based on pull request
+        <pr>814</pr> by Dmole. (markt)
+      </add>
     </changelog>
   </subsection>
   <subsection name="Coyote">
diff --git a/webapps/docs/config/valve.xml b/webapps/docs/config/valve.xml
index da28586791..09c346563d 100644
--- a/webapps/docs/config/valve.xml
+++ b/webapps/docs/config/valve.xml
@@ -477,6 +477,7 @@
     <ul>
     <li><b><code>x-H(authType)</code></b>: getAuthType </li>
     <li><b><code>x-H(characterEncoding)</code></b>: getCharacterEncoding </li>
+    <li><b><code>x-H(connectionId)</code></b>: getServletConnection().getConnectionId</li>
     <li><b><code>x-H(contentLength)</code></b>: getContentLength </li>
     <li><b><code>x-H(locale)</code></b>:  getLocale</li>
     <li><b><code>x-H(protocol)</code></b>: getProtocol </li>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


(tomcat) 02/02: Add ConnectionID to AccessLogValve

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 3cfc9bc048109c5a566fc24539e5bb9759c114b6
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Feb 24 12:55:08 2025 +0000

    Add ConnectionID to AccessLogValve
---
 .../catalina/valves/AbstractAccessLogValve.java    | 61 ++++++++++++++++++++--
 webapps/docs/changelog.xml                         |  5 +-
 webapps/docs/config/valve.xml                      |  2 +
 3 files changed, 61 insertions(+), 7 deletions(-)

diff --git a/java/org/apache/catalina/valves/AbstractAccessLogValve.java b/java/org/apache/catalina/valves/AbstractAccessLogValve.java
index a0f0163e9a..f6aeeb7e62 100644
--- a/java/org/apache/catalina/valves/AbstractAccessLogValve.java
+++ b/java/org/apache/catalina/valves/AbstractAccessLogValve.java
@@ -115,6 +115,8 @@ import org.apache.tomcat.util.net.IPv6Utils;
  * <li><code>%{xxx}s</code> xxx is an attribute in the HttpSession
  * <li><code>%{xxx}t</code> xxx is an enhanced SimpleDateFormat pattern (see Configuration Reference document for
  * details on supported time patterns)
+ * <li><code>%{xxx}L</code> xxx is the identifier to log (see Configuration Reference document for details on supported
+ * identifiers)
  * <li><code>%{xxx}T</code> xxx is the unit for the time taken to process the request (see Configuration Reference
  * document for details on supported units)
  * </ul>
@@ -167,7 +169,12 @@ public abstract class AbstractAccessLogValve extends ValveBase implements Access
         PEER
     }
 
-    // ------------------------------------------------------ Constructor
+    private enum IdentifierType {
+        CONNECTION,
+        UNKNOWN
+    }
+
+
     public AbstractAccessLogValve() {
         super(true);
     }
@@ -1675,6 +1682,48 @@ public abstract class AbstractAccessLogValve extends ValveBase implements Access
         }
     }
 
+
+
+    /**
+     * Write identifier element %{xxx}L
+     */
+    protected class IdentifierElement implements AccessLogElement {
+
+        /**
+         * Type of identifier to log
+         */
+        private final IdentifierType identifierType;
+
+        public IdentifierElement() {
+            this(null);
+        }
+
+
+        public IdentifierElement(String type) {
+            switch (type) {
+                case "c":
+                    identifierType = IdentifierType.CONNECTION;
+                    break;
+                default:
+                    log.error(sm.getString("accessLogValve.invalidIdentifierType", type));
+                    identifierType = IdentifierType.UNKNOWN;
+                    break;
+            }
+        }
+
+        @Override
+        public void addElement(CharArrayWriter buf, Date date, Request request, Response response, long time) {
+            switch(identifierType) {
+                case CONNECTION:
+                    buf.append(request.getServletConnection().getConnectionId());
+                    break;
+                case UNKNOWN:
+                    buf.append("???");
+            }
+        }
+    }
+
+
     /**
      * Parse pattern string and create the array of AccessLogElement.
      *
@@ -1747,14 +1796,16 @@ public abstract class AbstractAccessLogValve extends ValveBase implements Access
      */
     protected AccessLogElement createAccessLogElement(String name, char pattern) {
         switch (pattern) {
-            case 'i':
-                return new HeaderElement(name);
+            case 'a':
+                return new RemoteAddrElement(name);
             case 'c':
                 return new CookieElement(name);
+            case 'i':
+                return new HeaderElement(name);
+            case 'L':
+                return new IdentifierElement(name);
             case 'o':
                 return new ResponseHeaderElement(name);
-            case 'a':
-                return new RemoteAddrElement(name);
             case 'p':
                 return new PortElement(name);
             case 'r':
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index b9188c4249..5f0741cc28 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -162,8 +162,9 @@
       <add>
         Add support for logging the connection ID (as returned by
         <code>ServletRequest.getServletConnection().getConnectionId()</code>)
-        with the <code>ExtendedAccessLogValve</code>. Based on pull request
-        <pr>814</pr> by Dmole. (markt)
+        with the <code>AccessLogValve</code> and
+        <code>ExtendedAccessLogValve</code>. Based on pull request <pr>814</pr>
+        by Dmole. (markt)
       </add>
     </changelog>
   </subsection>
diff --git a/webapps/docs/config/valve.xml b/webapps/docs/config/valve.xml
index 09c346563d..add9753ecf 100644
--- a/webapps/docs/config/valve.xml
+++ b/webapps/docs/config/valve.xml
@@ -337,6 +337,8 @@
         remote (client) port (<code>xxx=remote</code>)</li>
     <li><b><code>%{xxx}t</code></b> write timestamp at the end of the request formatted using the
         enhanced SimpleDateFormat pattern <code>xxx</code></li>
+    <li><b><code>%{xxx}L</code></b> write an identifier associated with the request where the only valid value for
+        <code>xxx</code> is <code>c</code> for connection.</li>
     <li><b><code>%{xxx}T</code></b> write time taken to process the request using unit <code>xxx</code>
         where valid units are <code>ns</code> for nanoseconds, <code>us</code> for microseconds,
         <code>ms</code> for milliseconds, <code>fracsec</code> for fractional seconds, or <code>s</code> for whole seconds.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org