public class ServletDeploymentContext extends DeploymentContext
An instance of this class is created by creating using ServletDeploymentContext.Builder
, that allows to configure the deployment
context state, and finally building the context by invoking the ServletDeploymentContext.Builder.build()
method.
This deployment context is compatible with Servlet-based test containers. The following test container factories support the descriptor:
org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory
for testing with the
Grizzly Servlet container.org.glassfish.jersey.test.external.ExternalTestContainerFactory
for testing Java EE Web
applications deployed independently in a separate JVM to that of the tests. For example, the application
may be deployed to the GlassFish or WebLogic application server.Modifier and Type | Class and Description |
---|---|
static class |
ServletDeploymentContext.Builder
The builder for building a Servlet-based deployment context.
|
static class |
ServletDeploymentContext.FilterDescriptor
Helper class to keep configuration information of a single filter.
|
Modifier | Constructor and Description |
---|---|
protected |
ServletDeploymentContext(ServletDeploymentContext.Builder b)
Create new servlet deployment context.
|
Modifier and Type | Method and Description |
---|---|
static ServletDeploymentContext.Builder |
builder(Application application)
Create a new servlet deployment context builder for a JAX-RS / Jersey application instance.
|
static ServletDeploymentContext.Builder |
builder(Class<? extends Application> applicationClass)
Create a new servlet deployment context builder for a JAX-RS / Jersey application instance.
|
static ServletDeploymentContext.Builder |
builder(Map<String,String> initParams)
Create new servlet deployment context builder initialized from the supplied initialization parameters.
|
static ServletDeploymentContext.Builder |
forPackages(String packages)
Create new servlet deployment context builder initialized with the providers from the specified packages.
|
static ServletDeploymentContext.Builder |
forServlet(Class<? extends javax.servlet.http.HttpServlet> servletClass)
Create new servlet deployment context builder bound to a Servlet class.
|
static ServletDeploymentContext.Builder |
forServlet(javax.servlet.http.HttpServlet servlet)
Create new servlet deployment context builder bound to a Servlet instance.
|
Map<String,String> |
getContextParams()
Get the context parameters.
|
List<ServletDeploymentContext.FilterDescriptor> |
getFilters()
Get the filter class.
|
Map<String,String> |
getInitParams()
Get the initialization parameters.
|
List<Class<? extends EventListener>> |
getListeners()
Get all the registered Listener classes
|
Class<? extends javax.servlet.http.HttpServlet> |
getServletClass()
Get the servlet class.
|
javax.servlet.http.HttpServlet |
getServletInstance()
Get the servlet instance.
|
String |
getServletPath()
Get the servlet path.
|
static ServletDeploymentContext |
newInstance(Application application)
Create a new servlet deployment context for a JAX-RS / Jersey application instance.
|
static ServletDeploymentContext |
newInstance(Class<? extends Application> applicationClass)
Create a new servlet deployment context for a JAX-RS / Jersey application instance.
|
static ServletDeploymentContext.Builder |
newInstance(String packages)
Create new servlet deployment context initialized with the providers from the specified packages.
|
getContextPath, getResourceConfig
protected ServletDeploymentContext(ServletDeploymentContext.Builder b)
b
- ServletDeploymentContext.Builder
instance.public static ServletDeploymentContext.Builder builder(Application application)
application
- a JAX-RS / Jersey application to be tested.NullPointerException
- in case the application
is null
.public static ServletDeploymentContext.Builder builder(Class<? extends Application> applicationClass)
applicationClass
- a JAX-RS / Jersey application to be tested.NullPointerException
- in case the applicationClass
is null
.public static ServletDeploymentContext.Builder builder(Map<String,String> initParams)
initParams
- a map of initialization parameters. The parameters will be copied.NullPointerException
- is the specified map is null
.public static ServletDeploymentContext.Builder forServlet(javax.servlet.http.HttpServlet servlet)
Note that the servlet instance will be discarded if one of the ServletDeploymentContext.Builder.servlet(javax.servlet.http.HttpServlet)
,
ServletDeploymentContext.Builder.servletClass(Class)
, ServletDeploymentContext.Builder.filterClass(Class)
or
ServletDeploymentContext.Builder.filterClass(Class, java.util.Set)
is invoked on the builder.
servlet
- the servlet instance to serve the application.NullPointerException
- is the specified map is null
.public static ServletDeploymentContext.Builder forServlet(Class<? extends javax.servlet.http.HttpServlet> servletClass)
Note that the servlet instance will be discarded if one of the ServletDeploymentContext.Builder.servlet(javax.servlet.http.HttpServlet)
,
ServletDeploymentContext.Builder.servletClass(Class)
, ServletDeploymentContext.Builder.filterClass(Class)
or
ServletDeploymentContext.Builder.filterClass(Class, java.util.Set)
is invoked on the builder.
servletClass
- the servlet class to serve the application.NullPointerException
- is the specified map is null
.public static ServletDeploymentContext.Builder forPackages(String packages)
The packages
value will be set as one of the initialization parameters
with "jersey.config.server.provider.packages" key.
packages
- list of application packages containing JAX-RS / Jersey provider and resource classes.NullPointerException
- is the specified map is null
.ServerProperties.PROVIDER_PACKAGES
public static ServletDeploymentContext newInstance(Application application)
The created servlet deployment context will be configured to use default values.
application
- a JAX-RS / Jersey application to be tested.NullPointerException
- in case the application
is null
.public static ServletDeploymentContext newInstance(Class<? extends Application> applicationClass)
The created servlet deployment context will be configured to use default values.
applicationClass
- a JAX-RS / Jersey application to be tested.NullPointerException
- in case the applicationClass
is null
.public static ServletDeploymentContext.Builder newInstance(String packages)
The packages
value will be set as one of the initialization parameters
with "jersey.config.server.provider.packages" key.
packages
- list of application packages containing JAX-RS / Jersey provider and resource classes.NullPointerException
- is the specified map is null
.ServerProperties.PROVIDER_PACKAGES
public Map<String,String> getInitParams()
public Map<String,String> getContextParams()
public Class<? extends javax.servlet.http.HttpServlet> getServletClass()
Note that servlet class and servlet instance
can either be both null
or one of them is specified exclusively (i.e. servlet class and servlet instance cannot be both not null
at the same time).
getServletInstance()
public javax.servlet.http.HttpServlet getServletInstance()
Note that servlet class
and servlet instance can either be both null
or one of them is specified exclusively (i.e. servlet class and servlet instance cannot be both not null
at the same time).
getServletClass()
public List<ServletDeploymentContext.FilterDescriptor> getFilters()
public String getServletPath()
public List<Class<? extends EventListener>> getListeners()
null
if none is registered.Copyright © 2007-2015, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.