Package net.officefloor.servlet.tomcat
Class TomcatServletManager
- java.lang.Object
-
- net.officefloor.servlet.tomcat.TomcatServletManager
-
- All Implemented Interfaces:
ServletManager
,ServletServicer
public class TomcatServletManager extends java.lang.Object implements ServletManager, ServletServicer
Tomcat
ServletServicer
.- Author:
- Daniel Sagenschneider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TomcatServletManager.FilterChainHttpServlet
HttpServlet
to handleFilterChain
.static interface
TomcatServletManager.Operation<R,T extends java.lang.Throwable>
Operation to run.static class
TomcatServletManager.SetupApplicationListener
-
Constructor Summary
Constructors Constructor Description TomcatServletManager(java.lang.String contextPath, InjectionRegistry injectionRegistry, OfficeExtensionContext sourceContext, java.lang.String webAppPath)
Instantiate.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description FilterServicer
addFilter(java.lang.String name, java.lang.Class<? extends javax.servlet.Filter> filterClass, java.util.function.Consumer<org.apache.tomcat.util.descriptor.web.FilterDef> decorator)
Adds aFilter
.ServletServicer
addServlet(java.lang.String name, java.lang.Class<? extends javax.servlet.Servlet> servletClass, java.util.function.Consumer<org.apache.catalina.Wrapper> decorator)
Adds aServlet
.ServletServicer
addServlet(java.lang.String name, javax.servlet.Servlet servlet, boolean isInjectDependencies, java.util.function.Consumer<org.apache.catalina.Wrapper> decorator)
Adds aServlet
instance.void
chainInServletManager()
Chains in thisServletManager
to service HTTP requests.AvailableType[]
getAvailableTypes()
Obtains theAvailableType
instances fromOfficeFloor
.org.apache.catalina.Context
getContext()
Obtains theContext
.<T> T
getDependency(java.lang.String qualifier, java.lang.Class<? extends T> type)
Obtains a dependency.OfficeExtensionContext
getSourceContext()
Obtains theOfficeExtensionContext
.boolean
isChainServletManager()
Indicates if chain in theServletManager
.static <R,T extends java.lang.Throwable>
RrunInMavenWarProject(TomcatServletManager.Operation<R,T> operation)
Runs theTomcatServletManager.Operation
assuming within Mavenwar
project.void
service(ServerHttpConnection connection, java.util.concurrent.Executor executor, AsynchronousFlow asynchronousFlow, AsynchronousFlowCompletion asynchronousFlowCompletion, java.util.Map<java.lang.String,? extends java.lang.Object> attributes)
Services theServerHttpConnection
.void
setSupplierSourceContext(SupplierSourceContext supplierSourceContext)
Specifies theSupplierSourceContext
.void
start(AvailableType[] availableTypes)
Starts theServlet
container.void
stop()
Stops theServlet
container.
-
-
-
Constructor Detail
-
TomcatServletManager
public TomcatServletManager(java.lang.String contextPath, InjectionRegistry injectionRegistry, OfficeExtensionContext sourceContext, java.lang.String webAppPath) throws java.io.IOException
Instantiate.- Parameters:
contextPath
- Context path.injectionRegistry
-InjectionRegistry
.sourceContext
-OfficeExtensionContext
.webAppPath
- Path to web application (WAR). May benull
.- Throws:
java.io.IOException
- If fails to setup container.
-
-
Method Detail
-
runInMavenWarProject
public static <R,T extends java.lang.Throwable> R runInMavenWarProject(TomcatServletManager.Operation<R,T> operation) throws T extends java.lang.Throwable
Runs theTomcatServletManager.Operation
assuming within Mavenwar
project.- Type Parameters:
R
- Return type.T
- Possible exception type.- Parameters:
operation
-TomcatServletManager.Operation
.- Returns:
- Result.
- Throws:
T
- Possible failure.T extends java.lang.Throwable
-
setSupplierSourceContext
public void setSupplierSourceContext(SupplierSourceContext supplierSourceContext)
Specifies theSupplierSourceContext
.- Parameters:
supplierSourceContext
-SupplierSourceContext
.
-
isChainServletManager
public boolean isChainServletManager()
Indicates if chain in theServletManager
.- Returns:
true
to chain in theServletManager
.
-
start
public void start(AvailableType[] availableTypes) throws java.lang.Exception
Starts theServlet
container.- Parameters:
availableTypes
-AvailableType
instances.- Throws:
java.lang.Exception
- If fails to start.
-
stop
public void stop() throws java.lang.Exception
Stops theServlet
container.- Throws:
java.lang.Exception
- If fails to stop.
-
service
public void service(ServerHttpConnection connection, java.util.concurrent.Executor executor, AsynchronousFlow asynchronousFlow, AsynchronousFlowCompletion asynchronousFlowCompletion, java.util.Map<java.lang.String,? extends java.lang.Object> attributes) throws java.lang.Exception
Description copied from interface:ServletServicer
Services theServerHttpConnection
.- Specified by:
service
in interfaceServletServicer
- Parameters:
connection
-ServerHttpConnection
.executor
-Executor
.asynchronousFlow
-AsynchronousFlow
to allow forAsyncContext
.asynchronousFlowCompletion
-AsynchronousFlowCompletion
for handling completion of servicing.attributes
- Optional attributes to load to theHttpServletRequest
. May benull
.- Throws:
java.lang.Exception
- If fails to service.
-
getContext
public org.apache.catalina.Context getContext()
Description copied from interface:ServletManager
Obtains theContext
.- Specified by:
getContext
in interfaceServletManager
- Returns:
Context
.
-
addServlet
public ServletServicer addServlet(java.lang.String name, java.lang.Class<? extends javax.servlet.Servlet> servletClass, java.util.function.Consumer<org.apache.catalina.Wrapper> decorator)
Description copied from interface:ServletManager
Adds aServlet
.- Specified by:
addServlet
in interfaceServletManager
- Parameters:
name
- Name ofServlet
.servletClass
-Servlet
Class
.decorator
- Decorates theServlet
. May benull
.- Returns:
ServletServicer
.
-
addServlet
public ServletServicer addServlet(java.lang.String name, javax.servlet.Servlet servlet, boolean isInjectDependencies, java.util.function.Consumer<org.apache.catalina.Wrapper> decorator)
Description copied from interface:ServletManager
Adds aServlet
instance.- Specified by:
addServlet
in interfaceServletManager
- Parameters:
name
- Name ofServlet
.servlet
-Servlet
.isInjectDependencies
- Flags to inject dependencies into theServlet
instance.decorator
- Decorates theServlet
. May benull
.- Returns:
ServletServicer
.
-
addFilter
public FilterServicer addFilter(java.lang.String name, java.lang.Class<? extends javax.servlet.Filter> filterClass, java.util.function.Consumer<org.apache.tomcat.util.descriptor.web.FilterDef> decorator)
Description copied from interface:ServletManager
Adds aFilter
.- Specified by:
addFilter
in interfaceServletManager
- Parameters:
name
- Name ofFilter
.filterClass
-Filter
Class
.decorator
- Decorates theFilter
. May benull
.- Returns:
FilterServicer
.
-
getDependency
public <T> T getDependency(java.lang.String qualifier, java.lang.Class<? extends T> type)
Description copied from interface:ServletManager
Obtains a dependency.
The dependency is via a
SupplierThreadLocal
that is always available in servicing aServlet
/Filter
.- Specified by:
getDependency
in interfaceServletManager
- Type Parameters:
T
- Type of dependency.- Parameters:
qualifier
- Qualifier. May benull
.type
- Type.- Returns:
- Dependency.
-
getAvailableTypes
public AvailableType[] getAvailableTypes()
Description copied from interface:ServletManager
Obtains the
AvailableType
instances fromOfficeFloor
.This should only be invoked during
Servlet
container startup.- Specified by:
getAvailableTypes
in interfaceServletManager
- Returns:
AvailableType
instances fromOfficeFloor
.
-
chainInServletManager
public void chainInServletManager()
Description copied from interface:ServletManager
Chains in thisServletManager
to service HTTP requests. This allows the backingServlet
container to route requests to the appropriateFilter
/Servlet
to service the HTTP request.- Specified by:
chainInServletManager
in interfaceServletManager
-
getSourceContext
public OfficeExtensionContext getSourceContext()
Description copied from interface:ServletManager
Obtains theOfficeExtensionContext
.- Specified by:
getSourceContext
in interfaceServletManager
- Returns:
OfficeExtensionContext
.
-
-