Same Way for two resources in knitwear

Is it possible to map the same path for two resources?

Ex: Resource1.java

@Path("/users") 

Ex: Resource2.java

 @Path("/users") 

Is it possible? Both classes have different subpaths that still fail and give me 500 internal server errors with a servlet initialization error.

+4
source share
5 answers

Request matching rules specified in section 3.7.2 of the specification

+5
source

I think you can really have the same path if you change something else in the request.

If I change @produces and @consumes for each method, I can, for example, return XML for one of the methods and JSON for the other.

 @produces(Application.XML) @Path("/path") public void methodA(); @produces(Application.jSON) @Path("/path") public void methodB(); 
+3
source

If the paths have different subpaths, then you define the paths in separate @Path attributes in more detail, for example:

@Path("/users/{id:[a-z0-9]+}/sub1/")

@Path("/users/{id:[a-z0-9]+}/sub2/")

If you cannot indicate them to the extent that it is clear which resource to call is given in any particular way, Jersey will not be able to decide which resource to call.

+3
source

I would recommend using one class matched to knitwear and having 2 helper classes that you delegate to keep your code clean.

+2
source

Jersey will give you an error message if you make a request that several resources may respond to. That is, resources have ambiguous paths. However, I do not think that the error you get here is if the common path is not ambiguous, as you say.

+1
source

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


All Articles