Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
465 views
in Technique[技术] by (71.8m points)

java - Case-insensitive URLs with JAX-RS

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...