-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Description
Statement:
The error handling for 404 errors (or general error pages) seems to not be working. If a contextPath is set, all servlets are initialised with this context path and there is nothing handling URL requests for URLs that do not match the context path.
Bug Report:
I created a demo project using the spring boot intialiser with jersey:
Versions:
spring-boot-starter-jersey:1.5.8.RELEASE
spring-boot-starter-test:1.5.8.RELEASE
I created a simple setup that creates a REST Application such as this:
@Component
public class ResourceConfig extends org.glassfish.jersey.server.ResourceConfig {
public ResourceConfig() {
register(HW.class);
}
@Path("test")
public static class HW {
@GET
public String test() {
return "Hello test";
}
}
}
I set the context path to:
server.contextPath=/mainstay
The server starts and it will now use the default error page registered with tomcat for any 404 after `localhost:8080/mainstay' and it will respond with a random 404 error for all other requests that do not match the prefix.
On curl:
Success:
curl localhost:8080/mainstay/test -v
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /mainstay/test HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200
< Content-Type: text/plain
< Content-Length: 10
< Date: Mon, 13 Nov 2017 13:57:45 GMT
<
* Connection #0 to host localhost left intact
Hello test
Successful error case:
curl localhost:8080/mainstay/test/does_not_exist -v
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /mainstay/test/does_not_exist HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 404
< Content-Type: text/html;charset=utf-8
< Content-Language: en
< Content-Length: 1078
< Date: Mon, 13 Nov 2017 13:58:21 GMT
<
<!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Not Found</p><p><b>Description</b> The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.</p><hr clas* Connection #0 to host localhost left intact
s="line" /><h3>Apache Tomcat/8.5.23</h3></body></html>
Faulty error case that does not match the servlet contextpath:
curl localhost:8080/test/does_not_exist -v
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /test/does_not_exist HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 404
< Content-Length: 0
< Date: Mon, 13 Nov 2017 13:58:54 GMT
<
* Connection #0 to host localhost left intact
If I refactor my code and annotate the entire prefix into my jersey resource all works as expected, all requests get routed and the error handler's are called. It enables me to also send the exception and catch it with jersey's exception mappers to handle it.
However I have not found a way to register a custom error handle for this case.
I hope this makes sense. Please let me know if I can do anything else to add value to this issue.
Regards,
Artur