This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 489288341c Add attribute for error status code
489288341c is described below
commit 489288341c106b0e498fa8ca2721528cb4e3b48a
Author: remm <[email protected]>
AuthorDate: Mon Mar 11 15:24:41 2024 +0100
Add attribute for error status code
Part 1 of BZ 60997.
Although subclasses can do it (that is the design of the valve), it
seems very reasonable/simple to add it.
---
java/org/apache/catalina/valves/SemaphoreValve.java | 19 ++++++++++++++++++-
webapps/docs/changelog.xml | 10 ++++++++++
webapps/docs/config/valve.xml | 7 +++++++
3 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/java/org/apache/catalina/valves/SemaphoreValve.java
b/java/org/apache/catalina/valves/SemaphoreValve.java
index 66b03d7868..4b2e2ce7de 100644
--- a/java/org/apache/catalina/valves/SemaphoreValve.java
+++ b/java/org/apache/catalina/valves/SemaphoreValve.java
@@ -113,6 +113,21 @@ public class SemaphoreValve extends ValveBase {
}
+ /**
+ * High concurrency status. This status code is returned as an
+ * error if concurrency is too high.
+ */
+ protected int highConcurrencyStatus = -1;
+
+ public int getHighConcurrencyStatus() {
+ return this.highConcurrencyStatus;
+ }
+
+ public void setHighConcurrencyStatus(int highConcurrencyStatus) {
+ this.highConcurrencyStatus = highConcurrencyStatus;
+ }
+
+
/**
* Start this component and implement the requirements of
* {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
@@ -213,7 +228,9 @@ public class SemaphoreValve extends ValveBase {
* @throws ServletException Other error
*/
public void permitDenied(Request request, Response response) throws
IOException, ServletException {
- // NO-OP by default
+ if (highConcurrencyStatus > 0) {
+ response.sendError(highConcurrencyStatus);
+ }
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index cf21f8c98f..d8842e1476 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -105,6 +105,16 @@
issues do not "pop up" wrt. others).
-->
<section name="Tomcat 9.0.88 (remm)" rtext="in development">
+ <subsection name="Catalina">
+ <changelog>
+ <update>
+ Add <code>highConcurrencyStatus</code> attribute to the
+ <code>SemaphoreValve</code> to optionally allow the valve to return an
+ error status code to the client when a permit cannot be acquired from
+ the semaphore. (remm)
+ </update>
+ </changelog>
+ </subsection>
</section>
<section name="Tomcat 9.0.87 (remm)" rtext="release in progress">
<subsection name="Catalina">
diff --git a/webapps/docs/config/valve.xml b/webapps/docs/config/valve.xml
index d71997d32c..f4a862ba1a 100644
--- a/webapps/docs/config/valve.xml
+++ b/webapps/docs/config/valve.xml
@@ -2556,6 +2556,13 @@
<strong>false</strong>.</p>
</attribute>
+ <attribute name="highConcurrencyStatus" required="false">
+ <p>The error status code which will be returned to the client, if the
+ value is positive, when a permit cannot be acquired from the
+ sepmaphore. The default value is <strong>-1</strong>, which will mean
+ no error status will be sent back.</p>
+ </attribute>
+
<attribute name="interruptible" required="false">
<p>Flag to determine if a thread may be interrupted until a permit is
available. The default value is <strong>false</strong>.</p>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]