Home > Mobile >  404 error when upgrading from Tomcat7 / Jersey 2.25 / Servlet 2.5 to Tomcat 10 / Jersey 3.0.8 / Serv
404 error when upgrading from Tomcat7 / Jersey 2.25 / Servlet 2.5 to Tomcat 10 / Jersey 3.0.8 / Serv

Time:09-14

I have a Jersey application running on Tomcat that we've had up for several years. We are currently upgrading to Java 11 and Tomcat 10, which necessitates Servlet 5.0 and Jersey 3.0.8

After satisfying all of the compile needs, and any runtime errors of "class not found", I am running into a problem I have been bashing my head against all day. No matter what I try, I keep getting a 404 error.

I tried changing the original application from ResourceConfig:

public class AppConfig extends ResourceConfig {

    public AppConfig() {
        packages("com.carpart.webservices.rest.oauth");
        property(JspMvcFeature.TEMPLATE_BASE_PATH, "/");
        register(JspMvcFeature.class);
    }
}

to a subclass of application, overriding getClasses:

    public class AppConfig extends Application {
        
        @Override
        public Set<Class<?>> getClasses() {
            Set<Class<?>> s = new HashSet<Class<?>>();
            s.add( Connect.class );
            return s;
        }
        
    }

I've tried different web.xml variations from the original filter to the wording on the Jersey documentation:

Original:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

<filter>
    <filter-name>Jersey</filter-name>
    <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
    <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>com.carpart.webservices.rest.oauth.AppConfig</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <url-pattern>/*</url-pattern>
    <filter-name>Jersey</filter-name>
  </filter-mapping>
</web-app>

New:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="5.0"
    xmlns="https://jakarta.ee/xml/ns/jakartaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  
    <servlet>
        <servlet-name>com.carpart.webservices.rest.oauth.AppConfig</servlet-name>
    </servlet>
     
    <servlet-mapping>
        <servlet-name>com.carpart.webservices.rest.oauth.AppConfig</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
 
 </web-app>

I've tried setting an @ApplicationPath on the application to various values from "/" to "/*" to "/api" just to see if I could get some different reaction.

The Connect class is defined as such:

@Path("/connect")
public class Connect {

    @GET
    @Path("/authorize")
    @Produces(MediaType.TEXT_HTML)
    public Response authorize(@QueryParam("client_id") String client_app_id ) {
        log.debug("Inside authorize (phase 1) GET method...");
    }
}

The Connect resource class hasn't changed. from what we had.

I've read the Jersey 3.0.8 documentation several times with regards to configuring and deploying, but I am not seeing what is wrong.

CodePudding user response:

<init-param>
    <param-name>javax.ws.rs.Application</param-name>
    <param-value>com.carpart.webservices.rest.oauth.AppConfig</param-value>
</init-param>

If you're using Jersey 3, then javax needs to be changed to jakarta. No more Javax anywhere.

CodePudding user response:

Ok, So I found the issue! (Thank you Paul, your comment below the code helped trigger my thoughts this morning!)

I was still including the javax.* pathed classes in my Connect class for the annotations. I deleted them and re imported them all as jakarta.ws.rs.* and it recognized the Connect class as a resource.

  • Related