JAX-RS: case insensitive paths

I bound the REST services / methods to the URI template using the @Path annotation. It looks as usual:

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

But my REST service must be case insensitive. Now I use regex in @Path in all my code:

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

It looks weird. Is there something that I overlooked in the spec (hopefully not, see this ) or has any JAX-RS feature for this feature? Now I am using JBoss RESTeasy .

Thanks.

+2
java case-insensitive annotations jax-rs
source share
2 answers

I do not know resteasy, but if it supports all regex java syntax, you can use (?i:message) instead of your template.

+3
source share

If you really need to make case-insensitive api and you use Apache on the interface of your site, consider doing it outside the code: define your API using the URLs of all lowercase letters and use Mod-Rewrite to change the URLs lowercase when they hit the web server, regardless of what the client sent. This blog post describes how to do this.

+1
source share

All Articles