Java Spring webflow URI映射到包含斜杠的流ID(“/”)
我们有一个要求,以处理登录和注册略有不同,在我们的网站部分。对于以下每个URI,我们需要单独的流 /登录Java Spring webflow URI映射到包含斜杠的流ID(“/”),java,spring-webflow,spring-webflow-2,Java,Spring Webflow,Spring Webflow 2,我们有一个要求,以处理登录和注册略有不同,在我们的网站部分。对于以下每个URI,我们需要单独的流 /登录 /注册 /分段/登录 /分段/注册 我们的流量注册表使用webflow文档中的位置模式进行配置: <flow:flow-registry id="flowRegistry" base-path="/WEB-INF/flow" flow-builder-services="flowBuilderServices"> <flow:flow-location-p
/注册
/分段/登录
/分段/注册 我们的流量注册表使用webflow文档中的位置模式进行配置:
<flow:flow-registry id="flowRegistry" base-path="/WEB-INF/flow" flow-builder-services="flowBuilderServices">
<flow:flow-location-pattern value="/**/*-flow.xml" />
</flow:flow-registry>
启用调试日志记录后,我可以在日志中看到创建了四个流,ID为“login”、“signup”、“subsection/login”和“subsection/signup”:
当我去手术室时,一切正常
但是,当我转到或时,URI被映射到“登录”(而不是“小节/登录”)或“注册”(而不是“小节/注册”):
我在调试器中对此进行了跟踪,DefaultFlowUrlHandler.getFlowId方法仅根据最后一个“/”后面的内容返回流ID,因此对于URI“/小节/signup”,返回的流ID只是“signup”
我做错了什么?有没有办法强制实现所需的流映射
谢谢 我知道了。DefaultFlowUrlHandler的文档说明: 希望URL启动流采用以下模式:
http://<host>/[app context path]/[app servlet path]/<flow path>
然后我将这个bean注入我的webflow上下文中的FlowHandlerMapping:
<bean id="uriFlowUrlHandler" class="com.mycompany.web.spring.UriFlowUrlHandler" />
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="flowRegistry" ref="flowRegistry" />
<property name="alwaysUseFullPath" value="true" />
<property name="flowUrlHandler" ref="uriFlowUrlHandler" />
</bean>
也许有更好的方法,但这是有效的
24-Apr 09:32:16,917 DEBUG ajp-bio-8009-exec-5 mvc.servlet.FlowHandlerMapping - Mapping request with URI '/subsection/signup' to flow with id 'signup'
http://<host>/[app context path]/[app servlet path]/<flow path>
public class UriFlowUrlHandler extends DefaultFlowUrlHandler
{
@Override
public String getFlowId(HttpServletRequest request)
{
// Strip off leading "/" and any file extension (e.g., ".jsp")
String uriNoExtension = StringUtils.substringBeforeLast(request.getRequestURI().substring(1), ".");
if (StringUtils.isNotEmpty(uriNoExtension))
return uriNoExtension;
else
return super.getFlowId(request);
}
}
<bean id="uriFlowUrlHandler" class="com.mycompany.web.spring.UriFlowUrlHandler" />
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="flowRegistry" ref="flowRegistry" />
<property name="alwaysUseFullPath" value="true" />
<property name="flowUrlHandler" ref="uriFlowUrlHandler" />
</bean>