Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTEASY002142: Multiple resource methods match request

I am getting following for two completely different URLs and I cannot explain why:

RESTEASY002142: 

   Multiple resource methods match request "GET /devices/distinctValues/3". 
   Selecting one. 

Matching methods: 
[public javax.ws.rs.core.Response 
mypackage.DevService.getDistinctValues(int) throws java.lang.Exception, 

public javax.ws.rs.core.Response 
mypackage.DevRESTService.getDevice(int,java.lang.String) 
throws java.lang.Exception]

This warning should not come up, since the URLS are completely different. If anybody knows why this is happening:

URLs for both methods:

getDevice:

@GET
@Path("devices/{customerId}/{deviceIds}")
@Produces({ "application/json" })

getDistinctValues:

@GET
@Path("devices/distinctValues/{customerId}")
@Consumes("application/json")
@Produces("application/json")
like image 815
skal Avatar asked Sep 06 '17 18:09

skal


1 Answers

The warning happens because your request string can match both path templates. The request "devices/distinctValues/3"

  • matches devices/distinctValues/{customerId} in that customerId = "3"
  • matches devices/{customerId}/{deviceIds} in that customerId = "distinctValues" and deviceIds = "3".

There is no type resolution and since your request is a String there is no way to tell customerId that it cannot accept "distinctValues".

As a workaround, you can either specify a regex as shown in the linked question, or use the RESTEasy proxy framework which is basically a shared interface that both server (your JAX-RS resource) and client use, and then you have a common language with type resolution. Note that there is a typo in the example of the docs.

like image 136
user1803551 Avatar answered Oct 15 '22 19:10

user1803551