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

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

问题描述

是否有任何简单的方法可以在 JAX-RS Web 服务中提供不区分大小写的 URL?这样做的目标是生成一个宽松接受器"的 Web 服务.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() 的所有传入 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)

推荐答案

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

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")不区分大小写,因此应该规范化以使用大写字母作为数字 A-F.

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.

如果您考虑从 Jersey 切换到 Apache Wink,您可以使用 动态资源 以确保所有 url 都是小写/大写.因此,将 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天全站免登陆