Package net.officefloor.servlet.tomcat
Class TomcatServletManager
java.lang.Object
net.officefloor.servlet.tomcat.TomcatServletManager
- All Implemented Interfaces:
ServletManager,ServletServicer
Tomcat ServletServicer.- Author:
- Daniel Sagenschneider
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classHttpServletto handleFilterChain.static interfaceTomcatServletManager.Operation<R,T extends Throwable> Operation to run.static classServletContextListenerfor application setup. -
Constructor Summary
ConstructorsConstructorDescriptionTomcatServletManager(String contextPath, InjectionRegistry injectionRegistry, OfficeExtensionContext sourceContext, String webAppPath) Instantiate. -
Method Summary
Modifier and TypeMethodDescriptionaddFilter(String name, Class<? extends jakarta.servlet.Filter> filterClass, Consumer<org.apache.tomcat.util.descriptor.web.FilterDef> decorator) Adds aFilter.addServlet(String name, jakarta.servlet.Servlet servlet, boolean isInjectDependencies, Consumer<org.apache.catalina.Wrapper> decorator) Adds aServletinstance.addServlet(String name, Class<? extends jakarta.servlet.Servlet> servletClass, Consumer<org.apache.catalina.Wrapper> decorator) Adds aServlet.voidChains in thisServletManagerto service HTTP requests.Obtains theAvailableTypeinstances fromOfficeFloor.org.apache.catalina.ContextObtains theContext.<T> TgetDependency(String qualifier, Class<? extends T> type) Obtains a dependency.Obtains theOfficeExtensionContext.booleanIndicates if chain in theServletManager.static <R,T extends Throwable>
RrunInMavenWarProject(TomcatServletManager.Operation<R, T> operation) Runs theTomcatServletManager.Operationassuming within Mavenwarproject.voidservice(ServerHttpConnection connection, Executor executor, AsynchronousFlow asynchronousFlow, AsynchronousFlowCompletion asynchronousFlowCompletion, Map<String, ? extends Object> attributes) Services theServerHttpConnection.voidsetSupplierSourceContext(SupplierSourceContext supplierSourceContext) Specifies theSupplierSourceContext.voidstart(AvailableType[] availableTypes) Starts theServletcontainer.voidstop()Stops theServletcontainer.
-
Constructor Details
-
TomcatServletManager
public TomcatServletManager(String contextPath, InjectionRegistry injectionRegistry, OfficeExtensionContext sourceContext, String webAppPath) throws IOException Instantiate.- Parameters:
contextPath- Context path.injectionRegistry-InjectionRegistry.sourceContext-OfficeExtensionContext.webAppPath- Path to web application (WAR). May benull.- Throws:
IOException- If fails to setup container.
-
-
Method Details
-
runInMavenWarProject
public static <R,T extends Throwable> R runInMavenWarProject(TomcatServletManager.Operation<R, T> operation) throws TRuns theTomcatServletManager.Operationassuming within Mavenwarproject.- Type Parameters:
R- Return type.T- Possible exception type.- Parameters:
operation-TomcatServletManager.Operation.- Returns:
- Result.
- Throws:
T- Possible failure.
-
setSupplierSourceContext
Specifies theSupplierSourceContext.- Parameters:
supplierSourceContext-SupplierSourceContext.
-
isChainServletManager
public boolean isChainServletManager()Indicates if chain in theServletManager.- Returns:
trueto chain in theServletManager.
-
start
Starts theServletcontainer.- Parameters:
availableTypes-AvailableTypeinstances.- Throws:
Exception- If fails to start.
-
stop
Stops theServletcontainer.- Throws:
Exception- If fails to stop.
-
service
public void service(ServerHttpConnection connection, Executor executor, AsynchronousFlow asynchronousFlow, AsynchronousFlowCompletion asynchronousFlowCompletion, Map<String, ? extends Object> attributes) throws ExceptionDescription copied from interface:ServletServicerServices theServerHttpConnection.- Specified by:
servicein interfaceServletServicer- Parameters:
connection-ServerHttpConnection.executor-Executor.asynchronousFlow-AsynchronousFlowto allow forAsyncContext.asynchronousFlowCompletion-AsynchronousFlowCompletionfor handling completion of servicing.attributes- Optional attributes to load to theHttpServletRequest. May benull.- Throws:
Exception- If fails to service.
-
getContext
public org.apache.catalina.Context getContext()Description copied from interface:ServletManagerObtains theContext.- Specified by:
getContextin interfaceServletManager- Returns:
Context.
-
addServlet
public ServletServicer addServlet(String name, Class<? extends jakarta.servlet.Servlet> servletClass, Consumer<org.apache.catalina.Wrapper> decorator) Description copied from interface:ServletManagerAdds aServlet.- Specified by:
addServletin interfaceServletManager- Parameters:
name- Name ofServlet.servletClass-ServletClass.decorator- Decorates theServlet. May benull.- Returns:
ServletServicer.
-
addServlet
public ServletServicer addServlet(String name, jakarta.servlet.Servlet servlet, boolean isInjectDependencies, Consumer<org.apache.catalina.Wrapper> decorator) Description copied from interface:ServletManagerAdds aServletinstance.- Specified by:
addServletin interfaceServletManager- Parameters:
name- Name ofServlet.servlet-Servlet.isInjectDependencies- Flags to inject dependencies into theServletinstance.decorator- Decorates theServlet. May benull.- Returns:
ServletServicer.
-
addFilter
public FilterServicer addFilter(String name, Class<? extends jakarta.servlet.Filter> filterClass, Consumer<org.apache.tomcat.util.descriptor.web.FilterDef> decorator) Description copied from interface:ServletManagerAdds aFilter.- Specified by:
addFilterin interfaceServletManager- Parameters:
name- Name ofFilter.filterClass-FilterClass.decorator- Decorates theFilter. May benull.- Returns:
FilterServicer.
-
getDependency
Description copied from interface:ServletManagerObtains a dependency.
The dependency is via a
SupplierThreadLocalthat is always available in servicing aServlet/Filter.- Specified by:
getDependencyin interfaceServletManager- Type Parameters:
T- Type of dependency.- Parameters:
qualifier- Qualifier. May benull.type- Type.- Returns:
- Dependency.
-
getAvailableTypes
Description copied from interface:ServletManagerObtains the
AvailableTypeinstances fromOfficeFloor.This should only be invoked during
Servletcontainer startup.- Specified by:
getAvailableTypesin interfaceServletManager- Returns:
AvailableTypeinstances fromOfficeFloor.
-
chainInServletManager
public void chainInServletManager()Description copied from interface:ServletManagerChains in thisServletManagerto service HTTP requests. This allows the backingServletcontainer to route requests to the appropriateFilter/Servletto service the HTTP request.- Specified by:
chainInServletManagerin interfaceServletManager
-
getSourceContext
Description copied from interface:ServletManagerObtains theOfficeExtensionContext.- Specified by:
getSourceContextin interfaceServletManager- Returns:
OfficeExtensionContext.
-