F
- type of FirstTurn
L
- type of LastTurn
O
- type of OutputTurn
I
- type of InputTurn
C
- type of DialogueContext
public abstract class DialogueServlet<I extends InputTurn,O extends OutputTurn,F extends FirstTurn,L extends LastTurn,C extends DialogueContext<I,O>> extends HttpServlet
SynchronousDialogueChannel
.
This abstract servlet must be extended in order to provide a specific implementation. For each session,
Session
and place it in the
SessionContainer
Dialogue
with a DialogueFactory
DialogueContext
with a
DialogueContextFactory
SynchronousDialogueChannel
and starts the dialogue
upon initial HTTP requeststeps
from the dialogue channel into
appropriate HTTP responsesInputTurns
using the
InputTurnFactory
The following servlet initial arguments are supported:
OutputTurn
. Value
specified must be followed by unit (ms, s, m, h, d, y), e.g. 10s
for 10 seconds. Default value: 10 s
InputTurn
. Value
specified must be followed by unit (ms, s, m, h, d, y), e.g. 10s
for 10 seconds. Default value: 5 m
10s
for 10 seconds. Default
value: 30 m
10s
for 10 seconds. Default value: 2 m
HttpSession
should be created for
each dialogue or not. This is useful for load-balancers using JSESSIONID
cookie to enforce server affinity (or stickyness). Value should be
true
or false
. Default value:
true
Constructor and Description |
---|
DialogueServlet() |
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Destroys the servlet.
|
protected abstract void |
destroyDialogueServlet()
Performs shutdown.
|
protected void |
doGet(HttpServletRequest request,
HttpServletResponse response) |
protected void |
doPost(HttpServletRequest request,
HttpServletResponse response) |
protected Session<I,O,F,L,C> |
getExistingSession(String sessionId) |
ILoggerFactory |
getLoggerFactory() |
protected Session<I,O,F,L,C> |
getSession(HttpServletRequest request) |
protected abstract StepRenderer<I,O,L,C> |
getStepRenderer(HttpServletRequest request,
Session<I,O,F,L,C> session)
Provides the
StepRenderer appropriate for the context. |
void |
init()
Initializes the servlet.
|
protected abstract void |
initDialogueServlet()
Performs initialization.
|
protected void |
renderError(Throwable error,
HttpServletRequest request,
HttpServletResponse response,
Session<I,O,F,L,C> session) |
protected void |
renderLastTurn(L result,
HttpServletRequest request,
HttpServletResponse response,
Session<I,O,F,L,C> session) |
protected void |
renderOutputTurn(O outputTurn,
HttpServletRequest request,
HttpServletResponse response,
Session<I,O,F,L,C> session) |
void |
setControllerTimeout(Duration controllerTimeout)
Sets maximum duration the dialogue thread can wait for the controller
response.
|
void |
setDialogueContextFactory(DialogueContextFactory<C,I,O> dialogueContextFactory) |
void |
setDialogueFactory(DialogueFactory<I,O,F,L,C> dialogueFactory) |
void |
setDialogueTimeout(Duration dialogueTimeout)
Sets maximum duration the servlet thread can wait for the dialogue
response.
|
void |
setErrorHandler(ErrorHandler<L> errorHandler) |
void |
setInputTurnFactory(InputTurnFactory<I,F> inputTurnFactory) |
void |
setLoggerFactory(ILoggerFactory loggerFactory) |
void |
setSessionScanPeriod(Duration sessionScanPeriod) |
void |
setSessionTimeout(Duration sessionTimeout) |
void |
setWebappServerSessionTrackingEnabled(boolean enableWebappServerSessionTracking)
Indicates if the servlet should create an HttpSession object for each
dialogue.
|
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
public DialogueServlet()
protected abstract void initDialogueServlet() throws DialogueServletInitializationException
DialogueServletInitializationException
- when servlet can't be
initialized properly.protected abstract void destroyDialogueServlet()
protected abstract StepRenderer<I,O,L,C> getStepRenderer(HttpServletRequest request, Session<I,O,F,L,C> session)
StepRenderer
appropriate for the context.request
- the requestsession
- the sessionStepRenderer
object.public final void init() throws ServletException
initDialogueServlet()
. This method is called by the servlet
container.init
in class GenericServlet
ServletException
public final void destroy()
destroyDialogueServlet()
. This method is called by the servlet
container.destroy
in interface Servlet
destroy
in class GenericServlet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
doGet
in class HttpServlet
ServletException
IOException
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
doPost
in class HttpServlet
ServletException
IOException
public final ILoggerFactory getLoggerFactory()
protected void renderOutputTurn(O outputTurn, HttpServletRequest request, HttpServletResponse response, Session<I,O,F,L,C> session) throws IOException, StepRendererException
IOException
StepRendererException
protected void renderLastTurn(L result, HttpServletRequest request, HttpServletResponse response, Session<I,O,F,L,C> session) throws IOException, StepRendererException
IOException
StepRendererException
protected void renderError(Throwable error, HttpServletRequest request, HttpServletResponse response, Session<I,O,F,L,C> session) throws IOException, StepRendererException
IOException
StepRendererException
public final void setInputTurnFactory(InputTurnFactory<I,F> inputTurnFactory)
public final void setDialogueFactory(DialogueFactory<I,O,F,L,C> dialogueFactory)
public final void setDialogueContextFactory(DialogueContextFactory<C,I,O> dialogueContextFactory)
public final void setLoggerFactory(ILoggerFactory loggerFactory)
public final void setDialogueTimeout(Duration dialogueTimeout)
dialogueTimeout
- the timeout. Cannot be null
. A value
of Duration.ZERO
(or equivalent) means to wait
forever.public final void setControllerTimeout(Duration controllerTimeout)
controllerTimeout
- the timeout. Cannot be null
. A
value of Duration.ZERO
(or equivalent) means to
wait forever.public final void setSessionTimeout(Duration sessionTimeout)
public final void setSessionScanPeriod(Duration sessionScanPeriod)
public final void setErrorHandler(ErrorHandler<L> errorHandler)
public final void setWebappServerSessionTrackingEnabled(boolean enableWebappServerSessionTracking)
HttpSession
.
However, the creation of a session would force the web container to track
the session using a cookie (JSESSIONID) or to do URL-rewriting. This is
only relevant if there is more than one web container fronted by a load
balancer.enableWebappServerSessionTracking
- true if HttpSession are to be
used for session tracking.protected Session<I,O,F,L,C> getSession(HttpServletRequest request) throws SessionNotFoundException
SessionNotFoundException
protected Session<I,O,F,L,C> getExistingSession(String sessionId) throws SessionNotFoundException
SessionNotFoundException
Copyright © 2019 Nu Echo Inc..