Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path annotation of different methods are interfering #4119

Closed
a13u opened this issue May 1, 2019 · 5 comments
Closed

Path annotation of different methods are interfering #4119

a13u opened this issue May 1, 2019 · 5 comments
Labels
Milestone

Comments

@a13u
Copy link

a13u commented May 1, 2019

I am using jersey 2.28 via maven and have two methods in my service class (i am using a jetty server).

@GET
@Path("{Prefix}{p:/?}{id: ((\\d+)?)}/abc{p2:/?}{number: (([A-Za-z0-9]*)?)}")
public Response doAnything2() {
    return Response.ok("sdf").build();

}
/*with that code below the GET method does not work, if I remove it, it works*/
@POST
@Path("{Prefix}{p:/?}{id: ((\\d+)?)}/abc/{yeah}")
public Response doAnything3() {
    return Response.ok("sdf").build();

}

With Postman I try to access
GET **P/abc/MyNumber**

If I remove the method doAnything3 I can access the GET endpoint. If I leave the method I can't access the GET endpoint (Method not found error).
Please, inform me if you have troubles reproducing the error.

@jansupol jansupol added bug Something isn't working and removed bug Something isn't working labels May 7, 2019
@jansupol
Copy link
Contributor

Uri P/abc/MyNumber matches both @Path("{Prefix}{p:/?}{id: ((\\d+)?)}/abc/{yeah}") and @Path("{Prefix}{p:/?}{id: ((\\d+)?)}/abc{p2:/?}{number: (([A-Za-z0-9]*)?)}"). In your case, the method with @POST is matched first and a correct method designator (i.e. @GET) is not found.

You could find a more simple example:

    @GET        
    @Path("x")
    public Response doAnything2() {
        return Response.ok("sdf").build();
    }

    @POST
    @Path("{name:[a-zA-Z][a-zA-Z_0-9]*}")
    public Response doAnything3() {
        return Response.ok("sdfa").build();
    }

In this case POST /x will not get matched.

The issue here is that you have two different @PATHs each matching the request, but the paths are not equal.

Unfortunately, you could have a resource with many resource locators, each would lead to another locator only to eventually find the method designator differs from the request type. Then, backtracking would need to be implemented to fallback to the previous resource locator and to try a different path.

For various performance reasons, it was decided the backtracking is not to be implemented and your example is (not) working as designed.

@a13u
Copy link
Author

a13u commented May 14, 2019 via email

@jansupol
Copy link
Contributor

I am starting to think the way it was designed is not completely correct. The method selection is described by JAX-RS Spec. Section 3.7. In Step 2, both methods should be taken to Step 3, where the method with the wrong method designator should be removed.

@a13u
Copy link
Author

a13u commented May 15, 2019 via email

@jansupol
Copy link
Contributor

This seems to work as described by the Request Matching Algorithm. Step 2.f sorts the resource methods, but since the sorting criterium is equal for both resource methods, step 2.g selects the first.

That being said, I think the algorithm allows for picking a correct resource in both your cases, but not requires to pick both. The algorithm does not allow for choosing a resource locator with an equal path (for instance for PUT), though.

@senivam senivam added the 2.29 label Jun 11, 2019
@senivam senivam added this to the 2.29 milestone Sep 12, 2019
This was referenced Oct 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants