urlrewritefilter icon indicating copy to clipboard operation
urlrewritefilter copied to clipboard

Not compatible with Tomcat 9

Open vmassol opened this issue 3 years ago • 10 comments

Tomcat 9 performs very early mapping of incoming requests before the URLRewriteFilter has a chance to execute (this was working fine in Tomcat 8 and probably earlier versions too).

See https://jira.xwiki.org/browse/XWIKI-19444?focusedCommentId=112420&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-112420 for an explanation based on the XWiki use case of URLRewriteFilter

vmassol avatar Jul 11 '22 13:07 vmassol

UrlRewriteFilter has fallen behind in it's support of modern versions of app servers. It think it would be best to shop around for an alternative.

Tomcat 9 includes it's own rewrite engine. Perhaps it would be better to use that?
https://tomcat.apache.org/tomcat-9.0-doc/rewrite.html

Note, I'm more than happy to accept any PRs that have full test coverage across a variety of containers.

paultuckey avatar Jul 12 '22 08:07 paultuckey

Thanks for the answer @paultuckey

Yeah I had realized it has fallen behind. It's still a great and elegant solution though ;)

Actually I've reported this issue here to let users know but it would probably be more accurate to report it on the Tomcat side as I believe the way they have coded Tomcat 9 prevents any URL rewriting from working transparently.

PS: yes I have noticed the rewrite valve. I need to find some time to check if it can work for our use case but I don't think it would as we are also rewriting outbound URLs and this is done through our call to getResponse().encodeURL(url);, which triggers the URLRewriteFilter. I don't see how any solution that is not executing under the same webapp would work to rewrite the URLs we generate in our responses (the solution would need to parse the content to make replacements AFAICS).

Thanks!

vmassol avatar Jul 12 '22 08:07 vmassol

I've recently migrated a java legacy app running struts1 (originally developed back in 2005-2008!) but had consistent crashes (every other day) on our virtual web server running Tomcat 9. I rolled back the urlrewritefilter to version 4.0.3 and found stability. However after a few weeks of intermittent crashes (once a week maybe, tomcat freezes when heap size maxes out) I'm considering eliminating it all together to avoid further headaches.

Any recommendations for replacing this well used tool (for years)?

octafishmedia avatar Sep 11 '22 17:09 octafishmedia

Perhaps use Nginx in front as rewriting proxy, or the built-in tomcat rewrite valve mentioned above. It's also relatively simple to write your own custom filter for your specific use-case.

paultuckey avatar Sep 11 '22 23:09 paultuckey

5.1.1 should now work with tomcat 9.

paultuckey avatar Oct 19 '23 02:10 paultuckey

Tomcat 9 recommends Servlet 4.0 usage (https://tomcat.apache.org/whichversion.html)

Updated README says to use older version 4.0.3 w/ Servlet spec 4.0

When I use Tomcat 9 + version 5.1.2 + Servlet 4.0 I get...

SEVERE: Exception starting filter [UrlRewriteFilter] java.lang.NoClassDefFoundError: jakarta/servlet/Filter

octafishmedia avatar Oct 19 '23 13:10 octafishmedia

Apologies, I was confused about this. Looks like Tomcat 9 users will have to stay on version 4.0.3.

If anyone want to submit a PR to fix this issue (use the 4.x branch) I'd be happy to accept it.

paultuckey avatar Oct 19 '23 20:10 paultuckey

Looking for feedback on https://github.com/lobosstudios/xwiki_urlrewrite

I'm running XWiki 15.5.0/Tomcat 9.0.76 and URL rewrites seem to work fine.

stevesobol avatar Nov 06 '23 20:11 stevesobol

@stevesobol I'm updating here for you: https://github.com/lobosstudios/xwiki_urlrewrite still presents the incompatibility reported in this issue, but only on certain actions as discussed in: https://forum.xwiki.org/t/xwiki-docker-image-with-short-urls/13448/9

acotiuga avatar Nov 13 '23 16:11 acotiuga

@acotiuga yes, I think I misunderstood the original problem. I'll dig into it when I have time.

stevesobol avatar Nov 26 '23 07:11 stevesobol