Class FlowHandlerAdapter

java.lang.Object
org.springframework.context.support.ApplicationObjectSupport
org.springframework.web.context.support.WebApplicationObjectSupport
org.springframework.web.servlet.support.WebContentGenerator
org.springframework.webflow.mvc.servlet.FlowHandlerAdapter
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.web.context.ServletContextAware, org.springframework.web.servlet.HandlerAdapter
Direct Known Subclasses:
JsfFlowHandlerAdapter

public class FlowHandlerAdapter extends org.springframework.web.servlet.support.WebContentGenerator implements org.springframework.web.servlet.HandlerAdapter, org.springframework.beans.factory.InitializingBean
A custom MVC HandlerAdapter that encapsulates the generic workflow associated with executing flows in a Servlet environment. Delegates to mapped flow handlers to manage the interaction with executions of specific flow definitions.
Author:
Keith Donald, Phillip Webb
  • Field Summary

    Fields inherited from class org.springframework.web.servlet.support.WebContentGenerator

    HEADER_CACHE_CONTROL, METHOD_GET, METHOD_HEAD, METHOD_POST
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new flow handler adapter.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    createServletExternalContext(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    Creates the servlet external context for the current HTTP servlet request.
    defaultCreateFlowExecutionInputMap(jakarta.servlet.http.HttpServletRequest request)
    The default algorithm to create the flow execution input map.
    protected String
    defaultGetFlowId(jakarta.servlet.http.HttpServletRequest request)
    The default algorithm to determine the id of the flow to launch from the current request.
    protected void
    defaultHandleException(String flowId, FlowException e, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    The default algorithm for handling a FlowException now handled by the Web Flow system.
    protected void
    defaultHandleExecutionOutcome(String flowId, FlowExecutionOutcome outcome, ServletExternalContext context, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    The default algorithm for handling a flow execution outcome.
    Returns the configured Ajax handler.
    Returns the central service for executing flows.
    Returns the flow url handler.
    Return the configured hosts associated with the application.
    long
    getLastModified(jakarta.servlet.http.HttpServletRequest request, Object handler)
     
    boolean
    Whether redirect sent by this handler adapter should be compatible with HTTP 1.0 clients.
    boolean
    Whether servlet relative redirects should pass flow output to the Spring MVC flash scope.
    org.springframework.web.servlet.ModelAndView
    handle(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Object handler)
     
    protected boolean
    isRemoteHost(String targetUrl)
    Whether the given targetUrl has a host that is a "foreign" system in which case HttpServletResponse.encodeRedirectURL(java.lang.String) will not be applied.
    protected void
    sendRedirect(String url, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    Sends a redirect to the requested url using HttpServletResponse.sendRedirect(String).Called to actually perform flow execution redirects, flow definition redirects, and external redirects.
    void
    Sets the configured Ajax handler.
    void
    Sets the central service for executing flows.
    void
    Sets the flow url handler
    void
    setHosts(String[] hosts)
    Configure one or more hosts associated with the application.
    void
    setRedirectHttp10Compatible(boolean redirectHttp10Compatible)
    Set whether redirects sent by this handler adapter should be compatible with HTTP 1.0 clients.
    void
    setSaveOutputToFlashScopeOnRedirect(boolean saveOutputToFlashScopeOnRedirect)
    Set whether servlet relative redirects sent by this handler adapter should pass flow output to the Spring MVC flash scope.
    void
    setStatusCode(org.springframework.http.HttpStatus statusCode)
    Set the status code for this view.
    boolean
    supports(Object handler)
     

    Methods inherited from class org.springframework.web.servlet.support.WebContentGenerator

    applyCacheControl, applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkRequest, getAllowHeader, getCacheControl, getCacheSeconds, getSupportedMethods, getVaryByRequestHeaders, isAlwaysMustRevalidate, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, prepareResponse, preventCaching, setAlwaysMustRevalidate, setCacheControl, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader, setVaryByRequestHeaders

    Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport

    getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext

    Methods inherited from class org.springframework.context.support.ApplicationObjectSupport

    getApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • getFlowExecutor

      public FlowExecutor getFlowExecutor()
      Returns the central service for executing flows. Required.
    • setFlowExecutor

      public void setFlowExecutor(FlowExecutor flowExecutor)
      Sets the central service for executing flows. Required.
      Parameters:
      flowExecutor -
    • getFlowUrlHandler

      public FlowUrlHandler getFlowUrlHandler()
      Returns the flow url handler.
    • setFlowUrlHandler

      public void setFlowUrlHandler(FlowUrlHandler flowUrlHandler)
      Sets the flow url handler
      Parameters:
      flowUrlHandler - the flow url handler
    • getAjaxHandler

      public AjaxHandler getAjaxHandler()
      Returns the configured Ajax handler.
    • setAjaxHandler

      public void setAjaxHandler(AjaxHandler ajaxHandler)
      Sets the configured Ajax handler.
      Parameters:
      ajaxHandler - the ajax handler
    • getRedirectHttp10Compatible

      public boolean getRedirectHttp10Compatible()
      Whether redirect sent by this handler adapter should be compatible with HTTP 1.0 clients.
      Returns:
      true if so, false otherwise
    • setRedirectHttp10Compatible

      public void setRedirectHttp10Compatible(boolean redirectHttp10Compatible)
      Set whether redirects sent by this handler adapter should be compatible with HTTP 1.0 clients.

      By default, this will enforce a redirect HTTP status code of 302 by delegating to HttpServletResponse.sendRedirect. Setting this to false will send HTTP status code 303, which is the correct code for HTTP 1.1 clients, but not understood by HTTP 1.0 clients.

      Many HTTP 1.1 clients treat 302 just like 303, not making any difference. However, some clients depend on 303 when redirecting after a POST request; turn this flag off in such a scenario.

      See Also:
      • HttpServletResponse.sendRedirect(java.lang.String)
    • setStatusCode

      public void setStatusCode(org.springframework.http.HttpStatus statusCode)
      Set the status code for this view.

      Default is to send 302/303, depending on the value of the http10Compatible flag.

    • setHosts

      public void setHosts(String[] hosts)
      Configure one or more hosts associated with the application. All other hosts will be considered external hosts. In effect this property provides a way turn off encoding via HttpServletResponse.encodeRedirectURL(java.lang.String) for URLs that have a host and that host is not listed as a known host.

      If not set (the default) all URLs are encoded through the response.

      Parameters:
      hosts - one or more application hosts
      Since:
      2.4.3
    • getHosts

      public String[] getHosts()
      Return the configured hosts associated with the application.
    • setSaveOutputToFlashScopeOnRedirect

      public void setSaveOutputToFlashScopeOnRedirect(boolean saveOutputToFlashScopeOnRedirect)
      Set whether servlet relative redirects sent by this handler adapter should pass flow output to the Spring MVC flash scope.

      By default, to remain compatible with previous releases, flow output is not mapped to flash scope.

      Parameters:
      saveOutputToFlashScopeOnRedirect -
    • getSaveOutputToFlashScopeOnRedirect

      public boolean getSaveOutputToFlashScopeOnRedirect()
      Whether servlet relative redirects should pass flow output to the Spring MVC flash scope.
      Returns:
      true if so, false otherwise
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception
    • supports

      public boolean supports(Object handler)
      Specified by:
      supports in interface org.springframework.web.servlet.HandlerAdapter
    • handle

      public org.springframework.web.servlet.ModelAndView handle(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Object handler) throws Exception
      Specified by:
      handle in interface org.springframework.web.servlet.HandlerAdapter
      Throws:
      Exception
    • getLastModified

      public long getLastModified(jakarta.servlet.http.HttpServletRequest request, Object handler)
      Specified by:
      getLastModified in interface org.springframework.web.servlet.HandlerAdapter
    • createServletExternalContext

      protected ServletExternalContext createServletExternalContext(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      Creates the servlet external context for the current HTTP servlet request.
      Parameters:
      request - the current request
      response - the current response
    • defaultGetFlowId

      protected String defaultGetFlowId(jakarta.servlet.http.HttpServletRequest request)
      The default algorithm to determine the id of the flow to launch from the current request. Only called if FlowHandler.getFlowId() returns null. This implementation delegates to the configured FlowUrlHandler.getFlowId(HttpServletRequest). Subclasses may override.
      Parameters:
      request - the current request
    • defaultCreateFlowExecutionInputMap

      protected MutableAttributeMap<Object> defaultCreateFlowExecutionInputMap(jakarta.servlet.http.HttpServletRequest request)
      The default algorithm to create the flow execution input map. Only called if FlowHandler.createExecutionInputMap(HttpServletRequest) returns null. This implementation exposes all current request parameters as flow execution input attributes. Subclasses may override.
      Parameters:
      request - the current request
    • defaultHandleExecutionOutcome

      protected void defaultHandleExecutionOutcome(String flowId, FlowExecutionOutcome outcome, ServletExternalContext context, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException
      The default algorithm for handling a flow execution outcome. Only called if FlowHandler.handleExecutionOutcome(FlowExecutionOutcome, HttpServletRequest, HttpServletResponse) returns null. This implementation attempts to start a new execution of the ended flow. Any flow execution output is passed as input to the new execution. Subclasses may override.
      Parameters:
      flowId - the id of the ended flow
      outcome - the flow execution outcome
      context - ServletExternalContext the completed ServletExternalContext
      request - the current request
      response - the current response
      Throws:
      IOException
    • defaultHandleException

      protected void defaultHandleException(String flowId, FlowException e, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException
      The default algorithm for handling a FlowException now handled by the Web Flow system. Only called if FlowHandler.handleException(FlowException, HttpServletRequest, HttpServletResponse) returns null. This implementation rethrows the exception unless it is a NoSuchFlowExecutionException. If the exception is a NoSuchFlowExecutionException, this implementation attempts to start a new execution of the ended or expired flow. Subclasses may override.
      Parameters:
      flowId - the id of the ended flow
      e - the flow exception
      request - the current request
      response - the current response
      Throws:
      IOException
    • sendRedirect

      protected void sendRedirect(String url, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException
      Sends a redirect to the requested url using HttpServletResponse.sendRedirect(String).Called to actually perform flow execution redirects, flow definition redirects, and external redirects. Subclasses may override to customize general Web Flow system redirect behavior.
      Parameters:
      url - the url to redirect to
      request - the current request
      response - the current response
      Throws:
      IOException - an exception occurred
    • isRemoteHost

      protected boolean isRemoteHost(String targetUrl)
      Whether the given targetUrl has a host that is a "foreign" system in which case HttpServletResponse.encodeRedirectURL(java.lang.String) will not be applied. This method returns true if the setHosts(String[]) property is configured and the target URL has a host that does not match.
      Parameters:
      targetUrl - the target redirect URL
      Returns:
      true the target URL has a remote host, false if it the URL does not have a host or the "host" property is not configured.
      Since:
      2.4.3