/checklistbank-autocomplete/src/main/java/org/gbif/clb/guice/JerseyListener.java
http://gbif-ecat.googlecode.com/ · Java · 42 lines · 30 code · 10 blank · 2 comment · 0 complexity · 62df25ee64db183a2867f9c9d890adad MD5 · raw file
- package org.gbif.clb.guice;
- import org.gbif.clb.AutoCompleteService;
- import java.util.HashMap;
- import java.util.Map;
- import com.google.inject.Guice;
- import com.google.inject.Injector;
- import com.google.inject.Scopes;
- import com.google.inject.name.Names;
- import com.google.inject.servlet.GuiceServletContextListener;
- import com.sun.jersey.api.core.PackagesResourceConfig;
- import com.sun.jersey.api.json.JSONConfiguration;
- import com.sun.jersey.guice.JerseyServletModule;
- import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
- public class JerseyListener extends GuiceServletContextListener {
- @Override
- protected Injector getInjector() {
- return Guice.createInjector(new JerseyTestModule());
- }
- private static class JerseyTestModule extends JerseyServletModule {
- @Override
- protected void configureServlets() {
- bind(String.class).annotatedWith(Names.named("solrServerUrl")).toInstance("http://jawa.gbif.org:8080/solr/");
- bind(AutoCompleteService.class).in(Scopes.SINGLETON);
- Map<String, String> params = new HashMap<String, String>(2);
- // Configure automatic JSON output for Jersey
- params.put(JSONConfiguration.FEATURE_POJO_MAPPING, "true");
- // Let Jersey look for root resources and Providers automatically
- params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "org.gbif.clb.resource");
- serve("/*").with(GuiceContainer.class, params);
- }
- }
- }