Class AbstractRuntime
- java.lang.Object
-
- org.springframework.extensions.webscripts.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 Summary
Fields Modifier and Type Field Description protected RuntimeContainercontainerComponent Dependenciesprotected static org.apache.commons.logging.LogexceptionLoggerprotected static org.apache.commons.logging.Logloggerprotected WebScriptSessionsession
-
Constructor Summary
Constructors Constructor Description AbstractRuntime(RuntimeContainer container)Construct
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected booleanbeforeProcessError(Match match, java.lang.Throwable e)Before processing an error exception - hook point to allow additional processing of the exception based on the runtime.protected abstract AuthenticatorcreateAuthenticator()Create a Web Script Authenticatorprotected abstract WebScriptRequestcreateRequest(Match match)Create a Web Script Requestprotected abstract WebScriptResponsecreateResponse()Create a Web Script Responseprotected abstract WebScriptSessionFactorycreateSessionFactory()Create a Web Script SessionvoidexecuteScript()Execute the Web Script encapsulated by this Web Script Runtimeprotected voidexecuteScript(WebScriptRequest scriptReq, WebScriptResponse scriptRes, Authenticator auth)Execute script given the specified contextContainergetContainer()Gets the Web Script Container within which this Runtime is hostedprotected StatusTemplategetFormatStatusTemplate(java.lang.String format)Get format Status Template pathprotected static WebScriptRequestgetRealWebScriptRequest(WebScriptRequest request)Helper to retrieve real (last) Web Script Request in a stack of wrapped Web Script requestsprotected static WebScriptResponsegetRealWebScriptResponse(WebScriptResponse response)Helper to retrieve real (last) Web Script Response in a stack of wrapped Web Script responsesprotected abstract java.lang.StringgetScriptMethod()Get the Web Script Method e.g.java.util.Map<java.lang.String,java.lang.Object>getScriptParameters()Gets script parametersprotected abstract java.lang.StringgetScriptUrl()Get the Web Script UrlWebScriptSessiongetSession()Get the Web Script Sessionprotected StatusTemplategetStatusCodeTemplate(int statusCode)Get code specific Status Template pathprotected StatusTemplategetStatusTemplate()Get Status Template pathjava.util.Map<java.lang.String,java.lang.Object>getTemplateParameters()Gets template parametersprotected voidrenderErrorResponse(Match match, java.lang.Throwable exception, WebScriptRequest request, WebScriptResponse response)Renders an error message to the response based on the Throwable exception passed in.voidsetURLModelFactory(URLModelFactory urlModelFactory)
-
-
-
Field Detail
-
logger
protected static final org.apache.commons.logging.Log logger
-
exceptionLogger
protected static final org.apache.commons.logging.Log exceptionLogger
-
container
protected RuntimeContainer container
Component Dependencies
-
session
protected WebScriptSession session
-
-
Constructor Detail
-
AbstractRuntime
public AbstractRuntime(RuntimeContainer container)
Construct- Parameters:
container- web script context
-
-
Method Detail
-
getContainer
public Container getContainer()
Description copied from interface:RuntimeGets the Web Script Container within which this Runtime is hosted- Specified by:
getContainerin interfaceRuntime- Returns:
- web script container
-
getSession
public WebScriptSession getSession()
Description copied from interface:RuntimeGet the Web Script Session- Specified by:
getSessionin interfaceRuntime- Returns:
- web script session
-
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 errore- 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- WebScriptRequestscriptRes- WebScriptResponseauth- 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:RuntimeGets script parameters- Specified by:
getScriptParametersin interfaceRuntime- Returns:
- script parameters provided by the runtime
-
getTemplateParameters
public java.util.Map<java.lang.String,java.lang.Object> getTemplateParameters()
Description copied from interface:RuntimeGets template parameters- Specified by:
getTemplateParametersin interfaceRuntime- 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
-
-