0

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>
9
  • Literally the same server? Tomcat8 is using Servlet API 3.1 while Tomcat6 is using Servlet API 2.5. Increase log verbosity and check your webapp and catalina logs... – Freddy May 20 '19 at 21:56
  • Also read Migrating from 6.0.x to 7.0.x and Migrating from 7.0.x to 8.0.x. – Freddy May 20 '19 at 22:02
  • yes, same physical server. It is trivial to run "service tomcat6 stop" and then "service tomcat8 start". – Tony B May 20 '19 at 22:06
  • Ok, that's what you meant with server. I thought you mean Tomcat. And there might be one or two things you have to adjust. Reading the migration guides could help as well as increasing the log verbosity on both Tomcats/Webapps and comparing the logfiles. – Freddy May 20 '19 at 22:13
  • unless I am mistaken, logging level already set to "ALL". Nothing useful in there. What would I be looking for? I mean, does it even log anything to the tomcat logs in this case? – Tony B May 20 '19 at 22:41
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.