jax-rshttp-status-code-404jakarta-migration

JAX-RS resource returns HTTP/1.1 404 Not Found after Jakarta migration


I've upgraded an 'old' (was working) EE Application with JSON which did work with 'javax'. Now on EE 10.x & Jakarta.

implementation("com.google.code.gson:gson:2.11.0")

Using:

import com.bewherewhen.ejb.UsersJSONEJB;

import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Named
@Path("/")
public class UsersJSONController {
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/get-all-users")
    public Response getAllUsersJSON() {
        LOGGER.info(">>>>> UsersJSONController getAllUsersJSON .....");

        String json = usersJSONEJB.getAllUsersJSON();
        LOGGER.info(">>>>> 1.6 UsersJSONEJB getAllUsersJSON = {}", json);

        return Response.ok(json, MediaType.APPLICATION_JSON).build();
    }
}

If I run 'curl' I get:

curl -v http://127.0.0.1:8080/get-all-users/
*   Trying 127.0.0.1:8080...
* Connected to 127.0.0.1 (127.0.0.1) port 8080
> GET /get-all-users/ HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/8.7.1
> Accept: */*
> 
* Request completely sent off
< HTTP/1.1 404 Not Found
< Connection: keep-alive
< Content-Length: 74
< Content-Type: text/html
< Date: Sun, 04 Aug 2024 17:07:07 GMT
< 
* Connection #0 to host 127.0.0.1 left intact
<html><head><title>Error</title></head><body>404 - Not Found</body></html>

Using:

TIA.


Solution

  • I added 'ApplicationPath/ApplicationConfig' on 'javax':

    package com.bewherewhen.webservices;
    
    import javax.ws.rs.ApplicationPath;
    import javax.ws.rs.core.Application;
    
    @ApplicationPath("beWhereWhen")
    public class ApplicationConfig extends Application {
        public ApplicationConfig() {
        }
    }
    

    Run:

    curl -v http://localhost:8080/BeWhereWhen/beWhereWhen/get-all-users/
    

    Gives 'HTTP/1.1 200 OK":

    * Host localhost:8080 was resolved.
    * IPv6: ::1
    * IPv4: 127.0.0.1
    *   Trying [::1]:8080...
    * connect to ::1 port 8080 from ::1 port 63674 failed: Connection refused
    *   Trying 127.0.0.1:8080...
    * Connected to localhost (127.0.0.1) port 8080
    > GET /BeWhereWhen/beWhereWhen/get-all-users/ HTTP/1.1
    > Host: localhost:8080
    > User-Agent: curl/8.7.1
    > Accept: */*
    > 
    * Request completely sent off
    < HTTP/1.1 200 OK
    < Connection: keep-alive
    < Content-Type: application/json
    < Content-Length: 4
    < Date: Tue, 06 Aug 2024 21:31:47 GMT
    < 
    * Connection #0 to host localhost left intact
    

    However unable to create a version for Jakarta EE 10/11:

    import jakarta.faces.application.Application;
    import jakarta.ws.rs.ApplicationPath;
    

    Error with:

    error: ApplicationConfig is not abstract and does not override abstract method getValidatorIds() in Application
    

    Unable to deploy with "jakarta.ws.rs" on EE 10/11. Selected Methods to Implement on WildFly 33.0.0. Can any suggestion or examples?

    Fixed:

    import jakarta.ws.rs.ApplicationPath;
    import jakarta.ws.rs.core.Application;
    import java.util.Set;
    
    @ApplicationPath("beWhereWhen")
    public class ApplicationConfig extends Application {
        public ApplicationConfig() {
            // Default constructor
        }
    
        @Override
        public Set<Class<?>> getClasses() {
            // Return a non-null Set of resource and provider classes
            return Set.of(); // Replace with actual resource classes if any
        }
    
        //@Override
        public ActionListener getActionListener() {
            // Implement the method for the action listener
            return new MyActionListener(); // Replace with your actual listener implementation
        }
    
        // Define MyActionListener or replace with your actual implementation
        private static class MyActionListener implements ActionListener {
            @Override
            public void performSomeAction() {
                // Implement the action listener's functionality here
            }
        }
    
        // Define an interface if it's not already defined.
        // This is just an example. Replace it with the actual interface definition.
        private interface ActionListener {
            void performSomeAction();
        }
    }
    

    Run:

    * Host localhost:8080 was resolved.
    * IPv6: ::1
    * IPv4: 127.0.0.1
    *   Trying [::1]:8080...
    * connect to ::1 port 8080 from ::1 port 49357 failed: Connection refused
    *   Trying 127.0.0.1:8080...
    * Connected to localhost (127.0.0.1) port 8080
    > GET /BeWhereWhen/beWhereWhen/get-all-users HTTP/1.1
    > Host: localhost:8080
    > User-Agent: curl/8.7.1
    > Accept: */*
    > 
    * Request completely sent off
    < HTTP/1.1 200 OK
    < Connection: keep-alive
    < Content-Type: application/json
    < Content-Length: 14
    < Date: Fri, 09 Aug 2024 16:19:36 GMT
    < 
    [
      {etc ...},
      {etc ...}
    * Connection #0 to host localhost left intact