Can RestEasy choose a method based on query parameters?

I started working with RestEasy, and I had a problem that I cannot find an answer to. If I have two methods that allow the same path (in this case / path 1 / path2 / path3), but both have a different number of query parameters, can RestEasy determine which method to use?

@GET @NoCache @Produces({ MediaType.APPLICATION_JSON }) @Path("/path1/path2/{path3}") public String getResults1( @PathParam("path3") String path3, @QueryParam("query1") @DefaultValue("") String query1, @QueryParam("query2") String query2, @QueryParam("query3") @DefaultValue("25") int query3) { ... } @GET @NoCache @Produces({ MediaType.APPLICATION_JSON }) @Path("/path1/path2/{path3}") public String getResults2( @PathParam("path3") String path3, @QueryParam("query1") @DefaultValue("") String query1, @QueryParam("query2") @DefaultValue("5") Integer query2) { ... } 

I did some testing, and yesterday it seemed that everything was working fine and that he could choose the right path, but now I am starting to see that he takes the wrong path every time.

Is this something that needs to be processed, or should I just suck it and put it in one method and do a self check?

+4
source share
1 answer

No, you must handle this method. If conflicting resources are detected, it will be implementation independent, which method will be agreed upon.

Take a look at your example again:

If you sent query1 and query2, how would he know if you want to use a method with two query parameters or a method with three query parameters, and you want the default value to be equal to it by default?

+2
source

Source: https://habr.com/ru/post/1487095/


All Articles