Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropwizard Application doesn't start when used with Guice #43

Closed
ganeshs opened this issue Apr 24, 2018 · 8 comments
Closed

Dropwizard Application doesn't start when used with Guice #43

ganeshs opened this issue Apr 24, 2018 · 8 comments

Comments

@ganeshs
Copy link

ganeshs commented Apr 24, 2018

Throws the following exception on startup. The ServletJaxRsContextFactoryProvider has a request scoped injection thats causing this.

javax.servlet.ServletException: io.dropwizard.jersey.setup.JerseyServletContainer-5aab5b31@8b30bcb6==io.dropwizard.jersey.setup.JerseyServletContainer,jsp=null,order=1,inst=false
	at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:658)
	at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:421)
	at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:760)
	at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:348)
	at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:785)
	at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:261)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
	at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
	at com.codahale.metrics.jetty9.InstrumentedHandler.doStart(InstrumentedHandler.java:103)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113)
	at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
	at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
	at org.eclipse.jetty.server.handler.gzip.GzipHandler.doStart(GzipHandler.java:273)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
	at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
	at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
	at org.eclipse.jetty.server.handler.StatisticsHandler.doStart(StatisticsHandler.java:252)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
	at org.eclipse.jetty.server.Server.start(Server.java:449)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
	at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
	at org.eclipse.jetty.server.Server.doStart(Server.java:416)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
	at io.dropwizard.cli.ServerCommand.run(ServerCommand.java:53)
	at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:44)
	at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:85)
	at io.dropwizard.cli.Cli.run(Cli.java:75)
	at io.dropwizard.Application.run(Application.java:93)
Caused by: A MultiException has 1 exceptions.  They are:
1. com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access scoped [javax.servlet.http.HttpServletRequest]. Either we are not currently inside an HTTP Servlet request, or you may have forgotten to apply com.google.inject.servlet.GuiceFilter as a servlet filter for this request.
  at com.google.inject.servlet.InternalServletModule.provideHttpServletRequest(InternalServletModule.java:106) (via modules: com.google.inject.servlet.ServletModule -> com.google.inject.servlet.InternalServletModule)
  while locating javax.servlet.http.HttpServletRequest

1 error

	at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:494)
	at com.squarespace.jersey2.guice.GuiceScopeContext.findOrCreate(GuiceScopeContext.java:36)
	at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2022)
	at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:114)
	at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:88)
	at org.glassfish.jersey.internal.inject.ContextInjectionResolver.resolve(ContextInjectionResolver.java:126)
	at org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:943)
	at org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:993)
	at org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:983)
	at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:617)
	at org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:184)
	at org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:350)
	at org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:347)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
	at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:255)
	at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:347)
	at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:392)
	at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:177)
	at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:369)
	at javax.servlet.GenericServlet.init(GenericServlet.java:244)
	at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:637)
	... 41 more
Caused by: com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access scoped [javax.servlet.http.HttpServletRequest]. Either we are not currently inside an HTTP Servlet request, or you may have forgotten to apply com.google.inject.servlet.GuiceFilter as a servlet filter for this request.
  at com.google.inject.servlet.InternalServletModule.provideHttpServletRequest(InternalServletModule.java:106) (via modules: com.google.inject.servlet.ServletModule -> com.google.inject.servlet.InternalServletModule)
  while locating javax.servlet.http.HttpServletRequest

1 error
	at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1028)
	at com.squarespace.jersey2.guice.GuiceBindingDescriptor.create(GuiceBindingDescriptor.java:66)
	at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:479)
	... 62 more
Caused by: com.google.inject.OutOfScopeException: Cannot access scoped [javax.servlet.http.HttpServletRequest]. Either we are not currently inside an HTTP Servlet request, or you may have forgotten to apply com.google.inject.servlet.GuiceFilter as a servlet filter for this request.
	at com.google.inject.servlet.GuiceFilter.getContext(GuiceFilter.java:165)
	at com.google.inject.servlet.GuiceFilter.getOriginalRequest(GuiceFilter.java:147)
	at com.google.inject.servlet.ServletScopes$1$1.get(ServletScopes.java:107)
	at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
	at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.java:1019)
	at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1085)
	at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1015)
	... 64 more
@ganeshs ganeshs changed the title Application wont startup Dropwizard Application doesn't start when used with Guice Apr 24, 2018
@victornoel
Copy link
Member

@ganeshs could you include extra informations such as how guice is setup too? I have never used guice so it would be helpful.

Actually, the best would be some kind of test case such as in the dropwizard-pac4j tests but with guice instead of hk2… :)

@ganeshs ganeshs closed this as completed Apr 24, 2018
@ganeshs ganeshs reopened this Apr 24, 2018
@ganeshs
Copy link
Author

ganeshs commented Apr 24, 2018

In my scenario, guice was setup using the bundle https://github.com/gojek-engineering/gojek-commons/blob/master/gojek-commons-guice/src/main/java/com/gojek/guice/GuiceBundle.java

I will try to put up a test case for guice integration. I have already come up with a fix for this issue in the pac4j jax-rs module. Will raise a PR for that in a while

@ganeshs
Copy link
Author

ganeshs commented Apr 24, 2018

@victornoel Raised a PR for this in the jaxrs module. pac4j/jax-rs-pac4j#42

@victornoel
Copy link
Member

@ganeshs once the latest SNAPSHOT of jax-rs-pac4j is built, could you validate everything works as you expect it?
It would also be excellent if you could make a small test using guice in dropwizard-pac4j :)

@victornoel
Copy link
Member

@ganeshs did you get some time to confirm everything is ok? you should be able to use dropwizard-pac4j 3.0.0-SNAPSHOT for your tests :)
I also backported your PR to 2.x btw.

@ganeshs
Copy link
Author

ganeshs commented May 19, 2018 via email

@victornoel
Copy link
Member

victornoel commented Jun 16, 2018

@ganeshs have you had the time to validate everything is ok? We are going to release dropwizard-pac4j 3.0.0 soon btw (see pac4j/jax-rs-pac4j#44)

@victornoel
Copy link
Member

I'm closing this, please open a new issue if this is still a problem :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants