使用JAX-RS的不区分大小写的URL [英] Case-insensitive URLs with JAX-RS

查看:137
本文介绍了使用JAX-RS的不区分大小写的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有简单的方法在JAX-RS Web服务中提供不区分大小写的URL?这样做的目的是生成一个宽松的接受者的网络服务。 1

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

我想这可以用一个过滤哪个 .to [Lower | Upper] Case() s所有传入的URL。不幸的是,这种实现需要程序员纪律/一致性,以确保应用程序中的所有硬编码URL字符串严格[大写]。

另外,我不喜欢尚未知道JAX-RS类似于servlet过滤器。

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.

如果重要,我使用Jersey作为我的JAX-RS实现。

If it matters, I'm using Jersey as my JAX-RS implementation.

1 因为,对你接受的东西宽容,并严格对待你产生(不记得来源)

1As in, "be lenient in what you accept, and strict in what you produce" (can't recall the source)

推荐答案

答案是否定的,因为基本上根据 RFC 3986 的URI区分大小写:

The answer is No, since basically URIs according to RFC 3986 are case sensitive:


6.2.2.1。案例规范化

6.2.2.1. Case Normalization

对于所有URI,百分比编码
三元组中的十六进制数字(例如,%3a与%3A)是 - 不敏感,因此
应该被标准化为使用大写字母表示数字AF。

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.

当URI使用通用语法的组件时,组件
语法等价规则总是适用;即,该方案和
主机不区分大小写,因此应该标准化为
小写。例如,URI是
,相当于 http://www.example.com/ 。假设其他通用语法
组件区分大小写,除非该方案另有特定
定义(参见第6.2.3节)。

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).

如果你仍然想让它们不区分大小写,你可以使用servlet过滤器并将它放在JAX-RS框架之前。你仍然需要在你的申请中保持一致。

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.

如果你考虑从泽西转换到 Apache Wink ,你可以使用动态资源,以确保所有网址都较低/较高。因此,将servlet过滤器与动态资源相结合可以为这种情况提供完整的解决方案。

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.

这篇关于使用JAX-RS的不区分大小写的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