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>
Tony B
  • 254
  • 2
  • 12
  • Literally the [same server](http://tomcat.apache.org/whichversion.html)? Tomcat8 is using [Servlet API 3.1](https://tomcat.apache.org/tomcat-8.0-doc/servletapi/index.html) while Tomcat6 is using [Servlet API 2.5](https://docs.oracle.com/cd/E17802_01/products/products/servlet/2.5/docs/servlet-2_5-mr2/). 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](http://tomcat.apache.org/migration-7.html) and [Migrating from 7.0.x to 8.0.x](http://tomcat.apache.org/migration-8.html). – 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
  • I am confused from the migration instructions from 6 to 7: how does WebServlet as defined in annotations or in application level web.xml interact with global web.xml, like I am using? Of special importance is the "/*" url pattern in my case. I cannot tell if my "/*" is somehow messing up and confusing tomcat 8 but did not confuse tomcat 6 and so far nothing clarifies this. Any ideas? – Tony B May 20 '19 at 22:54
  • I'm not sure, but it sounds to me that your tomcat web.xml settings also have to be set in your webapp (I only set them in the webapp and never modified tomcat's default settings...). See https://bz.apache.org/bugzilla/show_bug.cgi?id=52138#c2. I guess you should see it in the logfiles which mappings are active on webapp deployment. – Freddy May 20 '19 at 23:08
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/93891/discussion-between-user3329922-and-freddy). – Tony B May 20 '19 at 23:22
  • How enable logs so can see what are active mappings? Obviously, I can list them in the servlet context listener, but that does not really tell me WHY they are not working. Add info to main post in case it helps. – Tony B May 21 '19 at 17:22

1 Answers1

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.

Tony B
  • 254
  • 2
  • 12