I'm having trouble getting google cloud endpoints working with google guice. It appears from the classes available in the endpoints library that this should be possible, but it isn't clear to me how to wire it up, and I see no documentation.
There apparently was a solution, but the API seems to have changed since then.
I tried extending com.google.api.server.spi.guice.SystemServiceModule overriding both configure() and getServiceClasses(), and implementing a GuiceServletContextListener.
The getInjector() method on the GuiceServletContextListeneris invoked, and thus the configure() method on the SystemServiceModule, but the "getServiceClasses() method is never invoked. When services are called, the service class has not had any dependencies injected.
Does anybody know how to wire this up correctly?
Key to use endpoints with guice is to get the servlet mapping right. Try
public class YourGuiceListener extends GuiceServletContextListener {
static class ServletModule extends GuiceSystemServiceServletModule {
@Override
protected void configureServlets() {
super.configureServlets();
Set<Class<?>> serviceClasses = new HashSet<Class<?>>();
serviceClasses.add(YourEndpointsService1.class);
serviceClasses.add(YourEndpointsService2.class);
this.serveGuiceSystemServiceServlet("/_ah/spi/*", serviceClasses);//endpoints servlet mapping
...
}
}
public static class InjectionModule extends AbstractModule {
@Override
protected void configure() {
bind... //optional bindings
}
}
}
add Guice listener and filter to web.xml
<listener><listener-class>package.YourGuiceListener</listener-class></listener>
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>