atg.userprofiling.email
Class TemplateInvoker

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.nucleus.logging.LogRedirectingGenericService
              extended by atg.userprofiling.email.TemplateInvoker
All Implemented Interfaces:
atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, atg.servlet.TemplateEmailConstants, java.util.EventListener

public class TemplateInvoker
extends atg.nucleus.logging.LogRedirectingGenericService
implements atg.servlet.TemplateEmailConstants

A class for invoking rendering a specified JSP/JHTML template. Works via loop-backs on application servers other than DAS.

Users can call createSession(), and then on the sesion invoke renderTemplate() for each template to be rendered, followed by endSession();

Created: May 04 2004

See Also:
RequestResponseInitializer

Nested Class Summary
 class TemplateInvoker.TemplateSession
          Represents a template rendering session.
 
Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from class atg.nucleus.logging.LogRedirectingGenericService
mApplicationLogger
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.servlet.TemplateEmailConstants
ATTR_EMAIL_SESSION, ATTR_INPUT_PARAMS, ATTR_PREFIX, ATTR_SESSION_COOKIES, PARAM_FILL_FROM_TEMPLATE, PARAM_MAILING_NAME, PARAM_MESSAGE_ATTACHMENTS, PARAM_MESSAGE_BCC, PARAM_MESSAGE_CC, PARAM_MESSAGE_FROM, PARAM_MESSAGE_REPLY_TO, PARAM_MESSAGE_SUBJECT, PARAM_MESSAGE_TO, TEMPLATE_PARAMS
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
TemplateInvoker()
          No-arg constructor for Nucleus.
TemplateInvoker(TemplateEmailSender pSender)
          Constructor for initializing from TemplateEmailSender, which is used for backwards compatability.
 
Method Summary
protected  atg.servlet.GenericHttpServletRequest createGenericHttpServletRequest(javax.servlet.http.HttpSession pSession, java.lang.String pSessionId, java.lang.String pTemplateURL)
          Create a GenericHttpServletRequest.
protected  DynamoHttpServletRequest createRequest(DynamoHttpServletResponse pResponse, java.lang.String pTemplateUrl, java.util.Dictionary pParameters, javax.servlet.http.HttpSession pSession, java.lang.String pSessionId)
          Creates and returns a "fake" request with the path info specified by the given TemplateEmailInfo's templateURL.
protected  DynamoHttpServletResponse createResponse()
          Creates and returns a "fake" response.
 TemplateInvoker.TemplateSession createSession(java.util.Map pParameterMap, atg.userprofiling.email.RequestResponseInitializer pReqResInitializer)
          Create a session for TemplateEmailRendering.
protected  javax.servlet.http.HttpSession createTemplateEmailSession()
          Creates an HTTP session by making a loopback request.
 java.lang.String getApplicationPrefix()
          Returns the Dynamo application prefix.
 java.lang.String getDefaultContentType()
          Get the default content type (probably "text/html").
 java.lang.String getDynamoInitSessionURL()
          URL for a page from which to obtain the initial session on DAS.
 java.lang.String getInitSessionURL()
          Returns the URL to use when creating a session via a loopback request, when running in another app server.
 boolean getLoopbackRequestsEnabled()
          Returns the flag indicating whether loopback requests should be performed when running in another app server.
 HeadPipelineServlet getRequestSetupServlet()
          Returns the HeadPipelineServlet that will be used to service each newly created request and thus setup the request for name resolution, associate it with a session, etc.
 atg.servlet.sessiontracking.DynamoSessionManager getSessionManager()
          Returns the session manager.
 java.lang.String getSiteHttpServerName()
          Returns the name of the server configured to serve HTTP requests.
 int getSiteHttpServerPort()
          Returns the port of the server configured to serve HTTP requests.
 javax.servlet.Servlet getTemplateRendererServlet()
          Returns the Servlet responsible for rendering the template.
 void setApplicationPrefix(java.lang.String pApplicationPrefix)
          Sets the Dynamo application prefix.
 void setDefaultContentType(java.lang.String pDefaultContentType)
          Set the default content type (probably "text/html").
 void setDynamoInitSessionURL(java.lang.String pDynamoInitSessionURL)
          URL for a page from which to obtain the initial session on DAS.
 void setInitSessionURL(java.lang.String pInitSessionURL)
          Sets the URL to use when creating a session via a loopback request, when running in another app server.
 void setLoopbackRequestsEnabled(boolean pLoopbackRequestsEnabled)
          Sets the flag indicating whether loopback requests should be performed when running in another app server.
 void setRequestSetupServlet(HeadPipelineServlet pServlet)
          Sets the HeadPipelineServlet that will be used to service each newly created request and thus setup the request for name resolution, associate it with a session, etc.
 void setSessionManager(atg.servlet.sessiontracking.DynamoSessionManager pSessionManager)
          Sets the session manager.
 void setSiteHttpServerName(java.lang.String pSiteHttpServerName)
          Sets the name of the server configured to serve HTTP requests.
 void setSiteHttpServerPort(int port)
          Sets the port of the server configured to serve HTTP requests.
 void setTemplateRendererServlet(javax.servlet.Servlet pServlet)
          Sets the Servlet responsible for rendering the template.
