Getting Null Pointer on Servlet trying to get zone !
Getting Null Pointer on Servlet trying to get zone !
Hello I am getting null pointer when trying to get the zone from a servlet.
I wonder what I am doing wrong please help!
Does both the extension and servlet code need be in same package ?
I currently have both the servlet and extension code as seperate projects.
Also I have noted that :
for(Zone z: sfs.getZoneManager().getZoneList()){
System.out.println(z.getName());
}
this gives out no result . So it appears inside servlet sfs instance is unable to get any of the zones that are initialized.
Re: Getting Null Pointer on Servlet trying to get zone !
Hi,
did you investigate which object is null in the call?
Also is the servlet being run after the sever has completed the boot process? If not that might be the problem.
Thanks
did you investigate which object is null in the call?
Also is the servlet being run after the sever has completed the boot process? If not that might be the problem.
Thanks
Re: Getting Null Pointer on Servlet trying to get zone !
Lapo wrote:Hi,
did you investigate which object is null in the call?
Also is the servlet being run after the sever has completed the boot process? If not that might be the problem.
Thanks
Hi ,
The null is because I was trying to get the zone by name and then its extension .
The code is unable to pull any zones as its zone list has no results.
Yes I am running servlet url well after the smartfoxserver has started.
Do they both need to be in same packages and code?
Re: Getting Null Pointer on Servlet trying to get zone !
Can you show me the complete code executed in the servlet?
Thanks
Thanks
Re: Getting Null Pointer on Servlet trying to get zone !
Lapo wrote:Can you show me the complete code executed in the servlet?
Thanks
Code: Select all
package sfs2x.extensions.games.aqua.http;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.smartfoxserver.v2.SmartFoxServer;
import com.smartfoxserver.v2.entities.Zone;
import com.smartfoxserver.v2.extensions.ISFSExtension;
@SuppressWarnings("serial")
public class ExtensionHTTPFacade extends HttpServlet
{
private final static String CMD_NUMBERS = "numbers";
private SmartFoxServer sfs;
private ISFSExtension myExtension;
@Override
public void init() throws ServletException
{
System.out.print("Inside Init");
sfs = SmartFoxServer.getInstance();
System.out.print("Got SFS");
for(Zone z: sfs.getZoneManager().getZoneList()){
System.out.println(z.getName());
}
System.out.println("After loop");
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
// Object result = null;
Object result ="Please pass a list of comma separated values called 'numbers'. Example ?numbers=1,2,3,4";
resp.getWriter().write(result.toString());
}
}
Here it is! Please see.
I am getting the last output message
but I can see in logs on Smartfoxserver that no Zone is getting pulled.
Re: Getting Null Pointer on Servlet trying to get zone !
The problem is running the code in the init() method I think, which is invoked very early when Jetty is starting up.
I'd suggest to move the code in the init() method to the doGet/doPost methods and you should be fine.
Cheers
I'd suggest to move the code in the init() method to the doGet/doPost methods and you should be fine.
Cheers
Re: Getting Null Pointer on Servlet trying to get zone !
Lapo wrote:The problem is running the code in the init() method I think, which is invoked very early when Jetty is starting up.
I'd suggest to move the code in the init() method to the doGet/doPost methods and you should be fine.
Cheers
No I have done that it is still same. Earlier also init only ran when I hit the url first time not before.
Even now it is same issue not pulling up any zones.
Re: Getting Null Pointer on Servlet trying to get zone !
Zenith wrote:Lapo wrote:The problem is running the code in the init() method I think, which is invoked very early when Jetty is starting up.
I'd suggest to move the code in the init() method to the doGet/doPost methods and you should be fine.
Cheers
No I have done that it is still same. Earlier also init only ran when I hit the url first time not before.
Even now it is same issue not pulling up any zones.
Mean while can you suggest if there is some alternative to achieve to somehow make some rest api which can talk to SFS Zones or Rooms EXTENSION codes. I would be very thankful.
Re: Getting Null Pointer on Servlet trying to get zone !
Zenith wrote:Lapo wrote:The problem is running the code in the init() method I think, which is invoked very early when Jetty is starting up.
I'd suggest to move the code in the init() method to the doGet/doPost methods and you should be fine.
Cheers
No I have done that it is still same. Earlier also init only ran when I hit the url first time not before.
Even now it is same issue not pulling up any zones.
I can't reproduce your issue.
I can access all the zones just fine in a doGet() method call.
I think it's a problem with your deployment. If you can't figure it out you can send us a .war file that reproduces the issue, via our support@... email box.
Thanks
Re: Getting Null Pointer on Servlet trying to get zone !
Lapo wrote:Zenith wrote:Lapo wrote:The problem is running the code in the init() method I think, which is invoked very early when Jetty is starting up.
I'd suggest to move the code in the init() method to the doGet/doPost methods and you should be fine.
Cheers
No I have done that it is still same. Earlier also init only ran when I hit the url first time not before.
Even now it is same issue not pulling up any zones.
I can't reproduce your issue.
I can access all the zones just fine in a doGet() method call.
I think it's a problem with your deployment. If you can't figure it out you can send us a .war file that reproduces the issue, via our support@... email box.
Thanks
Ok man found it! This was because my deployment war had the same libraries which were also in my SFS already. This was causing class loading collisions I would guess. Once I removed those libraries from my Web deployment it is working fine.
Thanks for the help.
Re: Getting Null Pointer on Servlet trying to get zone !
Good point, didn't think of that... but yes, definitely you don't need to include the compilation dependencies in your final .war file.
Cheers
Cheers
Who is online
Users browsing this forum: No registered users and 45 guests