Java servlet 404 error tomcat 8 but not tomcat 6

servletstomcat6tomcat8

I have a server which I flip back and forth between tomcat 6 and tomcat 8. When I do an HTTP post using the command

curl -v -X POST -d @webOpenCnsRealCheatsheet.xml -H Referrer:mobileWMS,LLC -H Content-Type:text/xml http://localhost:8080/fortive2/tsmService

I get different results between the different versions of tomcat.

First of all, for tomcat 8, I get:

* About to connect() to localhost port 8080 (#0)
*   Trying ::1... connected
* Connected to localhost (::1) port 8080 (#0)
> POST /fortive2/tsmService HTTP/1.1
> User-Agent: curl/7.19.7 (i386-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: localhost:8080
> Accept: */*
> Referrer:mobileWMS,LLC
> Content-Type:text/xml
> Content-Length: 218
> 
< HTTP/1.1 404 
< Content-Length: 0
< Date: Mon, 20 May 2019 16:17:36 GMT
< 
* Connection #0 to host localhost left intact
* Closing connection #0

Then, for tomcat 6, I get the proper response, no 404 error. What is happening? This is literally the same server, the same WAR file. My servlets are defined in the main tomcat web.xml ( $CATALINA_HOME/conf/web.xml ), NOT in the war file. This is on purpose, as it lets me quickly add web service URLs for new customers without changing the war file.

Also, I will say that multiple web applications reference the same war file ( multiple customers, so multiple websites with slight different configutations but the same UI ). This has always worked just fine for servlets in tomcat 6, so I just assumed this would keep working for Tomcat 8. Could this be causing a problem?

Also, as a side point, I can access port 8080 just fine in the browser, because that is how I sometimes get to the website or the tomcat manager ( when SSL is giving me problems with certificates ). So it is not the port.

Also, as added information, I have this for ONE of my servlets ( not the one I am using, a totally different servlet ):

@WebServlet(urlPatterns = "/*", name = "WmsServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = WmsUI.class, productionMode = false)
@SuppressWarnings("serial")
public class WmsServlet extends VaadinServlet {

    @Override
    protected final void servletInitialized() throws ServletException {
        super.servletInitialized();
        getService().addSessionInitListener(new WmsSessionInitListener());
    }
}

And here are some example $CATALINA_HOME/conf/web.xml servlet configurations:

   <servlet>
      <servlet-name>veeder-ws</servlet-name>
      <servlet-class>com.wmsvision.servlet.WMSProcessorServlet</servlet-class>
      <init-param>
        <param-name>socketType</param-name>
        <param-value>VEEDER-WS</param-value>
      </init-param>
    </servlet>

    <servlet>
      <servlet-name>spence-ws</servlet-name>
      <servlet-class>com.wmsvision.servlet.WMSProcessorServlet</servlet-class>
      <init-param>
        <param-name>socketType</param-name>
        <param-value>SPENCE-WS</param-value>
      </init-param>
    </servlet>
   <servlet-mapping>
        <servlet-name>veeder-ws</servlet-name>
        <url-pattern>/veeder-ws/tsmService</url-pattern>
    </servlet-mapping>

   <servlet-mapping>
        <servlet-name>spence-ws</servlet-name>
        <url-pattern>/spence-ws/tsmService</url-pattern>
    </servlet-mapping>

5/21/2019 update: using Servlet Context listener, I get the following for my development server:

[2019-05-21 13:11:47 EDT] FINE com.mobiwms.website.WmsContextListener logCurrentServlets Servlet name: WMSWebsite-NEWCUST; Mappings: /NEWCUST-WebsiteXML
[2019-05-21 13:11:47 EDT] FINE com.mobiwms.website.WmsContextListener logCurrentServlets Servlet name: default; Mappings: /
[2019-05-21 13:11:47 EDT] FINE com.mobiwms.website.WmsContextListener logCurrentServlets Servlet name: WmsServlet; Mappings: /*
[2019-05-21 13:11:47 EDT] FINE com.mobiwms.website.WmsContextListener logCurrentServlets Servlet name: FortivePFC; Mappings: /Fortive-PFC
[2019-05-21 13:11:47 EDT] FINE com.mobiwms.website.WmsContextListener logCurrentServlets Servlet name: Fortive3; Mappings: /fortive3/tsmService
[2019-05-21 13:11:47 EDT] FINE com.mobiwms.website.WmsContextListener logCurrentServlets Servlet name: jsp; Mappings: *.jspx, *.jsp
[2019-05-21 13:11:47 EDT] FINE com.mobiwms.website.WmsContextListener logCurrentServlets Servlet name: Fortive2; Mappings: /fortive2/tsmService
[2019-05-21 13:11:47 EDT] FINE com.mobiwms.website.WmsContextListener logCurrentServlets Servlet name: WMSWebsite-NEWCUST2; Mappings: /NEWCUST2-WebsiteXML

And the servlet sections of global web.xml ( so $CATALINA_HOME/conf/web.xml ) for my dev machine, where the above logging was printed:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  version="3.1">

    <!-- snipped unrelated config -->

    <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>listings</param-name>
            <param-value>false</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>


    <!-- snipped unrelated config -->

    <servlet>
        <servlet-name>jsp</servlet-name>
        <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
        <init-param>
            <param-name>fork</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>xpoweredBy</param-name>
            <param-value>false</param-value>
        </init-param>
        <load-on-startup>3</load-on-startup>
    </servlet>


    <!-- snipped unrelated config -->

  <!-- ================ Built In Servlet Mappings ========================= -->


  <!-- The servlet mappings for the built in servlets defined above.  Note  -->
  <!-- that, by default, the CGI and SSI servlets are *not* mapped.  You    -->
  <!-- must uncomment these mappings (or add them to your application's own -->
  <!-- web.xml deployment descriptor) to enable these services              -->

    <!-- The mapping for the default servlet -->
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!-- The mappings for the JSP servlet -->
    <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>*.jsp</url-pattern>
        <url-pattern>*.jspx</url-pattern>
    </servlet-mapping>

    <!-- snipped unrelated config -->

  <!-- ==================== Custom WMS servlet setup ===================== -->
    <servlet>
      <servlet-name>FortivePFC</servlet-name>
      <servlet-class>com.wmsvision.servlet.WMSProcessorServlet</servlet-class>
      <init-param>
        <param-name>socketType</param-name>
        <param-value>Fortive_PFC</param-value>
      </init-param>
    </servlet>

    <servlet>
      <servlet-name>Fortive2</servlet-name>
      <servlet-class>com.wmsvision.servlet.WMSProcessorServlet</servlet-class>
      <init-param>
        <param-name>socketType</param-name>
        <param-value>Fortive2</param-value>
      </init-param>
    </servlet>

    <servlet>
      <servlet-name>Fortive3</servlet-name>
      <servlet-class>com.wmsvision.servlet.WMSProcessorServlet</servlet-class>
      <init-param>
        <param-name>socketType</param-name>
        <param-value>Fortive3</param-value>
      </init-param>
    </servlet>

    <servlet>
      <servlet-name>WMSWebsite-NEWCUST</servlet-name>
      <servlet-class>com.wmsvision.servlet.WMSWebsiteServlet</servlet-class>
      <init-param>
        <param-name>socketType</param-name>
        <param-value>WMSWebsite-NEWCUST</param-value>
      </init-param>
    </servlet>

    <servlet>
      <servlet-name>WMSWebsite-NEWCUST2</servlet-name>
      <servlet-class>com.wmsvision.servlet.WMSWebsiteServlet</servlet-class>
      <init-param>
        <param-name>socketType</param-name>
        <param-value>WMSWebsite-NEWCUST2</param-value>
      </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>FortivePFC</servlet-name>
        <url-pattern>/Fortive-PFC</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>Fortive2</servlet-name>
        <!-- <url-pattern>/turnsmith/tsmService</url-pattern>-->
        <url-pattern>/fortive2/tsmService</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>Fortive3</servlet-name>
        <!-- <url-pattern>/NEWCUST/tsmService</url-pattern>-->
        <url-pattern>/fortive3/tsmService</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>WMSWebsite-NEWCUST</servlet-name>
        <url-pattern>/NEWCUST-WebsiteXML</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>WMSWebsite-NEWCUST2</servlet-name>
        <url-pattern>/NEWCUST2-WebsiteXML</url-pattern>
    </servlet-mapping>

</web-app>

Best Answer

OK, found the answer, and it is so simple. So quick answer, and to save people from making my mistake, don't just check the mappings in web.xml, make sure the context is there, or make sure your URL includes a valid context. So if you are not including the context in the URL, make sure the ROOT.xml configuration is there.

So, to be more specific, in my case, I removed $CATALINA_HOME/conf/Catalina/localhost/ROOT.xml, but was posting to the root context. So with my test above,

curl -v -X POST -d @webOpenCnsRealCheatsheet.xml -H Referrer:mobileWMS,LLC -H Content-Type:text/xml http://localhost:8080/fortive2/tsmService

"fortive2" is NOT the context, it is part of my reference to the servlet. You can see this in my web.xml snippets. Because tomcat8 configuration had no ROOT.xml, it was failing with 404 because could not be found. But tomcat6 worked because I never removed ROOT.xml from that "localhost" directory.