protected  boolean useLocalRequests()
          Whether to use local requests.
protected  void verifyResponseStatus(java.lang.String pPathInfo, int pStatus, java.lang.String pErrorMessage)
          Verifies that the response came back with no errors.
 
Methods inherited from class atg.nucleus.logging.LogRedirectingGenericService
format, format, format, format, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingWarning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logWarning, logWarning, logWarning, setApplicationLogger, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingWarning
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingTrace, isRunning, logTrace, logTrace, logTrace, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingTrace, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

TemplateInvoker

public TemplateInvoker()
No-arg constructor for Nucleus.


TemplateInvoker

public TemplateInvoker(TemplateEmailSender pSender)
Constructor for initializing from TemplateEmailSender, which is used for backwards compatability.

Parameters:
pSender - The TemplateEmailSender whose properties we will use for configuration.
Method Detail

getApplicationPrefix

public java.lang.String getApplicationPrefix()
Returns the Dynamo application prefix. This is used for loopback requests when running in another app server.


setApplicationPrefix

public void setApplicationPrefix(java.lang.String pApplicationPrefix)
Sets the Dynamo application prefix. This is used for loopback requests when running in another app server.


getInitSessionURL

public java.lang.String getInitSessionURL()
Returns the URL to use when creating a session via a loopback request, when running in another app server.


setInitSessionURL

public void setInitSessionURL(java.lang.String pInitSessionURL)
Sets the URL to use when creating a session via a loopback request, when running in another app server.


setDynamoInitSessionURL

public void setDynamoInitSessionURL(java.lang.String pDynamoInitSessionURL)
URL for a page from which to obtain the initial session on DAS.


getDynamoInitSessionURL

public java.lang.String getDynamoInitSessionURL()
URL for a page from which to obtain the initial session on DAS.


getSessionManager

public atg.servlet.sessiontracking.DynamoSessionManager getSessionManager()
Returns the session manager.


setSessionManager

public void setSessionManager(atg.servlet.sessiontracking.DynamoSessionManager pSessionManager)
Sets the session manager.


getLoopbackRequestsEnabled

public boolean getLoopbackRequestsEnabled()
Returns the flag indicating whether loopback requests should be performed when running in another app server.


setLoopbackRequestsEnabled

public void setLoopbackRequestsEnabled(boolean pLoopbackRequestsEnabled)
Sets the flag indicating whether loopback requests should be performed when running in another app server.

This value is true by default. It can be set to false if you are only using this TemplateEmailSender with DSP templates, rather than JSP templates, since DSP templates can always be rendered without making loopback requests.

Note: if you set this property to false, you should also set the contextPathPrefix property to null, so that the template URLs are not prefixed with "/dyn/dyn," but left to be relative to the Dynamo docroot.


getSiteHttpServerName

public java.lang.String getSiteHttpServerName()
Returns the name of the server configured to serve HTTP requests. This is used for loopback requests when running in another app server.


setSiteHttpServerName

public void setSiteHttpServerName(java.lang.String pSiteHttpServerName)
Sets the name of the server configured to serve HTTP requests. This is used for loopback requests when running in another app server.


getSiteHttpServerPort

public int getSiteHttpServerPort()
Returns the port of the server configured to serve HTTP requests. This is used for loopback requests when running in another app server.


setSiteHttpServerPort

public void setSiteHttpServerPort(int port)
Sets the port of the server configured to serve HTTP requests. This is used for loopback requests when running in another app server.


