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
-
Constructor Summary
ConstructorDescriptionTomcatServletWebServerFactory
(int port) TomcatServletWebServerFactory
(int port, String contextPath) -
Method Summary
Modifier and TypeMethodDescriptionprotected final File
createTempDir
(String prefix) Creates a temporary directory for Tomcat to use.org.apache.catalina.Context
Returns theContext
object associated with the embedded Tomcat server.Returns the context path for the embedded Tomcat server.Returns a new instance ofTomcatWebServer
configured based on the factory's settings.void
setBaseDirectory
(File baseDirectory) Sets the base directory for the embedded Tomcat server.void
setPort
(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, wait
Methods 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 ofTomcatWebServer
configured based on the factory's settings.- Specified by:
getWebServer
in 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:
getContextPath
in interfaceServletWebServerFactory
- Returns:
- the context path (default is an empty string)
-
getContext
public org.apache.catalina.Context getContext()Returns theContext
object associated with the embedded Tomcat server.- Specified by:
getContext
in interfaceServletWebServerFactory
- Returns:
- the Tomcat
Context
object - 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
File
representing the created temporary directory - Throws:
WebServerException
- if the temporary directory cannot be created
-