org.springframework.boot.context.embedded
Class AbstractEmbeddedServletContainerFactory

java.lang.Object
  extended by org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory
All Implemented Interfaces:
ConfigurableEmbeddedServletContainerFactory, EmbeddedServletContainerFactory
Direct Known Subclasses:
JettyEmbeddedServletContainerFactory, TomcatEmbeddedServletContainerFactory

public abstract class AbstractEmbeddedServletContainerFactory
extends Object
implements ConfigurableEmbeddedServletContainerFactory

Abstract base class for EmbeddedServletContainerFactory implementations.

Author:
Phillip Webb, Dave Syer

Field Summary
protected  org.apache.commons.logging.Log logger
           
 
Constructor Summary
AbstractEmbeddedServletContainerFactory()
          Create a new AbstractEmbeddedServletContainerFactory instance.
AbstractEmbeddedServletContainerFactory(int port)
          Create a new AbstractEmbeddedServletContainerFactory instance with the specified port.
AbstractEmbeddedServletContainerFactory(String contextPath, int port)
          Create a new AbstractEmbeddedServletContainerFactory instance with the specified context path and port.
 
Method Summary
 void addErrorPages(ErrorPage... errorPages)
          Adds error pages that will be used when handling exceptions.
 void addInitializers(ServletContextInitializer... initializers)
          Add ServletContextInitializers to those that should be applied in addition to EmbeddedServletContainerFactory.getEmbeddedServletContainer(ServletContextInitializer...) parameters.
 InetAddress getAddress()
           
 String getContextPath()
          Returns the context path for the embedded servlet container.
 File getDocumentRoot()
          Returns the document root which will be used by the web context to serve static files.
 Set<ErrorPage> getErrorPages()
          Returns a mutable set of ErrorPages that will be used when handling exceptions.
 List<ServletContextInitializer> getInitializers()
          Returns a mutable list of ServletContextInitializer that should be applied in addition to EmbeddedServletContainerFactory.getEmbeddedServletContainer(ServletContextInitializer...) parameters.
protected  String getJspServletClassName()
           
 MimeMappings getMimeMappings()
          Returns the mime-type mappings.
 int getPort()
          Returns the port that the embedded servlet container should listen on.
 int getSessionTimeout()
           
protected  File getValidDocumentRoot()
          Returns the absolute document root when it points to a valid folder, logging a warning and returning null otherwise.
 boolean isRegisterDefaultServlet()
          Flag to indicate that the default servlet should be registered.
 boolean isRegisterJspServlet()
          Flag to indicate that the JSP servlet should be registered if available on the classpath.
protected  ServletContextInitializer[] mergeInitializers(ServletContextInitializer... initializers)
          Utility method that can be used by subclasses wishing to combine the specified ServletContextInitializer parameters with those defined in this instance.
 void setAddress(InetAddress address)
          Sets the specific network address that the server should bind to.
 void setContextPath(String contextPath)
          Sets the context path for the embedded servlet container.
 void setDocumentRoot(File documentRoot)
          Sets the document root folder which will be used by the web context to serve static files.
 void setErrorPages(Set<ErrorPage> errorPages)
          Sets the error pages that will be used when handling exceptions.
 void setInitializers(List<? extends ServletContextInitializer> initializers)
          Sets ServletContextInitializer that should be applied in addition to EmbeddedServletContainerFactory.getEmbeddedServletContainer(ServletContextInitializer...) parameters.
 void setJspServletClassName(String jspServletClassName)
          The class name for the jsp servlet if used.
 void setMimeMappings(MimeMappings mimeMappings)
          Sets the mime-type mappings.
 void setPort(int port)
          Sets the port that the embedded servlet container should listen on.
 void setRegisterDefaultServlet(boolean registerDefaultServlet)
          Set if the DefaultServlet should be registered.
 void setRegisterJspServlet(boolean registerJspServlet)
          Set if the JspServlet should be registered if it is on the classpath.
 void setSessionTimeout(int sessionTimeout)
          The session timeout in seconds (default 30).
 void setSessionTimeout(int sessionTimeout, TimeUnit timeUnit)
          The session timeout in the specified TimeUnit (default 30 seconds).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.boot.context.embedded.EmbeddedServletContainerFactory
getEmbeddedServletContainer
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Constructor Detail

AbstractEmbeddedServletContainerFactory

