Spring Web Stream Request Mapping

I am adding Spring Web Flow 2 to a very large existing web application that does not currently use Spring MVC or Web Flow. My task is to start the web stream by going to mySite.com/flows, and I'm having difficulties. My approach was to configure the DispatcherServlet with the /flows/* mapping and map the web stream to /flows . Here is my web.xml where DispatcherServlet is configured:

 <servlet> <servlet-name>flow</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/flowContext.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>flow</servlet-name> <url-pattern>/flows/*</url-pattern> </servlet-mapping> 

I tried several ways for Web Flow to display on /flows . My first attempt was to use a thread registry with the base-path parameter:

 <webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF/app/flows"> <webflow:flow-location-pattern value="**/*-flow.xml" /> </webflow:flow-registry> 

I understand that this will result in a folder structure inside /WEB-INF/app/flows to create a query mapping. My first test was to add my stream, booking-flow.xml inside a subfolder called booking ( /WEB-INF/app/flows/booking ). And great! - it worked as expected. I was able to access the stream from mySite.com/flows/booking. OK, but I don’t want /booking in the URL, so I moved booking-flow.xml from the booking folder and directly to WEB-INF/app/flows and expected this to work for me, but it’s not - I don’t think that the stream is displayed at all.

Does anyone know how I can map a stream to the root of a DispatcherServlet mapping, or is there a better way to approach this? I do not want DispatcherServlet to handle any requests outside /flows in my application. Is it just me, or is there very little documentation available in the Spring web stream?

Thanks!

+4
source share
3 answers

You can use SimpleUrlHandlerMapping this way to map your stream to mySite.com/flows

 <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings" value="flows=flowController" /> </bean> <bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController"> <property name="flowExecutor" ref="flowExecutor" /> </bean> <webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry"> </webflow:flow-executor> <webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF/app/flows"> <webflow:flow-location path="booking-flow.xml" id="flows"/> </webflow:flow-registry> 
+4
source

Another way could be this:

 <!-- Registry of executable flows --> <flow:flow-registry flow-builder-services="flowBuilderServices" id="flowRegistry" base-path="/WEB-INF/flows/"> <flow:flow-location id="hello" path="hello-flow.xml" /> <flow:flow-location path="start-flow.xml" id="main" /> </flow:flow-registry> 

call streams using id, for example hello .htm or hello .html depending on the url mapping. The first display state in the corresponding file will be loaded.

+1
source

According to your current file structure setting, you can either do

 <webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF/app/flows"> <webflow:flow-location path="booking-flow.xml" id="flows"/> </webflow:flow-registry> 

If you explicitly specify id, in which case the applicable URL will be - mySite.com/flows

OR

you can remove threads from the underlying context -

 <webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF/app"> <webflow:flow-location-pattern value="**/*-flow.xml" /> </webflow:flow-registry> 

and outside the file /WEB-INF/app/flows/booking-flow.xml . This will automatically generate an identifier corresponding to the path between the base path and your file name, which will be flows , and again the applicable URL will be mySite.com/flows

0
source

All Articles