org.apache.oozie.test
Class EmbeddedServletContainer

java.lang.Object
  extended by org.apache.oozie.test.EmbeddedServletContainer

public class EmbeddedServletContainer
extends Object

An embedded servlet container for testing purposes.

It provides reduced functionality, it supports only Servlets.

The servlet container is started in a free port.


Constructor Summary
EmbeddedServletContainer(String contextPath)
          Create a servlet container.
 
Method Summary
 void addFilter(String filterPath, Class filterClass)
          Add a filter to the container.
 void addServletEndpoint(String servletPath, Class servletClass)
          Add a servlet to the container.
 void addServletEndpoint(String servletPath, Class servletClass, Map<String,String> initParams)
          Add a servlet to the container.
 String getContextURL()
          Return the full URL (including protocol, host, port, context path, servlet path) for the context path.
 String getHost()
          Return the hostname the servlet container is bound to.
 int getPort()
          Return the port number the servlet container is bound to.
 String getServletURL(String servletPath)
          Return the full URL (including protocol, host, port, context path, servlet path) for a servlet path.
 void start()
          Start the servlet container.
 void stop()
          Stop the servlet container.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EmbeddedServletContainer

public EmbeddedServletContainer(String contextPath)
Create a servlet container.

Parameters:
contextPath - context path for the servlet, it must not be prefixed or append with "/", for the default context use ""
Method Detail

addServletEndpoint

public void addServletEndpoint(String servletPath,
                               Class servletClass,
                               Map<String,String> initParams)
Add a servlet to the container.

Parameters:
servletPath - servlet path for the servlet, it should be prefixed with '/", it may contain a wild card at the end.
servletClass - servlet class
initParams - a mapping of init parameters for the servlet, or null

addServletEndpoint

public void addServletEndpoint(String servletPath,
                               Class servletClass)
Add a servlet to the container.

Parameters:
servletPath - servlet path for the servlet, it should be prefixed with '/", it may contain a wild card at the end.
servletClass - servlet class

addFilter

public void addFilter(String filterPath,
                      Class filterClass)
Add a filter to the container.

Parameters:
filterPath - path for the filter, it should be prefixed with '/", it may contain a wild card at the end.
filterClass - servlet class

start

public void start()
           throws Exception
Start the servlet container.

The container starts on a free port.

Throws:
Exception - thrown if the container could not start.

getHost

public String getHost()
Return the hostname the servlet container is bound to.

Returns:
the hostname.

getPort

public int getPort()
Return the port number the servlet container is bound to.

Returns:
the port number.

getContextURL

public String getContextURL()
Return the full URL (including protocol, host, port, context path, servlet path) for the context path.

Returns:
URL to the context path.

getServletURL

public String getServletURL(String servletPath)
Return the full URL (including protocol, host, port, context path, servlet path) for a servlet path.

Parameters:
servletPath - the path which will be expanded to a full URL.
Returns:
URL to the servlet.

stop

public void stop()
Stop the servlet container.



Copyright © 2013 Apache Software Foundation. All Rights Reserved.