Created
March 4, 2014 22:28
-
-
Save davetrux/9357113 to your computer and use it in GitHub Desktop.
Configuration class for instantiation of Jersey Services with Guice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.demo.test.rest; | |
import com.google.inject.Guice; | |
import com.google.inject.Injector; | |
import com.google.inject.servlet.GuiceServletContextListener; | |
import com.demo.DemoRestService; | |
import com.demo.BasicAuthFilter; | |
import com.sun.jersey.guice.JerseyServletModule; | |
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer; | |
import java.util.HashMap; | |
import java.util.Map; | |
public class GuiceServletConfig extends GuiceServletContextListener { | |
@Override | |
protected Injector getInjector() { | |
return Guice.createInjector(new JerseyServletModule() { | |
@Override | |
protected void configureServlets() { | |
bind(DataSource.class).to(HsqlDataSource.class); | |
Map<String, String> filterParams = new HashMap<>(); | |
filterParams.put("OpenUrls", "/noauth"); | |
filter("/api/*").through(BasicAuthFilter.class, filterParams); | |
Map<String, String> initParams = new HashMap<>(); | |
initParams.put("com.sun.jersey.api.json.POJOMappingFeature", "true"); | |
bind(DemoRestService.class); | |
serve("/api/*").with(GuiceContainer.class, initParams); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment