Skip to content

JAX-RS returns 404 incorrectly for route with path parameter containing prefix that matches segment from another route #50330

@paulooorg

Description

@paulooorg

Describe the bug

When registering JAX-RS routes with the following structure:

@Path("/")
public class TestResource {
   @GET
   @Path("/administration/containers/{container}")
   @Produces(MediaType.TEXT_PLAIN)
   public String get(@PathParam("container") String container) {
       return "/administration/containers/{container} - matched: " + container;
   }

   @GET
   @Path("/administration/containers/boost/{type}")
   @Produces(MediaType.TEXT_PLAIN)
   public String boost(@PathParam("type") String type) {
       return "/administration/containers/boost/{type} - matched: " + type;
   }
}

The following curl requests produce unexpected results:

curl http://localhost:8080/administration/containers/boost_aaa -> 404 (INCORRECT)
curl http://localhost:8080/administration/containers/booost_aaa -> matches /administration/containers/{container} (CORRECT)
curl http://localhost:8080/administration/containers/boost/aaa -> matches /administration/containers/boost/{type} (CORRECT)

The request curl http://localhost:8080/administration/containers/boost_aaa should match the route /administration/containers/{container} but returns 404 instead.

Interestingly, this issue does NOT occur when using Vert.x Router directly (io.vertx.ext.web.Router).

Workaround discovered:

The problem can be avoided by restructuring the routes with class-level @Path:

@Path("/administration/containers")
public class TestResource {

    @GET
    @Path("/{container}")
    @Produces(MediaType.TEXT_PLAIN)
    public String get(@PathParam("container") String container) {
        return "/administration/containers/{container} - matched: " + container;
    }

    @GET
    @Path("/boost/{type}")
    @Produces(MediaType.TEXT_PLAIN)
    public String boost(@PathParam("type") String type) {
        return "/administration/containers/boost/{type} - matched: " + type;
    }
}

Expected behavior

All curl requests should work correctly:

curl http://localhost:8080/administration/containers/boost_aaa -> matches /administration/containers/{container}
curl http://localhost:8080/administration/containers/booost_aaa -> matches /administration/containers/{container}
curl http://localhost:8080/administration/containers/boost/aaa -> matches /administration/containers/boost/{type}

No 404 errors should occur for valid path parameter values.

Actual behavior

Returns 404 for curl http://localhost:8080/administration/containers/boost_aaa instead of matching the route /administration/containers/{container}.

How to Reproduce?

  1. Download and run the attached project
  2. Start the Quarkus application
  3. Execute the following curl commands to observe the issue:
curl http://localhost:8080/administration/containers/boost_aaa       # Returns 404 (BUG)
curl http://localhost:8080/administration/containers/booost_aaa     # Works correctly
curl http://localhost:8080/administration/containers/boost/aaa        # Works correctly

bug.zip

Output of uname -a or ver

x86_64 macOS

Output of java -version

21.0.1

Quarkus version or git rev

3.28.1

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.11

Additional information

I'm uncertain whether this is a bug or expected behavior, since using class-level @Path("/administration/containers") resolves the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions