This is an automated email from the ASF dual-hosted git repository. kfujino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push: new a08ac04 Added filtering expression for requests that are not supposed to use session. a08ac04 is described below commit a08ac04849a59e157433c3730c56db8a083765b4 Author: KeiichiFujino <kfuj...@apache.org> AuthorDate: Mon Aug 31 22:49:25 2020 +0900 Added filtering expression for requests that are not supposed to use session. --- .../apache/catalina/valves/LocalStrings.properties | 2 ++ .../apache/catalina/valves/PersistentValve.java | 33 ++++++++++++++++++++++ .../apache/catalina/valves/mbeans-descriptors.xml | 28 ++++++++++++++++++ webapps/docs/changelog.xml | 4 +++ 4 files changed, 67 insertions(+) diff --git a/java/org/apache/catalina/valves/LocalStrings.properties b/java/org/apache/catalina/valves/LocalStrings.properties index 7cf2d11..3379786 100644 --- a/java/org/apache/catalina/valves/LocalStrings.properties +++ b/java/org/apache/catalina/valves/LocalStrings.properties @@ -145,3 +145,5 @@ sslValve.invalidProvider=The SSL provider specified on the connector associated stuckThreadDetectionValve.notifyStuckThreadCompleted=Thread [{0}] (id=[{3}]) was previously reported to be stuck but has completed. It was active for approximately [{1}] milliseconds.{2,choice,0#|0< There is/are still [{2}] thread(s) that are monitored by this Valve and may be stuck.} stuckThreadDetectionValve.notifyStuckThreadDetected=Thread [{0}] (id=[{6}]) has been active for [{1}] milliseconds (since [{2}]) to serve the same request for [{4}] and may be stuck (configured threshold for this StuckThreadDetectionValve is [{5}] seconds). There is/are [{3}] thread(s) in total that are monitored by this Valve and may be stuck. stuckThreadDetectionValve.notifyStuckThreadInterrupted=Thread [{0}] (id=[{5}]) has been interrupted because it was active for [{1}] milliseconds (since [{2}]) to serve the same request for [{3}] and was probably stuck (configured interruption threshold for this StuckThreadDetectionValve is [{4}] seconds). + +persistentValve.filter.failure=Unable to compile filter=[{0}] \ No newline at end of file diff --git a/java/org/apache/catalina/valves/PersistentValve.java b/java/org/apache/catalina/valves/PersistentValve.java index 2da42e7..ac1df10 100644 --- a/java/org/apache/catalina/valves/PersistentValve.java +++ b/java/org/apache/catalina/valves/PersistentValve.java @@ -17,6 +17,8 @@ package org.apache.catalina.valves; import java.io.IOException; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletResponse; @@ -53,6 +55,7 @@ public class PersistentValve extends ValveBase { private volatile boolean clBindRequired; + protected Pattern filter = null; //------------------------------------------------------ Constructor @@ -89,6 +92,12 @@ public class PersistentValve extends ValveBase { public void invoke(Request request, Response response) throws IOException, ServletException { + // request without session + if (isRequestWithoutSession(request.getDecodedRequestURI())) { + getNext().invoke(request, response); + return; + } + // Select the Context to be used for this Request Context context = request.getContext(); if (context == null) { @@ -230,4 +239,28 @@ public class PersistentValve extends ValveBase { context.unbind(Globals.IS_SECURITY_ENABLED, MY_CLASSLOADER); } } + + protected boolean isRequestWithoutSession(String uri) { + Pattern f = filter; + return f != null && f.matcher(uri).matches(); + } + + public String getFilter() { + if (filter == null) { + return null; + } + return filter.toString(); + } + + public void setFilter(String filter) { + if (filter == null || filter.length() == 0) { + this.filter = null; + } else { + try { + this.filter = Pattern.compile(filter); + } catch (PatternSyntaxException pse) { + container.getLogger().error(sm.getString("persistentValve.filter.failure", filter), pse); + } + } + } } diff --git a/java/org/apache/catalina/valves/mbeans-descriptors.xml b/java/org/apache/catalina/valves/mbeans-descriptors.xml index 2517d27..41d1178 100644 --- a/java/org/apache/catalina/valves/mbeans-descriptors.xml +++ b/java/org/apache/catalina/valves/mbeans-descriptors.xml @@ -556,4 +556,32 @@ type="int"/> </mbean> + + <mbean name="PersistentValve" + description="Valve that implements per-request session persistence" + domain="Catalina" + group="Valve" + type="org.apache.catalina.valves.PersistentValve"> + + <attribute name="asyncSupported" + description="Does this valve support async reporting." + is="true" + type="boolean"/> + + <attribute name="className" + description="Fully qualified class name of the managed object" + type="java.lang.String" + writeable="false"/> + + <attribute name="stateName" + description="The name of the LifecycleState that this component is currently in" + type="java.lang.String" + writeable="false"/> + + <attribute + name="filter" + description="filter to disable session persistence" + type="java.lang.String"/> + + </mbean> </mbeans-descriptors> diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 26d7820..420cada 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -93,6 +93,10 @@ the <code>docBase</code> attribute of a <code>Context</code>. Note that such a configuration should be used with caution. (markt) </fix> + <add> + Added filtering expression for requests that are not supposed to use + session in <code>PersistentValve</code>. (kfujino) + </add> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org