Wicket 9 & Tomcat 10 Can't Cast jakarta.servlet.Filter
Asked Answered
M

3

10

I'm trying to use the Wicket Project 'QuickStart' with Netbeans 11, Java 11, Tomcat 10, Wicket 9, and Ubuntu 18.04.

When I install the WAR package and start it, it throws:

20-May-2020 09:23:37.067 GRAVE [] org.apache.catalina.core.StandardContext.filterStart Exception at start [wicket.quickstart]
    java.lang.ClassCastException: class org.apache.wicket.protocol.http.WicketFilter cannot be cast to class jakarta.servlet.Filter (org.apache.wicket.protocol.http.WicketFilter is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader) 

Has anyone seen this issue before and if so, what can I do to resolve this?

Milkmaid answered 20/5, 2020 at 6:24 Comment(0)
M
21

The issue is that Tomcat 10 uses jakarta.** packages (Jakarta EE 9) while Wicket 9.x is still based on javax.** packages (Java EE 8).

The solutions are:

  1. Use Tomcat 9.x
  2. Use https://github.com/apache/tomcat-jakartaee-migration to migrate the Wicket application (the .war file) from javax to jakarta
  3. Deploy the javax.** based application into $TOMCAT10_HOME/webapps-javaee/ folder. It will be automatically migrated to jakarta.** by Tomcat.
Mcadams answered 20/5, 2020 at 7:20 Comment(3)
Applying it to the generated jar is sometimes too late in the development process. But you can apply it to the used jars and use these in your project. See my answer below.Heredia
Unfortunately the migration tool does not deal with deprecated methods, e.g. HttpServletResponse.setStatus(int sc, String sm) from the ...servlet.http package, so even if the application is able to start after the migration, it may be not functioning due to runtime exceptions like this https://mcmap.net/q/1176636/-jersey-servlet-version-issues-java-lang-nosuchmethoderror-jakarta-httpservlet/2518705 , and eventually forces to modify your whole app to support jakarta from the source :)Trumaine
@Trumaine I'd suggest you to report this to the tool maintainers at github.com/apache/tomcat-jakartaee-migration/issues/newMcadams
C
4

Don't use Tomcat 10 yet, it works with the new jakarta packages.

Switch to version 9 instead.

Cymoid answered 20/5, 2020 at 7:18 Comment(3)
Two years later - is this still true? We actually want to switch over to tomcat 10 and resolve different javax.* and jakarta.* clashes where Wicket 10 comes into play. According to issues.apache.org/jira/browse/WICKET-6882, the (main?) reason that Apache Wicket 10 cannot be released yet is a non-released version of Apache commons-fileupload2. Since the current commons-fileupload 1.x shows vulnerabilities in Maven Central and fileupload 2 is still not available there, a new release of 1.x and 2.x should come soon. Thank you developers :)Hargeisa
@Hargeisa The teams from the well known Java frameworks Wicket, Jetkins and Vaadin, are all still waiting for commons-fileupload: issues.apache.org/jira/browse/FILEUPLOAD-309Contextual
It seems that commons-fileupload won't be supported anymore, maybe due the fact that "it is not required from Servlet 3.1 onwards", see #68821207. Dear Wicket developers, are there alternatives that can be used here to get Apache Wicket 10 ready?Hargeisa
H
0

To make wicket 9 work with with jakarta, e.g. if using tomcat 10 or spring boot 3, you have to convert some jars. There is the tool jakartaee-migration which does this for a given jar. So apply it at least to these 4 jars and create new ones - I used -jakarta as appendix:

  • wicket-core -> wicket-core-jakarta
  • wicket-util -> wicket-util-jakarta
  • wicket-request -> wicket-request-jakarta
  • commons-fileupload -> commons-fileupload

Also create proper pom files put all together into your local/shared repository.

To use it, add the new dependencies and exclude the old ones where necessary. Run mvn dependency:tree until nothing bogus gets picked up.

Congrats - you now have wicket 9 for jakarta.

Heredia answered 20/2, 2023 at 19:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.