1

I faced with strange issue. We have old application that was written and deployed on Tomcat 6. And now our security team said that Tomcat 6 is EOL and we need to migrate to new version of Tomcat.

I decided to migrate this application from version to version and with Tomcat 7 I faced with strange issue.

On UI we have many different html forms and some fields in this forms can be empty. With tomcat 6 such fields were interpreted as null values. After migration to tomcat 7 I receive empty string instead of null value.

After some googling I found that people suggest to specify such parameter in web.xml:

    <context-param>
        <param-name>org.apache.el.parser.COERCE_TO_ZERO</param-name>
        <param-value>false</param-value>
    </context-param>

And this does not helped

Also I want to mentioned that we also use Spring MVC in this app. But during migration I have not changed any version in code. The only thing I changed is version of tomcat

Update

I updated tomcat to latest available dockerized version(9.0.16-jre8). As a result I still have same issue.

Update 2

I do not have unlimited time for this ticket so I decided to manually update/replace all places where we check fields on null to start check on empty value.

Also I found that starting from version 7 tomcat uses relative path for redirect links and in 6 version Tomcat uses absolute links by default(or it was configured with some legacy field/property that was removed in 7 version).

If you want to enable logic for absolute path you need to specify useRelativeRedirects attribute in Context configuration:

<Context useRelativeRedirects="false" />

Another point is that starting from Tomcat 8 it supports Rfc6265 and throw exception if your cookies have invalid format(in our case we have cookies that starts with .). Right now Tomcat supports legacy cookie processor but it can be removed in future versions. To enable legacy cookie processor you need to add such line in Context configuration:

<Context useRelativeRedirects="false">
    <CookieProcessor className="org.apache.tomcat.util.http.LegacyCookieProcessor" />
</Context>

Next thing also related to some new specifications is format of URLs and query parameters. In case you query params have some special characters you request will fail with new versions of Tomcat and in logs you will just see null instead of request url. To fix this you need to add elaxedQueryChars attribute for Connector in server.xml like this:

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               URIEncoding="UTF-8"
               redirectPort="8443"
               elaxedQueryChars="&lt;&gt;[\]^&apos;{|}"/>

&lt;&gt;[\]^&apos;{|} == <>[\]'{|}

And last thing that I found is that some listeners that was used in Tomcat6 were removed in Tomcat7+. For example I removed such lines from server.xml:

<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.core.JasperListener" />

One more thing. In new versions of Tomcat we have large list of jars specified in tomcat.util.scan.StandardJarScanFilter.jarsToSkip. With default list jstl library stop to work cause it is skipped by default. So you need to remove lines related to jstl:

Aliaksei Bulhak
  • 6,078
  • 8
  • 45
  • 75
  • Tomcat 7 is also EOL, you need Tomcat 8.5 at least. You should clean the code ( assuming you are using Eclipse) and also delete the version stored on the server, then completely rebuild the project. I find this eliminates a lot of strange behavior when writing a Spring project. – MGT Mar 25 '19 at 18:31
  • Thanks @MGT. Yes? I know that 7th version is also outdated, but my idea was like soft migration from version to version. I mean migrate +1 version check that everything is working and then migrate to next one. But I will try to migrate to 8.5 – Aliaksei Bulhak Mar 25 '19 at 18:36
  • You can change the object's type in the output for pretty printing. – Roman C Mar 25 '19 at 18:46
  • That param must be entered as a VM argument. See https://stackoverflow.com/questions/3116517/hinputtext-which-is-bound-to-integer-property-is-submitting-value-0-instead-of and https://stackoverflow.com/questions/6304025/work-around-for-faulty-interpret-empty-string-submitted-values-as-null-in-mojarra – Pino Mar 26 '19 at 10:42
  • @Pino thanks for links. I added it as vm argument with -D and result still the same – Aliaksei Bulhak Mar 26 '19 at 12:30

0 Answers0