public AbstractEmbeddedServletContainerFactory()
Create a new AbstractEmbeddedServletContainerFactory instance.


AbstractEmbeddedServletContainerFactory

public AbstractEmbeddedServletContainerFactory(int port)
Create a new AbstractEmbeddedServletContainerFactory instance with the specified port.

Parameters:
port - the port number for the embedded servlet container

AbstractEmbeddedServletContainerFactory

public AbstractEmbeddedServletContainerFactory(String contextPath,
                                               int port)
Create a new AbstractEmbeddedServletContainerFactory instance with the specified context path and port.

Parameters:
contextPath - the context path for the embedded servlet container
port - the port number for the embedded servlet container
Method Detail

setContextPath

public void setContextPath(String contextPath)
Description copied from interface: ConfigurableEmbeddedServletContainerFactory
Sets the context path for the embedded servlet container. The context should start with a "/" character but not end with a "/" character. The default context path can be specified using an empty string.

Specified by:
setContextPath in interface ConfigurableEmbeddedServletContainerFactory
Parameters:
contextPath - the contextPath to set

getContextPath

public String getContextPath()
Returns the context path for the embedded servlet container. The path will start with "/" and not end with "/". The root context is represented by an empty string.


setPort

public void setPort(int port)
Description copied from interface: ConfigurableEmbeddedServletContainerFactory
Sets the port that the embedded servlet container should listen on. If not specified port '8080' will be used. Use port 0 to switch off the server completely.

Specified by:
setPort in interface ConfigurableEmbeddedServletContainerFactory
Parameters:
port - the port to set

getPort

public int getPort()
Returns the port that the embedded servlet container should listen on.

Specified by:
getPort in interface ConfigurableEmbeddedServletContainerFactory
Returns:
the port

setAddress

public void setAddress(InetAddress address)
Description copied from interface: ConfigurableEmbeddedServletContainerFactory
Sets the specific network address that the server should bind to.

Specified by:
setAddress in interface ConfigurableEmbeddedServletContainerFactory
Parameters:
address - the address to set (defaults to null)

getAddress

public InetAddress getAddress()
Returns:
the address the embedded container binds to

setSessionTimeout

public void setSessionTimeout(int sessionTimeout)
Description copied from interface: ConfigurableEmbeddedServletContainerFactory
The session timeout in seconds (default 30). If 0 or negative then sessions never expire.

Specified by:
setSessionTimeout in interface ConfigurableEmbeddedServletContainerFactory
Parameters:
sessionTimeout - the session timeout

setSessionTimeout

public void setSessionTimeout(int sessionTimeout,
                              TimeUnit timeUnit)
Description copied from interface: ConfigurableEmbeddedServletContainerFactory
The session timeout in the specified TimeUnit (default 30 seconds). If 0 or negative then sessions never expire.

Specified by:
setSessionTimeout in interface ConfigurableEmbeddedServletContainerFactory
Parameters:
sessionTimeout - the session timeout
timeUnit - the time unit

getSessionTimeout

public int getSessionTimeout()
Returns:
the session timeout in minutes

setInitializers

public void setInitializers(List<? extends ServletContextInitializer> initializers)
Description copied from interface: ConfigurableEmbeddedServletContainerFactory
Sets ServletContextInitializer that should be applied in addition to EmbeddedServletContainerFactory.getEmbeddedServletContainer(ServletContextInitializer...) parameters. This method will replace any previously set or added initializers.

Specified by:
setInitializers in interface ConfigurableEmbeddedServletContainerFactory
Parameters:
initializers - the initializers to set
See Also:
ConfigurableEmbeddedServletContainerFactory.addInitializers(org.springframework.boot.context.embedded.ServletContextInitializer...)

addInitializers

public void addInitializers(ServletContextInitializer... initializers)
Description copied from interface: ConfigurableEmbeddedServletContainerFactory
Add ServletContextInitializers to those that should be applied in addition to EmbeddedServletContainerFactory.getEmbeddedServletContainer(ServletContextInitializer...) parameters.

Specified by:
addInitializers in interface ConfigurableEmbeddedServletContainerFactory
Parameters:
initializers - the initializers to add
See Also:
ConfigurableEmbeddedServletContainerFactory.setInitializers(java.util.List)

getInitializers

