我的应用程序在测试服务器上完全通过https执行.当我在没有重定向的情况下导航时,它完美地工作:
例:
<p:menuitem value="#{msg.customerScreen}" url="/restrict/customer.xhtml" />
<p:menuitem value="#{msg.productScreen}" url="/restrict/product.xhtml" />
Run Code Online (Sandbox Code Playgroud)
但是当我需要重定向到另一个页面时,它会重定向到http而不是https.当使用http时,它完美地工作:
<p:commandLink ajax="false" action="/commerce/store.xhtml?faces-redirect=true">
<h:graphicImage library="images/BTN" name="btn_to_shop.gif"/>
</p:commandLink>
Run Code Online (Sandbox Code Playgroud)
作为一种解决方法,我尝试重建URL:
<p:commandLink ajax="false" action="#{authorizerBean.getCompleteURL('/commerce/store.xhtml?faces-redirect=true')}">
<h:graphicImage library="images/BTN" name="btn_to_shop.gif"/>
</p:commandLink>
public String getCompleteURL(String page) {
try {
FacesContext ctxt = FacesContext.getCurrentInstance();
ExternalContext ext = ctxt.getExternalContext();
URI uri = new URI(ext.getRequestScheme(), null, ext.getRequestServerName(), ext.getRequestServerPort(), ext.getRequestContextPath(), null, null);
return uri.toASCIIString() + page;
} catch (URISyntaxException e) {
throw new FacesException(e);
}
}
Run Code Online (Sandbox Code Playgroud)
正在调用方法getCompleteURL并返回URL correclty,但JSF不会重定向到新URL.
JBoss正在接收HTTP连接.谁管理HTTPS是Apache,重定向到JBoss:
<VirtualHost *:443>
...
ProxyPass / http://server:8080/
ProxyPassReverse / http://server:8080/
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
我更愿意在不使用getCompleteURL的情况下解决此问题,但如果不可能,请帮助我解决其他问题.
我找到了解决这个问题的方法.我认为它正在发生,因为Apache接收https连接并通过http转发JBoss.然后,当我重定向到另一个页面时,JSF不知道它应该通过https进行.
使用ConfigurableNavigationHandler,我可以在重定向时拦截并挂载正确的URL.
public class NavigationHandler extends ConfigurableNavigationHandler {
private ConfigurableNavigationHandler concreteHandler;
public NavigationHandler(ConfigurableNavigationHandler concreteHandler) {
this.concreteHandler = concreteHandler;
}
@Override
public void handleNavigation(FacesContext context, String fromAction, String outcome) {
if (outcome != null && outcome.contains("faces-redirect=true")) {
try {
outcome = "https://server.com/project" + outcome;
context.getExternalContext().redirect( outcome );
} catch (IOException e) {
throw new FacesException(e);
}
} else {
concreteHandler.handleNavigation(context, fromAction, outcome);
}
}
}
Run Code Online (Sandbox Code Playgroud)
在faces-config.xml中:
<application>
<navigation-handler>com.example.NavigationHandler</navigation-handler>
</application>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3904 次 |
| 最近记录: |