/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

  1. package org.gbif.clb.guice;
  2. import org.gbif.clb.AutoCompleteService;
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import com.google.inject.Guice;
  6. import com.google.inject.Injector;
  7. import com.google.inject.Scopes;
  8. import com.google.inject.name.Names;
  9. import com.google.inject.servlet.GuiceServletContextListener;
  10. import com.sun.jersey.api.core.PackagesResourceConfig;
  11. import com.sun.jersey.api.json.JSONConfiguration;
  12. import com.sun.jersey.guice.JerseyServletModule;
  13. import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
  14. public class JerseyListener extends GuiceServletContextListener {
  15. @Override
  16. protected Injector getInjector() {
  17. return Guice.createInjector(new JerseyTestModule());
  18. }
  19. private static class JerseyTestModule extends JerseyServletModule {
  20. @Override
  21. protected void configureServlets() {
  22. bind(String.class).annotatedWith(Names.named("solrServerUrl")).toInstance("http://jawa.gbif.org:8080/solr/");
  23. bind(AutoCompleteService.class).in(Scopes.SINGLETON);
  24. Map<String, String> params = new HashMap<String, String>(2);
  25. // Configure automatic JSON output for Jersey
  26. params.put(JSONConfiguration.FEATURE_POJO_MAPPING, "true");
  27. // Let Jersey look for root resources and Providers automatically
  28. params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "org.gbif.clb.resource");
  29. serve("/*").with(GuiceContainer.class, params);
  30. }
  31. }
  32. }