public List<ServletContextInitializer> getInitializers()
Returns a mutable list of ServletContextInitializer that should be applied in addition to EmbeddedServletContainerFactory.getEmbeddedServletContainer(ServletContextInitializer...) parameters.

Returns:
the initializers

setDocumentRoot

public void setDocumentRoot(File documentRoot)
Description copied from interface: ConfigurableEmbeddedServletContainerFactory
Sets the document root folder which will be used by the web context to serve static files.

Specified by:
setDocumentRoot in interface ConfigurableEmbeddedServletContainerFactory
Parameters:
documentRoot - the document root or null if not required

getDocumentRoot

public File getDocumentRoot()
Returns the document root which will be used by the web context to serve static files.


setErrorPages

public void setErrorPages(Set<ErrorPage> errorPages)
Description copied from interface: ConfigurableEmbeddedServletContainerFactory
Sets the error pages that will be used when handling exceptions.

Specified by:
setErrorPages in interface ConfigurableEmbeddedServletContainerFactory
Parameters:
errorPages - the error pages

addErrorPages

public void addErrorPages(ErrorPage... errorPages)
Description copied from interface: ConfigurableEmbeddedServletContainerFactory
Adds error pages that will be used when handling exceptions.

Specified by:
addErrorPages in interface ConfigurableEmbeddedServletContainerFactory
Parameters:
errorPages - the error pages

getErrorPages

public Set<ErrorPage> getErrorPages()
Returns a mutable set of ErrorPages that will be used when handling exceptions.


setMimeMappings

public void setMimeMappings(MimeMappings mimeMappings)
Description copied from interface: ConfigurableEmbeddedServletContainerFactory
Sets the mime-type mappings.

Specified by:
setMimeMappings in interface ConfigurableEmbeddedServletContainerFactory
Parameters:
mimeMappings - the mime type mappings (defaults to MimeMappings.DEFAULT)

getMimeMappings

public MimeMappings getMimeMappings()
Returns the mime-type mappings.

Returns:
the mimeMappings the mime-type mappings.

setRegisterDefaultServlet

public void setRegisterDefaultServlet(boolean registerDefaultServlet)
Description copied from interface: ConfigurableEmbeddedServletContainerFactory
Set if the DefaultServlet should be registered. Defaults to true so that files from the document root will be served.

Specified by:
setRegisterDefaultServlet in interface ConfigurableEmbeddedServletContainerFactory
Parameters:
registerDefaultServlet - if the default servlet should be registered

isRegisterJspServlet

public boolean isRegisterJspServlet()
Flag to indicate that the JSP servlet should be registered if available on the classpath.

Returns:
true if the JSP servlet is to be registered

setRegisterJspServlet

public void setRegisterJspServlet(boolean registerJspServlet)
Description copied from interface: ConfigurableEmbeddedServletContainerFactory
Set if the JspServlet should be registered if it is on the classpath. Defaults to true so that files from the document root will be served.

Specified by:
setRegisterJspServlet in interface ConfigurableEmbeddedServletContainerFactory
Parameters:
registerJspServlet - if the JSP servlet should be registered

isRegisterDefaultServlet

public boolean isRegisterDefaultServlet()
Flag to indicate that the default servlet should be registered.

Returns:
true if the default servlet is to be registered

setJspServletClassName

public void setJspServletClassName(String jspServletClassName)
Description copied from interface: ConfigurableEmbeddedServletContainerFactory
The class name for the jsp servlet if used. If registerJspServlet is true and this class is on the classpath then it will be registered. Since both Tomcat and Jetty use Jasper for their JSP implementation the default is org.apache.jasper.servlet.JspServlet.

Specified by:
setJspServletClassName in interface ConfigurableEmbeddedServletContainerFactory
Parameters:
jspServletClassName - the class name for the JSP servlet if used

getJspServletClassName

protected String getJspServletClassName()
Returns:
the JSP servlet class name

mergeInitializers

protected final ServletContextInitializer[] mergeInitializers(ServletContextInitializer... initializers)
Utility method that can be used by subclasses wishing to combine the specified ServletContextInitializer parameters with those defined in this instance.

Parameters:
initializers - the initializers to merge
Returns:
a complete set of merged initializers (with the specified parameters appearing first)

getValidDocumentRoot

protected final File getValidDocumentRoot()
Returns the absolute document root when it points to a valid folder, logging a warning and returning null otherwise.



Copyright © 2013. All Rights Reserved.