Class EmbeddedServletService
- java.lang.Object
-
- de.aristaflow.adept2.base.service.AbstractADEPT2Service
-
- de.aristaflow.adept2.base.servletcontainer.dynamic.EmbeddedServletService
-
- All Implemented Interfaces:
ADEPT2Service
,LogService
,ServiceThreadHandling
,ServletService
@ConfigurationDescription(properties=, validator=ConfigurationValidator.class) public class EmbeddedServletService extends AbstractADEPT2Service implements ServletService
A servlet service deploying servlets dynamically via Servlet API 3.0. Note that all servlets have the same servlet context. The servlets need to be deployed before the servlet context has been fully initialised. Note that no undeploying may take place since this is not supported by the Servlet API 3.0.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EmbeddedServletService.ConfigurationValidator
Validates the configuration of the embedded servlet service, that is, an instance ofServletContext
needs to be provided and the URL of the outer servlet.-
Nested classes/interfaces inherited from class de.aristaflow.adept2.base.service.AbstractADEPT2Service
AbstractADEPT2Service.ActiveSessions
-
-
Field Summary
Fields Modifier and Type Field Description protected URL
baseUrl
The base URL of the servlet, that is the protocol, the host, the port and usually the servlet name or the name of the corresponding deployment file.static String
CONF_SERVLET_CONTEXT
The configuration key with which to store a servlet context in the configuration.static String
CONF_SERVLET_URL
The configuration key with which to store the URL of the servlet.protected javax.servlet.ServletContext
sc
The context of the outer servlet.protected ConcurrentMap<Pair<String,String>,Pair<DynamicServlet,javax.servlet.ServletContext>>
servlets
All servlets deployed via this service.-
Fields inherited from class de.aristaflow.adept2.base.service.AbstractADEPT2Service
CONF_CSV_LOGGING, configuration, logger, registry, runtimeRequiredServices, startupRequiredServices
-
-
Constructor Summary
Constructors Modifier Constructor Description EmbeddedServletService(org.apache.commons.configuration2.Configuration conf, Registry registry)
Creates a new embedded servlet service using Servlet API 3.0 for deploying servlets.protected
EmbeddedServletService(org.apache.commons.configuration2.Configuration conf, Registry registry, Class<?> cls)
Creates a new embedded servlet service using Servlet API 3.0 for deploying servlets.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description URL
deployWebApp(String hierarchicalContext, DynamicServlet servlet, Map<String,Object> contextAttrs)
Deploys the designated servlet via this service with the designated hierarchical context having the designated servlet context attributes.URL
deployWebApp(String hierarchicalContext, Class<?> baseClass, DynamicServlet servlet, Map<String,String> initParams, Map<String,Object> contextAttrs, String urlMapping)
Deploys the designated servlet via this service with the designated hierarchical context having the designated servlet context attributes.URL
deployWebApp(String hierarchicalContext, Class<?> baseClass, DynamicServlet servlet, Map<String,String> initParams, Map<String,Object> contextAttrs, String urlMapping, boolean asyncSupported)
Deploys the designated servlet via this service with the designated hierarchical context having the designated servlet context attributes.URL
getBaseURL()
Gets the base URL (without any context information) of the underlying servlet container.javax.servlet.ServletContext
getServletContext(Class<?> baseClass)
Gets the servlet context this servlet service runs in.void
undeployWebApp(String hierarchicalContext, String servletName)
Undeploys the designated servlet deployed with the designated hierarchical context and servlet name.-
Methods inherited from class de.aristaflow.adept2.base.service.AbstractADEPT2Service
_sessionActive, _sessionFinished, activeOrInvalidServiceStateException, changeLogContext, changeLogContext, changeLogContext, consoleLog, csvLoggingEnabled, getClassSpecificJulLogger, getDependencyRegistry, getLocalUris, getLogger, getRelease, getRuntimeRequiredServices, getServiceInstanceName, getStartupRequiredServices, getURIs, getUserCredentials, init, isActive, isSessionActive, isShutdown, logMethodEntry, logMethodEntry, logMethodEntry, logMethodExit, logMethodExit, ping, preShutdown, privilegeSession, privilegeThread, revertLogContextChanges, sessionActive, sessionActive, sessionActive, sessionActive, sessionFinished, sessionFinished, shutdown, signalShutdown, signalStart, start, unprivilegeThread
-
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.service.ADEPT2Service
getLocalUris, getRelease, getRuntimeRequiredServices, getServiceInstanceName, getStartupRequiredServices, getURIs, init, ping, preShutdown, shutdown, start
-
-
-
-
Field Detail
-
CONF_SERVLET_CONTEXT
public static final String CONF_SERVLET_CONTEXT
The configuration key with which to store a servlet context in the configuration.- See Also:
- Constant Field Values
-
CONF_SERVLET_URL
public static final String CONF_SERVLET_URL
The configuration key with which to store the URL of the servlet.- See Also:
- Constant Field Values
-
servlets
protected final ConcurrentMap<Pair<String,String>,Pair<DynamicServlet,javax.servlet.ServletContext>> servlets
All servlets deployed via this service.
-
sc
protected final javax.servlet.ServletContext sc
The context of the outer servlet.
-
baseUrl
protected final URL baseUrl
The base URL of the servlet, that is the protocol, the host, the port and usually the servlet name or the name of the corresponding deployment file.
-
-
Constructor Detail
-
EmbeddedServletService
public EmbeddedServletService(org.apache.commons.configuration2.Configuration conf, Registry registry) throws ConfigurationException
Creates a new embedded servlet service using Servlet API 3.0 for deploying servlets.- Parameters:
conf
- The configuration of this service.registry
- The registry to be used for accessing services by this service. This is provided as parameter to the constructor when creating a service.- Throws:
ConfigurationException
- If there are problems parsing the servlet URL, aConfigurationException
will be thrown.
-
EmbeddedServletService
protected EmbeddedServletService(org.apache.commons.configuration2.Configuration conf, Registry registry, Class<?> cls) throws ConfigurationException
Creates a new embedded servlet service using Servlet API 3.0 for deploying servlets. This constructor is for usage by subclasses.- Parameters:
conf
- The configuration of this service.registry
- The registry to be used for accessing services by this service. This is provided as parameter to the constructor when creating a service.cls
- The class specifying the name of the logger of this service.- Throws:
ConfigurationException
- If there are problems parsing the servlet URL, aConfigurationException
will be thrown.
-
-
Method Detail
-
getBaseURL
public URL getBaseURL()
Description copied from interface:ServletService
Gets the base URL (without any context information) of the underlying servlet container. This URL (or rather this URL with the corresponding servlet contexts) has to be reachable via browser.- Specified by:
getBaseURL
in interfaceServletService
- Returns:
- The base URL (without any context information) of the underlying servlet container.
-
getServletContext
public javax.servlet.ServletContext getServletContext(Class<?> baseClass)
Gets the servlet context this servlet service runs in. This should respect the designated base class, that is, it should resolve the resource paths appropriately.- Parameters:
baseClass
- The class with which to load resources. This allows to have aWEB-INF
-directory which is not at the top-level. It is expected to be besides this class. If this isnull
, the usual behaviour applies which is a top-levelWEB-INF
-directory.- Returns:
- The servlet context this servlet service runs in.
-
deployWebApp
public URL deployWebApp(String hierarchicalContext, DynamicServlet servlet, Map<String,Object> contextAttrs) throws ServletDeploymentException
Description copied from interface:ServletService
Deploys the designated servlet via this service with the designated hierarchical context having the designated servlet context attributes. Usually the base URL appended by the hierarchical context will be the actual URL of the servlet.
This will use "/" as URL pattern.Note that in case of an embedded servlet service, that is this service running within a servlet context, deploying service has to take place before the surrounding servlet context has been initialised.
- Specified by:
deployWebApp
in interfaceServletService
- Parameters:
hierarchicalContext
- The hierarchical context of the servlet. This corresponds to the file or directory name when deploying in the file system (no trailing "/").servlet
- The servlet which to deploy dynamically. Make sure that the servlet name is set appropriately since this is required for undeploying.contextAttrs
- The attributes added to the servlet context when deploying the servlet. Make sure that the keys are unique! In case of an embedded servlet service, all servlets will have the very same context. This may benull
.- Returns:
- The URL of the designated servlet, that is the base URL of the servlet container appended by the name of the web application. This URL does not contain a URL pattern specified in the servlet mapping except for the default pattern ("/").
- Throws:
ServletDeploymentException
- If there are problems deploying the designated servlet, aServletDeploymentException
having no cause will be thrown, otherwise the causing exception will be wrapped (mostly problems with URL-encoding or servlet container configuration.
-
deployWebApp
public URL deployWebApp(String hierarchicalContext, Class<?> baseClass, DynamicServlet servlet, Map<String,String> initParams, Map<String,Object> contextAttrs, String urlMapping) throws ServletDeploymentException
Description copied from interface:ServletService
Deploys the designated servlet via this service with the designated hierarchical context having the designated servlet context attributes. Usually the base URL appended by the hierarchical context will be the actual URL of the servlet.
This will use "/" as URL pattern.Note that in case of an embedded servlet service, that is this service running within a servlet context, deploying service has to take place before the surrounding servlet context has been initialised.
Implementations providing
ServletService.deployWebApp(String, Class, DynamicServlet, Map, Map, String, boolean)
should provide an implementation of this method forwarding toServletService.deployWebApp(String, Class, DynamicServlet, Map, Map, String, boolean)
with no asynchronous support (false
as value for the last parameter).- Specified by:
deployWebApp
in interfaceServletService
- Parameters:
hierarchicalContext
- The hierarchical context of the servlet. This corresponds to the file or directory name when deploying in the file system (no trailing "/").baseClass
- The class with which to load resources. This allows to have aWEB-INF
-directory which is not at the top-level. It is expected to be besides this class. If this isnull
, the usual behaviour applies which is a top-levelWEB-INF
-directory.servlet
- The servlet which to deploy dynamically. Make sure that the servlet name is set appropriately since this is required for undeploying.initParams
- The init parameters of the servlet. This may benull
.contextAttrs
- The attributes added to the servlet context when deploying the servlet. Make sure that the keys are unique! In case of an embedded servlet service, all servlets will have the very same context. This may benull
.urlMapping
- The mapping for the designated servlet. This corresponds to URL-pattern in the deployment descriptor. If this isnull
, the default mapping "/" will be used.- Returns:
- The URL of the designated servlet, that is the base URL of the servlet container appended by the name of the web application. This URL does not contain a URL pattern specified in the servlet mapping except for the default pattern ("/").
- Throws:
ServletDeploymentException
- If there are problems deploying the designated servlet, aServletDeploymentException
having no cause will be thrown, otherwise the causing exception will be wrapped (mostly problems with URL-encoding or servlet container configuration.
-
deployWebApp
public URL deployWebApp(String hierarchicalContext, Class<?> baseClass, DynamicServlet servlet, Map<String,String> initParams, Map<String,Object> contextAttrs, String urlMapping, boolean asyncSupported) throws ServletDeploymentException
Description copied from interface:ServletService
Deploys the designated servlet via this service with the designated hierarchical context having the designated servlet context attributes. Usually the base URL appended by the hierarchical context will be the actual URL of the servlet.
This will use "/" as URL pattern.Note that in case of an embedded servlet service, that is this service running within a servlet context, deploying service has to take place before the surrounding servlet context has been initialised.
- Specified by:
deployWebApp
in interfaceServletService
- Parameters:
hierarchicalContext
- The hierarchical context of the servlet. This corresponds to the file or directory name when deploying in the file system (no trailing "/").baseClass
- The class with which to load resources. This allows to have aWEB-INF
-directory which is not at the top-level. It is expected to be besides this class. If this isnull
, the usual behaviour applies which is a top-levelWEB-INF
-directory.servlet
- The servlet which to deploy dynamically. Make sure that the servlet name is set appropriately since this is required for undeploying.initParams
- The init parameters of the servlet. This may benull
.contextAttrs
- The attributes added to the servlet context when deploying the servlet. Make sure that the keys are unique! In case of an embedded servlet service, all servlets will have the very same context. This may benull
.urlMapping
- The mapping for the designated servlet. This corresponds to URL-pattern in the deployment descriptor. If this isnull
, the default mapping "/" will be used.asyncSupported
- Whether the designated servlet supports asynchronous operation.- Returns:
- The URL of the designated servlet, that is the base URL of the servlet container appended by the name of the web application. This URL does not contain a URL pattern specified in the servlet mapping except for the default pattern ("/").
- Throws:
ServletDeploymentException
- If there are problems deploying the designated servlet, aServletDeploymentException
having no cause will be thrown, otherwise the causing exception will be wrapped (mostly problems with URL-encoding or servlet container configuration.- See Also:
Registration.Dynamic.setAsyncSupported(boolean)
-
undeployWebApp
public void undeployWebApp(String hierarchicalContext, String servletName) throws ServletDeploymentException
Description copied from interface:ServletService
Undeploys the designated servlet deployed with the designated hierarchical context and servlet name. Note that undeploying may not work, for instance in case of an embedded servlet service.- Specified by:
undeployWebApp
in interfaceServletService
- Parameters:
hierarchicalContext
- The hierarchical context with which the servlet has been deployed.servletName
- The name of the servlet which to undeploy.- Throws:
ServletDeploymentException
- If there are problems undeploying the designated web application, aServletDeploymentException
will be thrown. If this is due to undeploying a non existing web application, it will have no cause, problems when stopping the servlet will have the appropriate cause.
-
-