Class ServletDeploymentContext
- java.lang.Object
-
- org.glassfish.jersey.test.DeploymentContext
-
- org.glassfish.jersey.test.ServletDeploymentContext
-
public class ServletDeploymentContext extends DeploymentContext
A Servlet-based deployment context.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 theServletDeploymentContext.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.
- Since:
- 2.8
- Author:
- Paul Sandoz, Marek Potociar
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 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.
-
Constructor Summary
Constructors Modifier Constructor Description protected
ServletDeploymentContext(ServletDeploymentContext.Builder b)
Create new servlet deployment context.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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(jakarta.servlet.http.HttpServlet servlet)
Create new servlet deployment context builder bound to a Servlet instance.static ServletDeploymentContext.Builder
forServlet(Class<? extends jakarta.servlet.http.HttpServlet> servletClass)
Create new servlet deployment context builder bound to a Servlet class.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 classesClass<? extends jakarta.servlet.http.HttpServlet>
getServletClass()
Get the servlet class.jakarta.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.-
Methods inherited from class org.glassfish.jersey.test.DeploymentContext
getContextPath, getResourceConfig, getSslContext, getSslParameters
-
-
-
-
Constructor Detail
-
ServletDeploymentContext
protected ServletDeploymentContext(ServletDeploymentContext.Builder b)
Create new servlet deployment context.- Parameters:
b
-ServletDeploymentContext.Builder
instance.
-
-
Method Detail
-
builder
public static ServletDeploymentContext.Builder builder(Application application)
Create a new servlet deployment context builder for a JAX-RS / Jersey application instance.- Parameters:
application
- a JAX-RS / Jersey application to be tested.- Returns:
- new servlet deployment context builder instance associated with the JAX-RS / Jersey application to be tested.
- Throws:
NullPointerException
- in case theapplication
isnull
.
-
builder
public static ServletDeploymentContext.Builder builder(Class<? extends Application> applicationClass)
Create a new servlet deployment context builder for a JAX-RS / Jersey application instance.- Parameters:
applicationClass
- a JAX-RS / Jersey application to be tested.- Returns:
- new servlet deployment context builder instance associated with the JAX-RS / Jersey application to be tested.
- Throws:
NullPointerException
- in case theapplicationClass
isnull
.
-
builder
public static ServletDeploymentContext.Builder builder(Map<String,String> initParams)
Create new servlet deployment context builder initialized from the supplied initialization parameters.- Parameters:
initParams
- a map of initialization parameters. The parameters will be copied.- Returns:
- new servlet deployment context builder instance initialized from the supplied initialization parameters.
- Throws:
NullPointerException
- is the specified map isnull
.
-
forServlet
public static ServletDeploymentContext.Builder forServlet(jakarta.servlet.http.HttpServlet servlet)
Create new servlet deployment context builder bound to a Servlet instance.Note that the servlet instance will be discarded if one of the
ServletDeploymentContext.Builder.servlet(jakarta.servlet.http.HttpServlet)
,ServletDeploymentContext.Builder.servletClass(Class)
,ServletDeploymentContext.Builder.filterClass(Class)
orServletDeploymentContext.Builder.filterClass(Class, java.util.Set)
is invoked on the builder.- Parameters:
servlet
- the servlet instance to serve the application.- Returns:
- new servlet deployment context builder instance bound to a Servlet instance.
- Throws:
NullPointerException
- is the specified map isnull
.
-
forServlet
public static ServletDeploymentContext.Builder forServlet(Class<? extends jakarta.servlet.http.HttpServlet> servletClass)
Create new servlet deployment context builder bound to a Servlet class.Note that the servlet instance will be discarded if one of the
ServletDeploymentContext.Builder.servlet(jakarta.servlet.http.HttpServlet)
,ServletDeploymentContext.Builder.servletClass(Class)
,ServletDeploymentContext.Builder.filterClass(Class)
orServletDeploymentContext.Builder.filterClass(Class, java.util.Set)
is invoked on the builder.- Parameters:
servletClass
- the servlet class to serve the application.- Returns:
- new servlet deployment context builder instance bound to a Servlet instance.
- Throws:
NullPointerException
- is the specified map isnull
.
-
forPackages
public static ServletDeploymentContext.Builder forPackages(String packages)
Create new servlet deployment context builder initialized with the providers from the specified packages.The
packages
value will be set as one of theinitialization parameters
with "jersey.config.server.provider.packages" key.- Parameters:
packages
- list of application packages containing JAX-RS / Jersey provider and resource classes.- Returns:
- new servlet deployment context builder instance initialized with the providers from the specified packages.
- Throws:
NullPointerException
- is the specified map isnull
.- See Also:
ServerProperties.PROVIDER_PACKAGES
-
newInstance
public static ServletDeploymentContext newInstance(Application application)
Create a new servlet deployment context for a JAX-RS / Jersey application instance.The created servlet deployment context will be configured to use default values.
- Parameters:
application
- a JAX-RS / Jersey application to be tested.- Returns:
- new servlet deployment context instance associated with the JAX-RS / Jersey application to be tested.
- Throws:
NullPointerException
- in case theapplication
isnull
.
-
newInstance
public static ServletDeploymentContext newInstance(Class<? extends Application> applicationClass)
Create a new servlet deployment context for a JAX-RS / Jersey application instance.The created servlet deployment context will be configured to use default values.
- Parameters:
applicationClass
- a JAX-RS / Jersey application to be tested.- Returns:
- new servlet deployment context instance associated with the JAX-RS / Jersey application to be tested.
- Throws:
NullPointerException
- in case theapplicationClass
isnull
.
-
newInstance
public static ServletDeploymentContext.Builder newInstance(String packages)
Create new servlet deployment context initialized with the providers from the specified packages.The
packages
value will be set as one of theinitialization parameters
with "jersey.config.server.provider.packages" key.- Parameters:
packages
- list of application packages containing JAX-RS / Jersey provider and resource classes.- Returns:
- new servlet deployment context instance initialized with the providers from the specified packages.
- Throws:
NullPointerException
- is the specified map isnull
.- See Also:
ServerProperties.PROVIDER_PACKAGES
-
getInitParams
public Map<String,String> getInitParams()
Get the initialization parameters.- Returns:
- the initialization parameters.
-
getContextParams
public Map<String,String> getContextParams()
Get the context parameters.- Returns:
- the context parameters.
-
getServletClass
public Class<? extends jakarta.servlet.http.HttpServlet> getServletClass()
Get the servlet class.Note that servlet class and
servlet instance
can either be bothnull
or one of them is specified exclusively (i.e. servlet class and servlet instance cannot be both notnull
at the same time).- Returns:
- the servlet class.
- See Also:
getServletInstance()
-
getServletInstance
public jakarta.servlet.http.HttpServlet getServletInstance()
Get the servlet instance.Note that
servlet class
and servlet instance can either be bothnull
or one of them is specified exclusively (i.e. servlet class and servlet instance cannot be both notnull
at the same time).- Returns:
- the servlet instance.
- See Also:
getServletClass()
-
getFilters
public List<ServletDeploymentContext.FilterDescriptor> getFilters()
Get the filter class.- Returns:
- the filter classes.
-
getServletPath
public String getServletPath()
Get the servlet path.- Returns:
- the servlet path.
-
getListeners
public List<Class<? extends EventListener>> getListeners()
Get all the registered Listener classes- Returns:
- the registered listener classes, or
null
if none is registered.
-
-