Class AbstractRuntime

  • All Implemented Interfaces:
    Runtime
    Direct Known Subclasses:
    WebScriptServletRuntime

    public abstract class AbstractRuntime
    extends java.lang.Object
    implements Runtime
    Encapsulates the execution of a single Web Script. Sub-classes of WebScriptRuntime maintain the execution environment e.g. servlet request & response. A new instance of WebScriptRuntime is required for each invocation.
    Author:
    davidc
    • Field Detail

      • logger

        protected static final org.apache.commons.logging.Log logger
      • exceptionLogger

        protected static final org.apache.commons.logging.Log exceptionLogger
    • Constructor Detail

      • AbstractRuntime

        public AbstractRuntime​(RuntimeContainer container)
        Construct
        Parameters:
        container - web script context
    • Method Detail

      • getContainer

        public Container getContainer()
        Description copied from interface: Runtime
        Gets the Web Script Container within which this Runtime is hosted
        Specified by:
        getContainer in interface Runtime
        Returns:
        web script container
      • setURLModelFactory

        public void setURLModelFactory​(URLModelFactory urlModelFactory)
      • executeScript

        public final void executeScript()
        Execute the Web Script encapsulated by this Web Script Runtime
      • renderErrorResponse

        protected void renderErrorResponse​(Match match,
                                           java.lang.Throwable exception,
                                           WebScriptRequest request,
                                           WebScriptResponse response)
        Renders an error message to the response based on the Throwable exception passed in.
        Parameters:
        match -
        exception -
        request -
        response -
      • beforeProcessError

        protected boolean beforeProcessError​(Match match,
                                             java.lang.Throwable e)
        Before processing an error exception - hook point to allow additional processing of the exception based on the runtime. This allows runtime to handle errors themselves if required - for example silently ignoring missing webscripts.
        Parameters:
        match - WebScript that was processed and caused the error
        e - Exception that occured during webscript processing
        Returns:
        true to continue default error processing, false to assume handling is complete
      • executeScript

        protected void executeScript​(WebScriptRequest scriptReq,
                                     WebScriptResponse scriptRes,
                                     Authenticator auth)
                              throws java.io.IOException
        Execute script given the specified context
        Parameters:
        scriptReq - WebScriptRequest
        scriptRes - WebScriptResponse
        auth - Authenticator
        Throws:
        java.io.IOException
      • getStatusCodeTemplate

        protected StatusTemplate getStatusCodeTemplate​(int statusCode)
        Get code specific Status Template path
        Parameters:
        statusCode - int
        Returns:
        path
      • getFormatStatusTemplate

        protected StatusTemplate getFormatStatusTemplate​(java.lang.String format)
        Get format Status Template path
        Parameters:
        format - String
        Returns:
        path
      • getStatusTemplate

        protected StatusTemplate getStatusTemplate()
        Get Status Template path
        Returns:
        path
      • getScriptParameters

        public java.util.Map<java.lang.String,​java.lang.Object> getScriptParameters()
        Description copied from interface: Runtime
        Gets script parameters
        Specified by:
        getScriptParameters in interface Runtime
        Returns:
        script parameters provided by the runtime
      • getTemplateParameters

        public java.util.Map<java.lang.String,​java.lang.Object> getTemplateParameters()
        Description copied from interface: Runtime
        Gets template parameters
        Specified by:
        getTemplateParameters in interface Runtime
        Returns:
        template parameters provided by the runtime
      • getScriptMethod

        protected abstract java.lang.String getScriptMethod()
        Get the Web Script Method e.g. get, post
        Returns:
        web script method
      • getScriptUrl

        protected abstract java.lang.String getScriptUrl()
        Get the Web Script Url
        Returns:
        web script url
      • createRequest

        protected abstract WebScriptRequest createRequest​(Match match)
        Create a Web Script Request
        Parameters:
        match - web script matching the script method and url
        Returns:
        web script request
      • createResponse

        protected abstract WebScriptResponse createResponse()
        Create a Web Script Response
        Returns:
        web script response
      • createAuthenticator

        protected abstract Authenticator createAuthenticator()
        Create a Web Script Authenticator
        Returns:
        web script authenticator
      • createSessionFactory

        protected abstract WebScriptSessionFactory createSessionFactory()
        Create a Web Script Session
      • getRealWebScriptRequest

        protected static WebScriptRequest getRealWebScriptRequest​(WebScriptRequest request)
        Helper to retrieve real (last) Web Script Request in a stack of wrapped Web Script requests
        Parameters:
        request - WebScriptRequest
        Returns:
        WebScriptRequest
      • getRealWebScriptResponse

        protected static WebScriptResponse getRealWebScriptResponse​(WebScriptResponse response)
        Helper to retrieve real (last) Web Script Response in a stack of wrapped Web Script responses
        Parameters:
        response - WebScriptResponse
        Returns:
        WebScriptResponse