JSF - 代理丢失的转发 URL

发布于 2025-01-12 07:51:49 字数 1165 浏览 2 评论 0原文

当对 glassfish 5 使用 apache 代理时,转发的 URL 数据会丢失。

这发生在我们的登录 @WebFilter 中,并且可以使用带有 .

测试用例

此示例访问 URL http://localhost:3080/News

此 URL 代表我们的 testTenant 并代理到:/tenant /testTenant/News 是使用 OCPSoft 库重写的 /sites/tenant/news.xhtml?tenant=testTentant 版本。

请求标头 host、x-forwarded-host 在 ajax 检查 #{headerValues} 上正确设置为 http://localhost:3080

标记中的 GET 请求正确

forward.request_uri: /News

标记中的 AJAX 请求错误

forward.request_uri: /tenant/testTenant/News

Java 中的 WebFilter 错误

将其记录在 @WebFilter 中,即使在第一个 GET 请求中使用request.getAttribute("javax.servlet.forward.request_uri") 将给出相同的错误 URI。

丢失的原因可能是什么?

request.getAttribute("javax.servlet.forward.request_uri")#{requestScoped['request.getAttribute("javax.servlet.forward.request_uri')} 之间有区别吗?

When using an apache proxy against our glassfish 5 the forwarded URL data are lost.

This happens within our login @WebFilter and can be reproduced using a simple ajax page update with an <h:outputText value="forward.request_uri: #{requestScope['javax.servlet.forward.request_uri']}" /> .

Testcase

This example access URL http://localhost:3080/News

This URL represents our testTenant and is proxied to: /tenant/testTenant/News which is the rewritten version of /sites/tenant/news.xhtml?tenant=testTentant using OCPSoft library.

The request headers host, x-forwarded-host are set correctly to http://localhost:3080 on the ajax checking #{headerValues}.

GET request correct in Markup

forward.request_uri: /News

AJAX request wrong in Markup

forward.request_uri: /tenant/testTenant/News

WebFilter wrong in Java

Logging this inside the @WebFilter, even at the first GET request using request.getAttribute("javax.servlet.forward.request_uri") will give same wrong URI.

What can be the reason this is lost?

Is there a differene between request.getAttribute("javax.servlet.forward.request_uri") and #{requestScoped['request.getAttribute("javax.servlet.forward.request_uri')}?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疾风者 2025-01-19 07:51:49

标记似乎具有正确的 URI /tenant/testTenant/News,因为 apache 代理中有一个 SUBSTITUTE 规则来删除 /tenant/testTenant >。

ajax 不正确,因为替换仅对 text/html 文件有效,对 AJAX text/xml 文件无效。

在 ajax 请求后检查周围表单的 action 属性,发现它没有被重写,这是代理配置错误的标志。感谢 @BalusC 的回复: https://github.com/omnifaces/omnifaces /issues/370#issuecomment-299688452

所以没有错误@WebFilter 要么因为它显示与标记相同的结果(刚刚被替换)。

The markup seemed to have the correct URI /tenant/testTenant/News since there was a SUBSTITUTE rule in the apache proxy to remove /tenant/testTenant.

The ajax was not correct, since the substitution was only active for text/html files and not for AJAX text/xml files.

Checking the action attribute of the surrounding form after the ajax request showed it was not rewritten which is a sign of a bad proxy config. Thanks to @BalusC response at: https://github.com/omnifaces/omnifaces/issues/370#issuecomment-299688452

So there was no error in the @WebFilter either since it showed the same result as the markup (which just was substituted).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文