开发者

Problem with differentiation of pathparams

I have problem with Jax-rs @Path variable, I need to differentiate the following two pathparams

  1. @Path({domain}/{id})

  2. @Path({domain}/{filename})

sample url for both:

1. http://localhost:8080/in.com/lrth09erdfgwe

2. http://localhost:8080/in.com/lrth09erdfgwe.xml

I think we need to use regex in pathparam! I tried it but failed to get it! I'm using this applica开发者_如何学Ction in Resteasy integration with spring-mvc. Plz advice on this issue!

Cheers!


You control the matching of path parameter by putting inside the parameter a colon and then an RE pattern to match it, like this (where the RE is .+[.].+, which matches anything so long as it has at least one dot somewhere in the middle):

@Path("{domain}/{filename:.+[.].+}")

I use this in one of my services (which uses Apache CXF, but I believe this is a feature of all JAX-RS implementations). Have a care though! You can match path separators with this, which can make things very confusing. (I think you might be better to change the structure of the URIs so that there is no ambiguity, e.g., {domain}/id/{id} and {domain}/files/{filename}. I bet your clients will grok that much more rapidly.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