Spring webflow - end flow and execution snapshots?

Trying to answer my own question led me to the following piece of code.

Trying to answer my own question led me to the following piece of code: public void endFlow() { if (context! = null && definition! = null) { ExternalContextHolder.

SetExternalContext(contex. GetExternalContext()); context. RemoveAllFlowExecutionSnapshots(); context.

EndActiveFlowSession(definition.getId(), definition.getAttributes()); Flow flow = (Flow)definition; flow.destroy(); } } The ExternalContextHolder... line avoids the NPE, and snapshots are removed and flowSession its also terminated, Yet new questions have arisen why is ExternalContextHolder necessary? Is it ok?. Below is some weird(or is it normal?) behaviour im getting Suppose i've started a flow e1s1 in browser tab1 and also e2s1 in another tab, now if im on e2s1 and click 'next' button on my wizard I get e2s2(this is right), now if I remove execution snapshots that belong to e1s1, they are removed without problems, but if go to tab where e2s2 is and I click 'previous' button so I can return to previous snapshot, snapshot e2s1 is also gone, I mean shouldnt snapshot removal be like something "per execution".

I have tested new code to remove flow execution (using method removeFlowExecution from class FlowExecutionRepository) but right now I won't show it, instead ill wait if someone can throw some pointers. Anyway if nothing shows up ill be keeping anyone interested in the loop. Once again im answering my question, hopefully this is the last answer.

Q: why is ExternalContextHolder necessary? Ans: according to my little experience ExternalContextHolder probably among other things, is needed so spring has access(HttpServletRequest and HttpServletResponse) to the data sent from whoever is doing the request.In the end removing flowexecution from a filter might sound like a good idea, but webflow gives us a better approach yet, I mean subclassing FlowExecutionListenerAdapter and in this case we I overrode method "void requestSubmitted(RequestContext context)" and here I check wheter or not current user has access to roomId and then I will call method endFlow(see code below) public void endFlow(ExternalContext externalContext) { FlowUrlHandler handler = flowController. GetFlowUrlHandler(); HttpServletRequest request = (HttpServletRequest) externalContext.

GetNativeRequest(); String stringKey = handler. GetFlowExecutionKey(request); if (stringKey! = null) { FlowExecutorImpl flowExecutor = (FlowExecutorImpl) flowController.getFlowExecutor(); FlowExecutionRepository repository = flowExecutor.

GetExecutionRepository(); FlowExecutionKey key = repository. ParseFlowExecutionKey(stringKey); ExternalContextHolder. SetExternalContext(externalContext); FlowExecutionLock lock = null; try{ lock = repository.

GetLock(key); }catch(NoSuchFlowExecutionException nsfee){ return; } lock.lock(); try { FlowExecution flowExecution = repository. GetFlowExecution(key); repository. RemoveFlowExecution(flowExecution); } finally { lock.unlock(); } } } flowController(org.springframework.webflow.mvc.servlet.

FlowController) is injected by spring and its added in our webflow config file. The above code removes flow Execution completely and if user tries to return to previous flow, lets say e1s1 then webflow automatically creates a new flow execution e2s1, and thats it. In case you want to use the filter approach all you need in doFilter method its this public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; String roomId = req.

GetParameter("roomId"); ExternalContext externalContext = new ServletExternalContext( this. ServletContext, req, resp); if (roomId! = null) { if (!currentUserHasAccess(roomId)) { flowExecutionManager.endFlow(); return; } } chain.

DoFilter(request, response); this. ServletContext its obtained through filterConfig. GetServletContext().

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions