public class ExampleJerseyGuiceModule extends JerseyGuiceModule
| Constructor and Description |
|---|
ExampleJerseyGuiceModule() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
configureServlets()
Servlet Mapping EDSL
|
configurable, provideHttpServletRequest, provideHttpServletResponse, provideHttpSession, provideParameterMap, providesContainerRequestContext, provideServletContext, providesExtendedResourceContext, providesHttpHeaders, providesMessageBodyWorkers, providesRequest, providesResourceContext, providesSecurityContext, providesUriInfoconfigure, filter, serveaddError, addError, addError, bind, bind, bind, bindConstant, binder, bindInterceptor, bindListener, bindListener, bindScope, configure, convertToTypes, currentStage, getMembersInjector, getMembersInjector, getProvider, getProvider, install, requestInjection, requestStaticInjection, requireBinding, requireBindingprotected void configureServlets()
JerseyMultiGuiceModulePart 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.configureServlets in class JerseyMultiGuiceModuleCopyright © 2014–2016 Soabase. All rights reserved.