Search code examples
springtomcatspring-boottomcat7

How do I differentiate between Apache Tomcat serving up a 404 and my application on tomcat returning a 404?


I have a Java/Spring application, and I'm using Spring's Rest Template to call a webservice hosted on an apache tomcat container, and I would like to know how I can differentiate between the tomcat container serving up a 404 page (when an application is not deployed for example) and when my webservice returns a 404 (say when I cannot find an account/resource). Am I forced to look into the payload and fish out the "Apache Tomcat" html string that is returned? Or is there a better way to distinguish these? (Ie. a setting on the tomcat server that exposes a header value that might tell me that this is an application container specific error?)

The versions that we use are listed below.

  • Tomcat 7.0.63 with JDK 8
  • Spring 4.3.3.RELEASE / Spring Boot 1.4.1.RELEASE

Thanks in advance,

Juan


Solution

  • Header may help to distinguish both.

    tomcat response to http://localhost:8080/asd
    Content-Length: 0

    HTTP/1.1 404 Not Found
    Server: Apache-Coyote/1.1
    Content-Length: 0
    Date: Sat, 28 Apr 2018 00:32:57 GMT
    

    manager app response to http://localhost:8080/manager/htmll
    Content-Type: text/html;charset=ISO-8859-1
    Content-Length: 1534

    HTTP/1.1 404 Not Found
    Server: Apache-Coyote/1.1
    Content-Type: text/html;charset=ISO-8859-1
    Content-Length: 1534
    Date: Sat, 28 Apr 2018 00:39:10 GMT