public class JerseyGuiceModule
extends com.google.inject.AbstractModule
Provides much of the functionality of the Guice ServletModule (https://github.com/google/guice/wiki/ServletModule). All registrations are forwarded to the appropriate Dropwizard/Jersey/Jetty methods.
heavily copied from Guice Servlet
| Constructor and Description |
|---|
JerseyGuiceModule() |
| Modifier and Type | Method and Description |
|---|---|
protected javax.ws.rs.core.Configurable<?> |
configurable() |
protected void |
configure() |
protected void |
configureServlets()
Servlet Mapping EDSL
|
protected FilterKeyBindingBuilder |
filter(String... urlPatterns) |
javax.servlet.http.HttpServletRequest |
provideHttpServletRequest() |
javax.servlet.http.HttpServletResponse |
provideHttpServletResponse() |
javax.servlet.http.HttpSession |
provideHttpSession() |
Map<String,String[]> |
provideParameterMap() |
javax.ws.rs.container.ContainerRequestContext |
providesContainerRequestContext() |
javax.servlet.ServletContext |
provideServletContext() |
org.glassfish.jersey.server.ExtendedResourceContext |
providesExtendedResourceContext() |
javax.ws.rs.core.HttpHeaders |
providesHttpHeaders() |
org.glassfish.jersey.message.MessageBodyWorkers |
providesMessageBodyWorkers() |
javax.ws.rs.core.Request |
providesRequest() |
javax.ws.rs.container.ResourceContext |
providesResourceContext() |
javax.ws.rs.core.SecurityContext |
providesSecurityContext() |
javax.ws.rs.core.UriInfo |
providesUriInfo() |
protected ServletKeyBindingBuilder |
serve(String... urlPatterns) |
addError, addError, addError, bind, bind, bind, bindConstant, binder, bindInterceptor, bindListener, bindScope, configure, convertToTypes, currentStage, getMembersInjector, getMembersInjector, getProvider, getProvider, install, requestInjection, requestStaticInjection, requireBinding, requireBindingprotected javax.ws.rs.core.Configurable<?> configurable()
protected final FilterKeyBindingBuilder filter(String... urlPatterns)
protected final ServletKeyBindingBuilder serve(String... urlPatterns)
protected final void configure()
configure in class com.google.inject.AbstractModuleprotected void configureServlets()
Part of the EDSL builder language for configuring servlets and filters with guice-servlet. Think of this as an in-code replacement for web.xml. Filters and servlets are configured here using simple java method calls. Here is a typical example of registering a filter when creating your Guice injector:
Guice.createInjector(..., new ServletModule() {
@Override
protected void configureServlets() {
serve("*.html").with(MyServlet.class)
}
}
This registers a servlet (subclass of HttpServlet) called MyServlet to service
any web pages ending in .html. You can also use a path-style syntax to register
servlets:
serve("/my/*").with(MyServlet.class)
Every servlet (or filter) is required to be a singleton. If you cannot annotate the class
directly, you should add a separate bind(..).in(Singleton.class) rule elsewhere in
your module. Mapping a servlet that is bound under any other scope is an error.
<init-param> tag in web.xml. You can similarly pass in parameters to
Servlets and filters registered in Guice-servlet using a Map of parameter
name/value pairs. For example, to initialize MyServlet with two parameters
(name="Dhanji", site="google.com") you could write:
Map<String, String> params = new HashMap<String, String>();
params.put("name", "Dhanji");
params.put("site", "google.com");
...
serve("/*").with(MyServlet.class, params)
...
filter("/*").through(Key.get(Filter.class, Fave.class));
Where Filter.class refers to the Servlet API interface and Fave.class is a
custom binding annotation. Elsewhere (in one of your own modules) you can bind this
filter's implementation:
bind(Filter.class).annotatedWith(Fave.class).to(MyFilterImpl.class);See
Binder for more information on binding syntax.@Provides public javax.servlet.http.HttpServletRequest provideHttpServletRequest()
@Provides public javax.servlet.http.HttpServletResponse provideHttpServletResponse()
@Provides public javax.servlet.ServletContext provideServletContext()
@Provides public javax.servlet.http.HttpSession provideHttpSession()
@Provides public javax.ws.rs.container.ContainerRequestContext providesContainerRequestContext()
@Provides public org.glassfish.jersey.server.ExtendedResourceContext providesExtendedResourceContext()
@Provides public javax.ws.rs.container.ResourceContext providesResourceContext()
@Provides public javax.ws.rs.core.Request providesRequest()
@Provides public javax.ws.rs.core.UriInfo providesUriInfo()
@Provides public javax.ws.rs.core.HttpHeaders providesHttpHeaders()
@Provides public org.glassfish.jersey.message.MessageBodyWorkers providesMessageBodyWorkers()
@Provides public javax.ws.rs.core.SecurityContext providesSecurityContext()
Copyright © 2014–2015 Soabase. All rights reserved.