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 2023/08/16 15:03:20 UTC
[tomcat] branch 8.5.x updated (87c291f7a6 -> f7bf4083fc)
This is an automated email from the ASF dual-hosted git repository.
markt pushed a change to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
from 87c291f7a6 Remove unnecessary uses of {@inheritDoc}
new 36114bc3c2 Refactor into individual tests
new b4be016ee0 Update certificate for user1
new f7bf4083fc Use application provided status code for error page if present
The 3 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:
.../apache/catalina/core/StandardHostValve.java | 13 ++--
.../catalina/core/TestStandardHostValve.java | 72 +++++++++++++++------
test/org/apache/tomcat/util/net/user1.jks | Bin 2668 -> 4386 bytes
webapps/docs/changelog.xml | 10 +++
4 files changed, 72 insertions(+), 23 deletions(-)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[tomcat] 02/03: Update certificate for user1
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit b4be016ee0fd5aaae92b4234330ab2f1637caf73
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Aug 16 15:40:42 2023 +0100
Update certificate for user1
---
test/org/apache/tomcat/util/net/user1.jks | Bin 2668 -> 4386 bytes
1 file changed, 0 insertions(+), 0 deletions(-)
diff --git a/test/org/apache/tomcat/util/net/user1.jks b/test/org/apache/tomcat/util/net/user1.jks
index efbade83df..1643506742 100644
Binary files a/test/org/apache/tomcat/util/net/user1.jks and b/test/org/apache/tomcat/util/net/user1.jks differ
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[tomcat] 01/03: Refactor into individual tests
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 36114bc3c2e78aa77bbcf3af9ff9e678d52ebb8c
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Aug 16 14:23:01 2023 +0100
Refactor into individual tests
---
.../catalina/core/TestStandardHostValve.java | 41 ++++++++++++----------
1 file changed, 23 insertions(+), 18 deletions(-)
diff --git a/test/org/apache/catalina/core/TestStandardHostValve.java b/test/org/apache/catalina/core/TestStandardHostValve.java
index b706f41b53..99d82f3331 100644
--- a/test/org/apache/catalina/core/TestStandardHostValve.java
+++ b/test/org/apache/catalina/core/TestStandardHostValve.java
@@ -40,7 +40,20 @@ import org.apache.tomcat.util.descriptor.web.ErrorPage;
public class TestStandardHostValve extends TomcatBaseTest {
@Test
- public void testErrorPageHandling() throws Exception {
+ public void testErrorPageHandling500() throws Exception {
+ doTestErrorPageHandling(500, "/500");
+ }
+
+
+ @Test
+ public void testErrorPageHandlingDefault() throws Exception {
+ doTestErrorPageHandling(501, "/default");
+ }
+
+
+ private void doTestErrorPageHandling(int error, String report)
+ throws Exception {
+
// Set up a container
Tomcat tomcat = getTomcatInstance();
@@ -68,8 +81,13 @@ public class TestStandardHostValve extends TomcatBaseTest {
tomcat.start();
- doTestErrorPageHandling(500, "/500");
- doTestErrorPageHandling(501, "/default");
+ // Request a page that triggers an error
+ ByteChunk bc = new ByteChunk();
+ int rc = getUrl("http://localhost:" + getPort() +
+ "/error?errorCode=" + error, bc, null);
+
+ Assert.assertEquals(error, rc);
+ Assert.assertEquals(report, bc.toString());
}
@@ -131,19 +149,6 @@ public class TestStandardHostValve extends TomcatBaseTest {
}
- private void doTestErrorPageHandling(int error, String report)
- throws Exception {
-
- // Request a page that triggers an error
- ByteChunk bc = new ByteChunk();
- int rc = getUrl("http://localhost:" + getPort() +
- "/error?errorCode=" + error, bc, null);
-
- Assert.assertEquals(error, rc);
- Assert.assertEquals(report, bc.toString());
- }
-
-
@Test
public void testIncompleteResponse() throws Exception {
// Set up a container
@@ -160,13 +165,13 @@ public class TestStandardHostValve extends TomcatBaseTest {
Tomcat.addServlet(ctx, "report", new ReportServlet());
ctx.addServletMappingDecoded("/report/*", "report");
- // And the handling for 500 responses
+ // Add the handling for 500 responses
ErrorPage errorPage500 = new ErrorPage();
errorPage500.setErrorCode(Response.SC_INTERNAL_SERVER_ERROR);
errorPage500.setLocation("/report/500");
ctx.addErrorPage(errorPage500);
- // And the default error handling
+ // Add the default error handling
ErrorPage errorPageDefault = new ErrorPage();
errorPageDefault.setLocation("/report/default");
ctx.addErrorPage(errorPageDefault);
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: [tomcat] 03/03: Use application provided status code for error page if present
Posted by Michael Osipov <mi...@apache.org>.
On 2023/08/16 15:03:23 markt@apache.org wrote:
> This is an automated email from the ASF dual-hosted git repository.
>
> markt pushed a commit to branch 8.5.x
> in repository https://gitbox.apache.org/repos/asf/tomcat.git
> diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
> index 99479d5486..a872539027 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 8.5.92 (schultz)" rtext="in development">
> + <subsection name="Catalina">
> + <changelog>
> + <fix>
> + If an application or library sets both a non-500 error code and the
> + <code>jakarta.servlet.error.exception</code> request attribute, use the
> + provided error code during error page processing rather than assuming an
> + error code of 500. (markt)
> + </fix>
> + </changelog>
> + </subsection>
> </section>
This looks wrong: jakarta.servlet.error.exception
Please fix for non-jakarta versions.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[tomcat] 03/03: Use application provided status code for error page if present
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit f7bf4083fca9ea48a61006c396a09997b76ef728
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Aug 16 15:57:31 2023 +0100
Use application provided status code for error page if present
---
.../apache/catalina/core/StandardHostValve.java | 13 ++++---
.../catalina/core/TestStandardHostValve.java | 41 +++++++++++++++++++---
webapps/docs/changelog.xml | 10 ++++++
3 files changed, 54 insertions(+), 10 deletions(-)
diff --git a/java/org/apache/catalina/core/StandardHostValve.java b/java/org/apache/catalina/core/StandardHostValve.java
index 3b50dfefee..584f59abcd 100644
--- a/java/org/apache/catalina/core/StandardHostValve.java
+++ b/java/org/apache/catalina/core/StandardHostValve.java
@@ -308,11 +308,14 @@ final class StandardHostValve extends ValveBase {
}
}
} else {
- // A custom error-page has not been defined for the exception
- // that was thrown during request processing. Check if an
- // error-page for error code 500 was specified and if so,
- // send that page back as the response.
- response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ /*
+ * A custom error-page has not been defined for the exception that was thrown during request processing.
+ * Set the status to 500 if an error status has not already been set and check for custom error-page for
+ * the status.
+ */
+ if (response.getStatus() < HttpServletResponse.SC_BAD_REQUEST) {
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
// The response is an error
response.setError();
diff --git a/test/org/apache/catalina/core/TestStandardHostValve.java b/test/org/apache/catalina/core/TestStandardHostValve.java
index 99d82f3331..efd3a4a1d9 100644
--- a/test/org/apache/catalina/core/TestStandardHostValve.java
+++ b/test/org/apache/catalina/core/TestStandardHostValve.java
@@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
@@ -39,19 +40,31 @@ import org.apache.tomcat.util.descriptor.web.ErrorPage;
public class TestStandardHostValve extends TomcatBaseTest {
+ @Test
+ public void testErrorPageHandling400() throws Exception {
+ doTestErrorPageHandling(400, "", "/400");
+ }
+
+
+ @Test
+ public void testErrorPageHandling400WithException() throws Exception {
+ doTestErrorPageHandling(400, "java.lang.IllegalStateException", "/400");
+ }
+
+
@Test
public void testErrorPageHandling500() throws Exception {
- doTestErrorPageHandling(500, "/500");
+ doTestErrorPageHandling(500, "", "/500");
}
@Test
public void testErrorPageHandlingDefault() throws Exception {
- doTestErrorPageHandling(501, "/default");
+ doTestErrorPageHandling(501, "", "/default");
}
- private void doTestErrorPageHandling(int error, String report)
+ private void doTestErrorPageHandling(int error, String exception, String report)
throws Exception {
// Set up a container
@@ -68,6 +81,12 @@ public class TestStandardHostValve extends TomcatBaseTest {
Tomcat.addServlet(ctx, "report", new ReportServlet());
ctx.addServletMappingDecoded("/report/*", "report");
+ // Add the handling for 400 responses
+ ErrorPage errorPage400 = new ErrorPage();
+ errorPage400.setErrorCode(Response.SC_BAD_REQUEST);
+ errorPage400.setLocation("/report/400");
+ ctx.addErrorPage(errorPage400);
+
// And the handling for 500 responses
ErrorPage errorPage500 = new ErrorPage();
errorPage500.setErrorCode(Response.SC_INTERNAL_SERVER_ERROR);
@@ -83,8 +102,8 @@ public class TestStandardHostValve extends TomcatBaseTest {
// Request a page that triggers an error
ByteChunk bc = new ByteChunk();
- int rc = getUrl("http://localhost:" + getPort() +
- "/error?errorCode=" + error, bc, null);
+ int rc = getUrl("http://localhost:" + getPort() + "/error?errorCode=" + error + "&exception=" + exception,
+ bc, null);
Assert.assertEquals(error, rc);
Assert.assertEquals(report, bc.toString());
@@ -200,6 +219,18 @@ public class TestStandardHostValve extends TomcatBaseTest {
throws ServletException, IOException {
int error = Integer.parseInt(req.getParameter("errorCode"));
resp.sendError(error);
+
+ Throwable t = null;
+ String exception = req.getParameter("exception");
+ if (exception != null && exception.length() > 0) {
+ try {
+ t = (Throwable) Class.forName(exception).getConstructor().newInstance();
+ } catch (ReflectiveOperationException e) {
+ // Should never happen but in case it does...
+ t = new IllegalArgumentException();
+ }
+ req.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
+ }
}
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 99479d5486..a872539027 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 8.5.92 (schultz)" rtext="in development">
+ <subsection name="Catalina">
+ <changelog>
+ <fix>
+ If an application or library sets both a non-500 error code and the
+ <code>jakarta.servlet.error.exception</code> request attribute, use the
+ provided error code during error page processing rather than assuming an
+ error code of 500. (markt)
+ </fix>
+ </changelog>
+ </subsection>
</section>
<section name="Tomcat 8.5.92 (markt)" rtext="2023-08-14">
<subsection name="Catalina">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org