操作 UriInfo 的中心点
我目前正在利用由 jax-rs 框架(当前为 RestEasy)注入的 UriInfo 来构建我在 Location 标头中使用的 URI。从 UriInfo 创建的 url 也用在响应 xml/json 中。
简而言之,它看起来像这样:
public class ResourceBean {
@Context
private UriInfo uriInfo
public Response mappedMethod(){
...
UriBuilder builder = uriInfo.getBaseUriBuilder().path(...);
...
}
}
问题是我们在应用程序服务器前面使用负载平衡器,如果用户/系统要遵循其中一个链接,它需要通过负载平衡器而不是直接到达这台机器。 uriInfo.getBaseUriBuilder()
返回当前计算机的基本 URL,而不是负载均衡器的基本 URL。
我知道某些负载均衡器可以通过重写 url 来实现此目的,但不幸的是,我对我们的负载均衡器没有任何控制权或访问权限,并且不知道它们是否支持它,或者是否可以在正文中实现html 响应。
是否存在可以操作或构造 UriInfo 以包含负载均衡器的基本 URI 的中心点?
I am currently utilizing UriInfo, injected by jax-rs framework (currently RestEasy), to build the URI that I use in the Location header. The url created from the UriInfo is also used in the response xml/json.
So in short it looks some thing like:
public class ResourceBean {
@Context
private UriInfo uriInfo
public Response mappedMethod(){
...
UriBuilder builder = uriInfo.getBaseUriBuilder().path(...);
...
}
}
The problem is that we use load balancers in front of the application servers and if a user/system is to follow one of the links it needs to go via the load balancers and not directly to this machine. uriInfo.getBaseUriBuilder()
returns the base URL of the current machine and not of the load balancers.
I understand that some load balancers can do url rewritting to achieve this, but I unfortunately don't have any control or access to our load balancers and don't know if they support it, or if it is even possible in the body of the html response.
Is there a central point where the UriInfo can be manipulated or contstructed to contain the load balancer's base URI?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了 UriInfo 的构建位置。该信息是从 HttpServletRequest 收集的。不幸的是,除了更改 RestEasy 代码之外,没有其他方法可以操作它。
因此,我将使用 Servlet Filter 在请求到达框架之前对其进行操作。
I have found where the UriInfo is constructed. The information is gathered from HttpServletRequest. Unfortunately there is no way other then changing RestEasy code to manipulate it.
So I am going to use a Servlet Filter to manipulate the request before it hits the framework.