Getting servletcontext in a RemoteServiceServlet

82 views
Skip to first unread message

Steven De Groote

unread,
May 30, 2008, 9:27:23 AM5/30/08
to Google Web Toolkit
Hi all,

I'm pretty new to GWT and I'm trying to perform an rather simple RPC
call.
The call works, as in debugging it enters the constructor of my
Service implementation:

public class BehaviourServiceImpl extends RemoteServiceServlet
implements BehaviourService {
private IMWSProxy mwsProxy;
private static final Log log =
LogFactory.getLog( BehaviourServiceImpl.class );

public BehaviourServiceImpl() {
super();
mwsProxy =
(IMWSProxy)this.getServletContext().getAttribute("mwsProxy");
}

The problem is however that getServletContext() throws a nullpointer
exception (I noticed while performing "inspect" in debug mode. Here's
what I get:

java.lang.NullPointerException
at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:
159)
at
be.sofico.web.pm.server.BehaviourServiceImpl.<init>(BehaviourServiceImpl.java:
29)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)

So, what I want to do is get an object from the application, as I will
need that one to retrieve my data later on.
Are there better ways to do that or can anyone help me solve this
issue please?

Thank you,
Steven

Steven De Groote

unread,
May 30, 2008, 9:40:11 AM5/30/08
to Google Web Toolkit
Ah well, nevermind, put it in the init() and that works fine.
Can't believe I missed that one :/
Reply all
Reply to author
Forward
0 new messages