Joqus
Joqus

Reputation: 585

What is the behaviour in Jersey if I have two equal paths but one has a parameter?

I would like to know what happen if I have two @PUT services in Jersey and one is defined as:

@PUT
@Path("/{elementId}")

And another one as:

@PUT
@Path("/service")

What is the expected behaviour?

Upvotes: 1

Views: 58

Answers (1)

Paul Samsotha
Paul Samsotha

Reputation: 208984

Given all else is the same (i.e. content negotiating annotations and such), given what you have provided, if you access the /service path, the explicit @Path("/service") will always be hit.

In the matching algorithm[1], the primary key in sorting the candidate methods, is the number of literal characters in the path expression. @Path("/service") has more (the other has none), so it will always win. You should easily be able to test this behavior.

[1]: See 3.7.2 Request Matching (in the JAX-RS spec. The part that specifies the above is 2.f (the same is detailed about the class level @Path annotation, in 1.e)

Upvotes: 2

Related Questions