JSF - 代理丢失的转发 URL
当对 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
标记似乎具有正确的 URI
/tenant/testTenant/News
,因为 apache 代理中有一个SUBSTITUTE
规则来删除/tenant/testTenant
>。ajax 不正确,因为替换仅对
text/html
文件有效,对 AJAXtext/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 aSUBSTITUTE
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 AJAXtext/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-299688452So there was no error in the
@WebFilter
either since it showed the same result as the markup (which just was substituted).