Is there any easy way to provide a case-insensitive URLs in a JAX-RS web service? The goal of this is to produce a web service which is a "lenient acceptor."1
I imagine it's possible to do this with a filter which .to[Lower|Upper]Case()
s all incoming URLs. Unfortunately, this implementation demands programmer discipline/consistency in making sure that all hard-coded URL strings in the application are strictly [lower|upper]case.
Also, I don't yet know the JAX-RS analog to a servlet filter.
If it matters, I'm using Jersey as my JAX-RS implementation.
1As in, "be lenient in what you accept, and strict in what you produce" (can't recall the source)
Google's John Mueller clarifies that URLs are case sensitive, so it matters whether the characters are uppercase or lowercase. Variations in cases can make one URL different from another, similar to how a URL with a trailing slash is different from a URL without the slash.
Rule #5: Lowercase letters should be preferred in URI paths When convenient, lowercase letters are preferred in URI paths since capital letters can sometimes cause problems. RFC 3986 defines URIs as case-sensitive except for the scheme and host components.
JavaScript is a case-sensitive language. This means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.
The answer is No, since basically URIs according to RFC 3986 are case sensitive:
6.2.2.1. Case Normalization
For all URIs, the hexadecimal digits within a percent-encoding triplet (e.g., "%3a" versus "%3A") are case-insensitive and therefore should be normalized to use uppercase letters for the digits A-F.
When a URI uses components of the generic syntax, the component syntax equivalence rules always apply; namely, that the scheme and host are case-insensitive and therefore should be normalized to lowercase. For example, the URI is equivalent to http://www.example.com/. The other generic syntax components are assumed to be case-sensitive unless specifically defined otherwise by the scheme (see Section 6.2.3).
If you still want to make them case insensitive, you can use a servlet filter and put it in front of JAX-RS framework. You still need to be consistent in your application.
If you consider switching from Jersey to Apache Wink, you can use the Dynamic Resources to ensure that all urls are lower/upper-cased. So combining a servlet filter with the Dynamic Resources can be a full solution for this case.
I think I found simple solution which is JAX-RS specification compliant. You are able to use in @Path
annotation regular expression like this:
@Path("/{message:[mM][eE][sS][aA][gG][eE]}")
I have used it with JBoss RESTeasy implemention. See more there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With