问题
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