'JSF - forwarded URL with proxy lost
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')}?
Solution 1:[1]
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).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | djmj |
