Provider<HttpSession> not getting injected
Posted
by
user1033715
on Stack Overflow
See other posts from Stack Overflow
or by user1033715
Published on 2012-03-26T14:19:17Z
Indexed on
2012/03/26
17:29 UTC
Read the original article
Hit count: 469
I am using gwt dispatch to communicate and get data from server to client.
In order to get user specific data I want to store the user object in httpsession and access application specific data from servlet context
but when I inject Provider<HttpSession>
when the handler execute is called but the dispatchservlet the provider is null i.e it does not get injected.
following is the code from my action handler
@Inject
Provider<HttpSession> provider;
public ReadEntityHandler() {
}
@Override
public EntityResult execute(ReadEntityAction arg0, ExecutionContext arg1) throws DispatchException {
HttpSession session = null;
if (provider == null)
System.out.println("httpSession is null..");
else {
session = provider.get();
System.out.println("httpSession not null..");
}
System.out.println("reached execution");
return null;
}
and my Dispatch servlet
@Singleton
public class ActionDispatchServlet extends RemoteServiceServlet implements StandardDispatchService {
private Dispatch dispatch;
public ActionDispatchServlet() {
InstanceActionHandlerRegistry registry = new DefaultActionHandlerRegistry();
registry.addHandler(new ReadEntityHandler());
dispatch = new SimpleDispatch(registry);
}
@Override
public Result execute(Action<?> action) throws DispatchException {
try {
return dispatch.execute(action);
}
catch (RuntimeException e) {
log("Exception while executing " + action.getClass().getName() + ": " + e.getMessage(), e);
throw e;
}
}
}
when I try to inject the ReadEntityHandler it throws the following exception
[WARN] failed guiceFilter
com.google.inject.ProvisionException: Guice provision errors:
1) Error injecting constructor, java.lang.NullPointerException
at com.ensarm.wikirealty.server.service.ActionDispatchServlet.<init>(ActionDispatchServlet.java:22)
at com.ensarm.wikirealty.server.service.ActionDispatchServlet.class(ActionDispatchServlet.java:22)
while locating com.ensarm.wikirealty.server.service.ActionDispatchServlet
1 error
at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:834)
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:856)
at com.google.inject.servlet.ServletDefinition.init(ServletDefinition.java:74)
at com.google.inject.servlet.ManagedServletPipeline.init(ManagedServletPipeline.java:84)
at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:106)
at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:168)
at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:593)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:222)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)
at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1068)
at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:811)
at com.google.gwt.dev.DevMode.main(DevMode.java:311)
Caused by: java.lang.NullPointerException
at net.customware.gwt.dispatch.server.DefaultActionHandlerRegistry.addHandler(DefaultActionHandlerRegistry.java:21)
at com.ensarm.wikirealty.server.service.ActionDispatchServlet.<init>(ActionDispatchServlet.java:24)
at com.ensarm.wikirealty.server.service.ActionDispatchServlet$$FastClassByGuice$$e0a28a5d.newInstance(<generated>)
at com.google.inject.internal.cglib.reflect.FastConstructor.newInstance(FastConstructor.java:40)
at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:58)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:84)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:200)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:43)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:878)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.Scopes$1$1.get(Scopes.java:64)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:40)
at com.google.inject.internal.InjectorImpl$4$1.call(InjectorImpl.java:825)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:871)
at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:821)
... 25 more
© Stack Overflow or respective owner