Class AristaFlowHTTPService
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- de.aristaflow.adept2.ui.htmlgui.httpservice.AristaFlowHTTPService
-
- All Implemented Interfaces:
ADEPT2Service
,DynamicServlet
,HTTPService
,Serializable
,javax.servlet.Servlet
,javax.servlet.ServletConfig
public class AristaFlowHTTPService extends javax.servlet.http.HttpServlet implements HTTPService, DynamicServlet
Servlet implementation for the HTTP service of the HTML context.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Logger
logger
My logger.protected Map<String,HTTPReplyHandler>
replyHandlers
The reply handlers to which HTTP-requests are forwarded after the decoding.protected String
servletName
The name of the servlet if dynamically deployed,null
otherwise.protected Map<UUID,String>
sessions
Own session IDs.
-
Constructor Summary
Constructors Constructor Description AristaFlowHTTPService()
Constructor for initialisation via Extension Point (must not have any parameters).AristaFlowHTTPService(String servletName)
Constructor providing a servlet name for dynamic servlet deployment.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
deregisterReplyHandler(SessionToken session, String sessionID)
Deregisters a reply handler for the activity with the designatedsessionID
.protected void
doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
protected void
doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
protected List<String>
getListValue(Object o)
Returns the string list value for the given object, or null if the object is not a representation of a list-valued string value.URI[]
getLocalUris()
Returns the URIs under which the service is locally exported.protected Pair<Map<String,HTMLContext.Attachment>,Map<String,List<HTMLContext.Attachment>>>
getParameterAttachments(List<org.apache.commons.fileupload.FileItem> items)
Gets new maps for the designated items being transformed toAttachment
s.protected void
getParameterAttachments(List<org.apache.commons.fileupload.FileItem> items, Map<String,HTMLContext.Attachment> attachments, Map<String,List<HTMLContext.Attachment>> attachmentLists)
Deprecated, for removal: This API element is subject to removal in a future version.Use the more efficientgetParameterAttachments(List)
instead.protected Map<String,List<String>>
getParameterLists(List<org.apache.commons.fileupload.FileItem> items)
Returns all list valued string parameters.protected Map<String,List<String>>
getParameterLists(javax.servlet.http.HttpServletRequest request)
Retrieves all list-valued parameters from the request and returns them as map.protected Map<String,String>
getParameters(List<org.apache.commons.fileupload.FileItem> items)
Returns all non-list-valued string parameters.protected Map<String,String>
getParameters(javax.servlet.http.HttpServletRequest request)
Retrieves all non-list-valued and non-attachment parameters from the request and returns them as map.SerialisablePair<String,String>
getRelease()
This service is started outside of the platform and therefore does not support the methods ofADEPT2Service
.String[]
getRuntimeRequiredServices()
Returns a list of service types, which are requested when needed at runtime.SerialisableTriple<String,String,String>
getServiceInstanceName()
This service is started outside of the platform and therefore does not support the methods ofADEPT2Service
.String
getServletName()
Gets the name of the servlet.String[]
getStartupRequiredServices()
Returns a list of service types, which are required for executing the service.protected String
getStringValue(Object o)
Returns the string value for the given object, or null if the object is not a representation of a (non-list-valued) string value.URI[]
getURIs()
Returns the URIs which are set for this service inADEPT2Service.init(URI[], URI[])
.void
init(URI[] localExportedUris, URI[] globalExportedUris)
Not forwarded since no client component should control the service.long
ping()
Gets whether the service is running and accepts requests or not and since when.void
preShutdown(boolean emergency)
Not forwarded since no client component should control the service.void
registerReplyHandler(SessionToken session, String sessionID, HTTPReplyHandler replyHandler)
Registers a reply handler for the activity with the designatedsessionID
.void
servletDeployed(javax.servlet.ServletContext context, String urlPattern)
Notifies the servlet that it has been deployed with the designated context and the designated pattern.void
servletUndeployed(javax.servlet.ServletContext context)
Notifies the servlet that it has been undeployed.void
setURL(URL myURL)
Set the URL to be used for the HTML contexts.void
shutdown(boolean emergency)
Not forwarded since no client component should control the service.void
start()
Not forwarded since no client component should control the service.-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
-
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, init, init, log, log
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.aristaflow.adept2.base.servletcontainer.DynamicServlet
servletDeployed
-
-
-
-
Field Detail
-
logger
protected final transient Logger logger
My logger.
-
replyHandlers
protected final Map<String,HTTPReplyHandler> replyHandlers
The reply handlers to which HTTP-requests are forwarded after the decoding. This maps the session ID to the corresponding reply handler-instance.
-
servletName
protected String servletName
The name of the servlet if dynamically deployed,null
otherwise.
-
-
Constructor Detail
-
AristaFlowHTTPService
public AristaFlowHTTPService()
Constructor for initialisation via Extension Point (must not have any parameters).
-
AristaFlowHTTPService
public AristaFlowHTTPService(String servletName)
Constructor providing a servlet name for dynamic servlet deployment.- Parameters:
servletName
- The name of the servlet if dynamically deployed,null
otherwise.
-
-
Method Detail
-
setURL
public void setURL(URL myURL)
Set the URL to be used for the HTML contexts.- Parameters:
myURL
-
-
doGet
protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
- Overrides:
doGet
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
IOException
-
doPost
protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
- Overrides:
doPost
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
IOException
-
deregisterReplyHandler
public void deregisterReplyHandler(SessionToken session, String sessionID)
Description copied from interface:HTTPService
Deregisters a reply handler for the activity with the designatedsessionID
. A reply handler may be deregistered any time. In case a reply handling is currently running, it will be allowed to finish.- Specified by:
deregisterReplyHandler
in interfaceHTTPService
- Parameters:
session
- The session which is used to check for access rights on this method.sessionID
- The session ID identifying the executed activity and therefore also the handler for the reply sent via HTTP.
-
registerReplyHandler
public void registerReplyHandler(SessionToken session, String sessionID, HTTPReplyHandler replyHandler) throws MalformedURLException
Description copied from interface:HTTPService
Registers a reply handler for the activity with the designatedsessionID
. This creates an own URL for the reply handler. It will be called as soon as a HTTP-request (the reply for the activity) is received by this HTTP-service.- Specified by:
registerReplyHandler
in interfaceHTTPService
- Parameters:
session
- The session which is used to check for access rights on this method.sessionID
- The session ID for the executed activity. It is used to create an appropriate URL.replyHandler
- The handler for the HTTP-replies sent to this service.- Throws:
MalformedURLException
- If the designated sessionID does not allow to create a valid URL, aMalformedURLException
will be thrown.
-
getParameters
protected Map<String,String> getParameters(javax.servlet.http.HttpServletRequest request)
Retrieves all non-list-valued and non-attachment parameters from the request and returns them as map.- Parameters:
request
-- Returns:
- The parameters as map from name to parameter value.
-
getParameterLists
protected Map<String,List<String>> getParameterLists(javax.servlet.http.HttpServletRequest request)
Retrieves all list-valued parameters from the request and returns them as map.- Parameters:
request
-- Returns:
- The parameters as map from name to list of parameter values.
-
getParameters
protected Map<String,String> getParameters(List<org.apache.commons.fileupload.FileItem> items)
Returns all non-list-valued string parameters.- Parameters:
items
-- Returns:
- All string parameters.
-
getParameterLists
protected Map<String,List<String>> getParameterLists(List<org.apache.commons.fileupload.FileItem> items)
Returns all list valued string parameters.- Parameters:
items
-- Returns:
- All list valued string parameters.
-
getParameterAttachments
protected Pair<Map<String,HTMLContext.Attachment>,Map<String,List<HTMLContext.Attachment>>> getParameterAttachments(List<org.apache.commons.fileupload.FileItem> items)
Gets new maps for the designated items being transformed toAttachment
s. If a file name exists several times in the designateditems
, all files will be added to the second element of the pair. File names occurring just once will be part of the first element of the pair.- Parameters:
items
- The file items being provided by a servlet request.- Returns:
- The designated files transformed to
Attachment
s indexed by file names. If a file name occurs once, the corresponding attachment will be in the first element of the pair, otherwise it will be in the second element and part of a list of attachments.
-
getParameterAttachments
@Deprecated(since="15.0.0", forRemoval=true) protected void getParameterAttachments(List<org.apache.commons.fileupload.FileItem> items, Map<String,HTMLContext.Attachment> attachments, Map<String,List<HTMLContext.Attachment>> attachmentLists)
Deprecated, for removal: This API element is subject to removal in a future version.Use the more efficientgetParameterAttachments(List)
instead. That does not need to consider attachments possibly already being part of the designated maps.Fillsattachments
andattachmentLists
with the attachment parameters and the list-valued attachment parameters.- Parameters:
items
-attachments
- The attachments to which to add the ones from the designateditems
. Existing ones which have no corresponding item will be removed and closed.attachmentLists
- The attachment lists to which to add the ones from the designateditems
. Existing ones which have no corresponding item will be removed and closed.
-
getStringValue
protected String getStringValue(Object o)
Returns the string value for the given object, or null if the object is not a representation of a (non-list-valued) string value.- Parameters:
o
-- Returns:
- The string for the given object, or null if not applicable
-
getListValue
protected List<String> getListValue(Object o)
Returns the string list value for the given object, or null if the object is not a representation of a list-valued string value.- Parameters:
o
-- Returns:
- The string list for the given object, or null if not applicable
-
ping
public long ping()
Description copied from interface:ADEPT2Service
Gets whether the service is running and accepts requests or not and since when. This allows, for instance, to check remotely whether this service is available. Additionally, restarts of the service can be detected by comparing the returned start time with the previous one.- Specified by:
ping
in interfaceADEPT2Service
- Returns:
- The start time of the service,
0
for a service that has not been started,-1
for a service that has been shut down.
If you need the oldboolean
logic use0 < ping()
.
-
getRelease
public SerialisablePair<String,String> getRelease()
This service is started outside of the platform and therefore does not support the methods ofADEPT2Service
.- Specified by:
getRelease
in interfaceADEPT2Service
- Returns:
<unknown>
for all elements of the triple.
-
getServiceInstanceName
public SerialisableTriple<String,String,String> getServiceInstanceName()
This service is started outside of the platform and therefore does not support the methods ofADEPT2Service
.- Specified by:
getServiceInstanceName
in interfaceADEPT2Service
- Returns:
null
for the cluster name,<unknown>
for the other elements of the triple.
-
getStartupRequiredServices
public String[] getStartupRequiredServices()
Description copied from interface:ADEPT2Service
Returns a list of service types, which are required for executing the service. The service is allowed for querying theRegistry
for implementations of this type duringADEPT2Service.init(URI[], URI[])
or toADEPT2Service.start()
the service.
It is assured thatADEPT2Service.init(URI[], URI[])
is not called before the required services are started. The order in the array is not relevant since the dependencies of the required services are also inspected and respected.
These services may also be accessed when shutting down the service.- Specified by:
getStartupRequiredServices
in interfaceADEPT2Service
- Returns:
- A list of service types which are required by this service.
-
getRuntimeRequiredServices
public String[] getRuntimeRequiredServices()
Description copied from interface:ADEPT2Service
Returns a list of service types, which are requested when needed at runtime. This has to be after the component is initialised and started and before the shutdown. This means before requesting a runtime required serviceADEPT2Service.init(URI[], URI[])
as well asADEPT2Service.start()
have to be returned. When starting another thread, this has to be synchronised correctly.
Since these services are not necessarily started before this service, they may be shutdown before shutting down this service. This has to be considered when calling a runtime required service. If a service is absolutely necessary when shutting down, it will have to be declared as startup-required.All services required at startup should not be returned again here.
- Specified by:
getRuntimeRequiredServices
in interfaceADEPT2Service
- Returns:
- A list of services which are required during runtime and requested lazily.
-
getLocalUris
public URI[] getLocalUris()
Description copied from interface:ADEPT2Service
Returns the URIs under which the service is locally exported. If this service is only locally available, there will be only one URI and this is a local one. The request for the corresponding component will fail if it is not a local service.
Internal services may return an empty array.- Specified by:
getLocalUris
in interfaceADEPT2Service
- Returns:
- The URIs with which this service is exported locally - this may also be one local URI or an empty array for internal services, that should not be reached at all, for instance communication services.
-
getURIs
public URI[] getURIs()
Description copied from interface:ADEPT2Service
Returns the URIs which are set for this service inADEPT2Service.init(URI[], URI[])
. For a published service these are the global URIs, otherwise the method will return the local URIs.- Specified by:
getURIs
in interfaceADEPT2Service
- Returns:
- The URIs with which this service is globally published or the local URIs.
-
init
public void init(URI[] localExportedUris, URI[] globalExportedUris) throws AbortServiceException
Not forwarded since no client component should control the service. Initialise the service. Startup-required services may already be used here.
After returning formADEPT2Service.init(URI[], URI[])
, the service must be ready forADEPT2Service.start()
.- Specified by:
init
in interfaceADEPT2Service
- Parameters:
localExportedUris
- The URIs with which this service is exported locally or a local URI or an empty array for internal services.globalExportedUris
- The URIs with which this service is published globally ornull
in case the service is not published.- Throws:
AbortServiceException
- If this service cannot be initialised due to a severe problem, anAbortServiceException
will be thrown.ADEPT2Service.shutdown(boolean)
will not be called when aborting; the service has to shut down itself/clean up before throwing the exception.
-
start
public void start()
Not forwarded since no client component should control the service. Starts the service. This method is executed exactly once by the registry and it must return to start further services. For a stand-alone-service own threads or processes have to be started here.
This method is executed exactly once by the registry.After returning from
ADEPT2Service.start()
, the service must be ready to receive any API call. This implicates for instance, that the thread calling this method may not leave the method before a server thread is actually ready to receive requests.- Specified by:
start
in interfaceADEPT2Service
-
preShutdown
public void preShutdown(boolean emergency)
Not forwarded since no client component should control the service. Signals this service that it is about to be shut down. While this method is called, the service is normally available, that is, it can be reached remotely and it should not refuse connections without reason.
This method can be used to perform some cleanup or to start cleaning up and continuing untilADEPT2Service.shutdown(boolean)
. All startup required services are available in pre shutdown, runtime services may already be shut down.
In case of an emergency shutdown, even startup required services may not be available. Additionally, shutting down should be rather fast, so cleanup should concentrate on the really important things. An emergency pre-shutdown usually should not do anything.- Specified by:
preShutdown
in interfaceADEPT2Service
- Parameters:
emergency
- Whether the shutdown will be an emergency shutdown. Normally a service should not do anything in pre-shutdown in case of an emergency.
-
shutdown
public void shutdown(boolean emergency)
Not forwarded since no client component should control the service. Signals this service that it is being shut down. While this method is called, the service is no longer (remotely) available. It should terminate and close all activities and connections. Since the service is in an inconsistent state while shutting down, access should be restricted to the threads relevant for shutting down. All other requests should be blocked (seeServiceThreadHandling
.
All startup required services are available in shutdown, runtime services may already be shut down.
In case of an emergency shutdown, even startup required services may not be available. Additionally, shutting down should be rather fast, so cleanup should concentrate on the really important things and use brief timeouts when waiting.- Specified by:
shutdown
in interfaceADEPT2Service
- Parameters:
emergency
- Whether the shutdown will be an emergency shutdown.
-
getServletName
public String getServletName()
Description copied from interface:DynamicServlet
Gets the name of the servlet. Note that usually the servlet implementations rely on the servlet configuration to provide a name. However, when using aDynamicServlet
, the servlet name has to be provided explicitly.- Specified by:
getServletName
in interfaceDynamicServlet
- Specified by:
getServletName
in interfacejavax.servlet.ServletConfig
- Overrides:
getServletName
in classjavax.servlet.GenericServlet
- Returns:
- The name of the servlet.
-
servletDeployed
public void servletDeployed(javax.servlet.ServletContext context, String urlPattern)
Description copied from interface:DynamicServlet
Notifies the servlet that it has been deployed with the designated context and the designated pattern. Note that the servlet usually will not have been initialised yet.- Specified by:
servletDeployed
in interfaceDynamicServlet
- Parameters:
context
- The servlet context of this servlet.urlPattern
- The URL pattern (mapping) this servlet has been deployed with.
-
servletUndeployed
public void servletUndeployed(javax.servlet.ServletContext context)
Description copied from interface:DynamicServlet
Notifies the servlet that it has been undeployed.- Specified by:
servletUndeployed
in interfaceDynamicServlet
- Parameters:
context
- The servlet context of this servlet.
-
-