getTemplateRendererServlet

public javax.servlet.Servlet getTemplateRendererServlet()
Returns the Servlet responsible for rendering the template.

This servlet's service method will be invoked by the renderTemplate method. If you are implementing your own servlet to do the rendering, note that your servlet can access the template URL by calling getPathInfo on the request.


setTemplateRendererServlet

public void setTemplateRendererServlet(javax.servlet.Servlet pServlet)
Sets the Servlet responsible for rendering the template.

This servlet's service method will be invoked by the renderTemplate method. If you are implementing your own servlet to do the rendering, note that your servlet can access the template URL by calling getPathInfo on the request.


getRequestSetupServlet

public HeadPipelineServlet getRequestSetupServlet()
Returns the HeadPipelineServlet that will be used to service each newly created request and thus setup the request for name resolution, associate it with a session, etc.


setRequestSetupServlet

public void setRequestSetupServlet(HeadPipelineServlet pServlet)
Sets the HeadPipelineServlet that will be used to service each newly created request and thus setup the request for name resolution, associate it with a session, etc.


setDefaultContentType

public void setDefaultContentType(java.lang.String pDefaultContentType)
Set the default content type (probably "text/html"). This gets set on the response each time, so that if a previously rendered page set the content type, all will be well.


getDefaultContentType

public java.lang.String getDefaultContentType()
Get the default content type (probably "text/html"). This gets set on the response each time, so that if a previously rendered page set the content type, all will be well.


createRequest

protected DynamoHttpServletRequest createRequest(DynamoHttpServletResponse pResponse,
                                                 java.lang.String pTemplateUrl,
                                                 java.util.Dictionary pParameters,
                                                 javax.servlet.http.HttpSession pSession,
                                                 java.lang.String pSessionId)
                                          throws TemplateEmailException
Creates and returns a "fake" request with the path info specified by the given TemplateEmailInfo's templateURL. The request is sent down the servlet pipeline once, so that it has a session associated with it, it can be used to resolve names, etc.

Parameters:
pTemplateUrl - the URL for the template (typically the dynamoInitSessionURL).
pParameters - the dictionary of parameters
pSession - the session
pSessionId - the session id
Throws:
TemplateEmailException - if a problem was encountered while obtaining or servicing the request

createResponse

protected DynamoHttpServletResponse createResponse()
Creates and returns a "fake" response.


createTemplateEmailSession

protected javax.servlet.http.HttpSession createTemplateEmailSession()
                                                             throws TemplateEmailException
Creates an HTTP session by making a loopback request. This method is only called if we are running in another (non-ATG) app server; otherwise the session is created via a dummy request internally.

Throws:
TemplateEmailException

createGenericHttpServletRequest

protected atg.servlet.GenericHttpServletRequest createGenericHttpServletRequest(javax.servlet.http.HttpSession pSession,
                                                                                java.lang.String pSessionId,
                                                                                java.lang.String pTemplateURL)
Create a GenericHttpServletRequest. One is created for each template rendered. This request will be wrapped by a DynamoHttpServletRequest.

Parameters:
pSession - the session to use
pSessionId - the parent session Id
pTemplateUrl - the URL of the template to be rendered.

createSession

public TemplateInvoker.TemplateSession createSession(java.util.Map pParameterMap,
                                                     atg.userprofiling.email.RequestResponseInitializer pReqResInitializer)
                                              throws TemplateEmailException
Create a session for TemplateEmailRendering. endSession() should be called to restore the current thread request and free session resources.

Parameters:
pParameterMap - Parameters that should be set on each request.
pReqResInitializer - An object that implements pReqResInitializer to do additional request/response initialization.
Throws:
TemplateEmailException

verifyResponseStatus

protected void verifyResponseStatus(java.lang.String pPathInfo,
                                    int pStatus,
                                    java.lang.String pErrorMessage)
                             throws TemplateEmailException
Verifies that the response came back with no errors. If it didn't (i.e., if status is not 200), throws an exception which attempts to describe the nature of the problem.

Parameters:
pPathInfo - The path info for the request, just used for error reporting
pStatus - the HTTP status code integer from the HTTP response
pErrorMessage - The error message from the HTTP response
Throws:
TemplateEmailException

useLocalRequests

protected boolean useLocalRequests()
Whether to use local requests. Only use local requests on DAS.