Can Resteasy look into parameter's type for JAX-RS methods?

会有一股神秘感。 提交于 2019-12-04 11:45:06

As far as I know, RESTEasy won't take the method parameter type into consideration when matching a request. According the JSR-339 (that RESTEasy implements), this is how the request matching process works:

A request is matched to the corresponding resource method or sub-resource method by comparing the normalized request URI, the media type of any request entity, and the requested response entity format to the metadata annotations on the resource classes and their methods. If no matching resource method or sub-resource method can be found then an appropriate error response is returned. [...]

The JAX-RS implementations must match the requested URI with the @Path annotation values. In the @Path annotation value you can define variables, that are denoted by braces ({ and }).

As part of the request matching, the JAX-RS implementation will replace each URI template variable with the specified regular expression or ([ˆ/]+?) if no regular expression is specified.

To address the situation you mentioned in your question, you should specify a regex to match UUIDs on one resource method:

@Path("{id : [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}}")

And you also may consider a regex to match integers on the other resource method:

@Path("{id : \\d+}")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!