Getting Null Pointer on Servlet trying to get zone !

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

User avatar
Zenith
Posts: 55
Joined: 09 Oct 2017, 09:57

Getting Null Pointer on Servlet trying to get zone !

Postby Zenith » 24 Apr 2019, 13:38

NullIssue.PNG
(6.43 KiB) Not downloaded yet


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.
SfsIssue2.PNG
(50.23 KiB) Not downloaded yet
User avatar
Lapo
Site Admin
Posts: 23024
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Getting Null Pointer on Servlet trying to get zone !

Postby Lapo » 24 Apr 2019, 16:24

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
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Zenith
Posts: 55
Joined: 09 Oct 2017, 09:57

Re: Getting Null Pointer on Servlet trying to get zone !

Postby Zenith » 24 Apr 2019, 16:26

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?
User avatar
Lapo
Site Admin
Posts: 23024
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Getting Null Pointer on Servlet trying to get zone !

Postby Lapo » 24 Apr 2019, 16:28

Can you show me the complete code executed in the servlet?
Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Zenith
Posts: 55
Joined: 09 Oct 2017, 09:57

Re: Getting Null Pointer on Servlet trying to get zone !

Postby Zenith » 24 Apr 2019, 16:29

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
nullissue3.PNG
(6.11 KiB) Not downloaded yet



but I can see in logs on Smartfoxserver that no Zone is getting pulled.
nullissue4.PNG
(7.81 KiB) Not downloaded yet
User avatar
Lapo
Site Admin
Posts: 23024
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Getting Null Pointer on Servlet trying to get zone !

Postby Lapo » 24 Apr 2019, 16:35

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
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Zenith
Posts: 55
Joined: 09 Oct 2017, 09:57

Re: Getting Null Pointer on Servlet trying to get zone !

Postby Zenith » 24 Apr 2019, 16:38

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.
User avatar
Zenith
Posts: 55
Joined: 09 Oct 2017, 09:57

Re: Getting Null Pointer on Servlet trying to get zone !

Postby Zenith » 24 Apr 2019, 16:46

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.
User avatar
Lapo
Site Admin
Posts: 23024
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Getting Null Pointer on Servlet trying to get zone !

Postby Lapo » 24 Apr 2019, 17:56

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
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Zenith
Posts: 55
Joined: 09 Oct 2017, 09:57

Re: Getting Null Pointer on Servlet trying to get zone !

Postby Zenith » 25 Apr 2019, 06:54

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.
User avatar
Lapo
Site Admin
Posts: 23024
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Getting Null Pointer on Servlet trying to get zone !

Postby Lapo » 25 Apr 2019, 07:00

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
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 46 guests