Package com.bobocode.bring.web.server
Class TomcatServletWebServerFactory
java.lang.Object
com.bobocode.bring.web.server.TomcatServletWebServerFactory
- All Implemented Interfaces:
ServletWebServerFactory
ServletWebServerFactory implementation for Apache Tomcat. This factory
creates and configures an embedded Tomcat web server instance.
The factory allows customization of the server's port, context path, base directory,
and other Tomcat-specific settings. It implements the ServletWebServerFactory
interface, providing a getWebServer method to create and return a
TomcatWebServer.
- Since:
- 1.0
- Author:
- Blyzhnytsia Team
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTomcatServletWebServerFactory(int port) TomcatServletWebServerFactory(int port, String contextPath) -
Method Summary
Modifier and TypeMethodDescriptionprotected final FilecreateTempDir(String prefix) Creates a temporary directory for Tomcat to use.org.apache.catalina.ContextReturns theContextobject associated with the embedded Tomcat server.Returns the context path for the embedded Tomcat server.Returns a new instance ofTomcatWebServerconfigured based on the factory's settings.voidsetBaseDirectory(File baseDirectory) Sets the base directory for the embedded Tomcat server.voidsetPort(int port) Sets the port number for the embedded Tomcat server.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.bobocode.bring.web.server.ServletWebServerFactory
setTomcatAppLifecycleListener
-
Field Details
-
port
private int port -
contextPath
-
baseDirectory
-
context
private org.apache.catalina.Context context -
tomcatAppLifecycleListener
private org.apache.catalina.LifecycleListener tomcatAppLifecycleListener
-
-
Constructor Details
-
TomcatServletWebServerFactory
public TomcatServletWebServerFactory() -
TomcatServletWebServerFactory
public TomcatServletWebServerFactory(int port) -
TomcatServletWebServerFactory
-
-
Method Details
-
getWebServer
Returns a new instance ofTomcatWebServerconfigured based on the factory's settings.- Specified by:
getWebServerin interfaceServletWebServerFactory- Returns:
- a configured instance of
TomcatWebServer - See Also:
-
setBaseDirectory
Sets the base directory for the embedded Tomcat server.- Parameters:
baseDirectory- the base directory for the server to use
-
setPort
public void setPort(int port) Sets the port number for the embedded Tomcat server.- Parameters:
port- the port number for the server to use
-
getContextPath
Returns the context path for the embedded Tomcat server.- Specified by:
getContextPathin interfaceServletWebServerFactory- Returns:
- the context path (default is an empty string)
-
getContext
public org.apache.catalina.Context getContext()Returns theContextobject associated with the embedded Tomcat server.- Specified by:
getContextin interfaceServletWebServerFactory- Returns:
- the Tomcat
Contextobject - See Also:
-
createTempDir
Creates a temporary directory for Tomcat to use.- Parameters:
prefix- a prefix to be used in the name of the directory- Returns:
- a
Filerepresenting the created temporary directory - Throws:
WebServerException- if the temporary directory cannot be created
-