JAX-RS: case-insensitive paths

…衆ロ難τιáo~ 提交于 2019-12-10 10:58:18

问题


I have anchored REST services/methods to URI template by @Path annotation. It looks like as usual:

@GET
@Path("/message")
@Produces("application/json")
public Response getMessage() { ... }

But my REST service has to be case-insensitive. Now I'm using regular expression in @Path in all my code like that:

@GET
@Path("/{message:[mM][eE][sS][aA][gG][eE]}")
@Produces("application/json")
public Response getMessage() { ... }

This looks weird. Is there something I overlooked in specification (I hope not, see this) or has any of JAX-RS implementations special feature for that? Now I'm using JBoss RESTeasy.

Thanks.


回答1:


i don't know resteasy, but if it supports all java regex syntax, you could use (?i:message) instead of your pattern.




回答2:


If you really need to make the api case-insensitive and you're using Apache on the front-end of your site, consider doing it outside of code: define your API with the urls all lowercase and use Mod-Rewrite to change the urls to lowercase when they hit the web server no matter what the client actually sent. This blog post describes how to do this.




回答3:


Also, the next pattern is working for me:

@Path("/{externalorders: (?i)externalorders}")


来源:https://stackoverflow.com/questions/8083851/jax-rs-case-insensitive-paths

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