Hopefully my last issue... RequestHandler

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

Moderators: Lapo, Bax

Post Reply
Onion
Posts: 10
Joined: 26 Jan 2011, 05:29

Hopefully my last issue... RequestHandler

Post by Onion »

I am looking over the RPG character example and was trying to do an addRequestHandler. In flash I have it send over the proper parameters when the player logs in correctly. Problem is I receive a NULL pointer error due to the

Code: Select all


sfs.send(new ExtensionRequest("getModel", new SFSObject()));

I am apparently sending a Null object so it is not allowing the request handler to proceed. This is from the example for the RPGcharacter as mentioned before.

What is going wrong exactly? I am trying to get data from the server and the server won't let me through this send request. I placed traces in the server extension code and noticed the Request handler did not get used at all so I know it isn't server side.

Please help.
smilefr
Posts: 58
Joined: 23 Mar 2009, 16:50
Location: France

Post by smilefr »

Try this way:

Code: Select all

var params:ISFSObject = new SFSObject();
		sfs.send(new ExtensionRequest("getModel", params));
tchen
Posts: 191
Joined: 11 Dec 2010, 14:14

Post by tchen »

If you're getting a nullexception in that snippet, then chances are good your variable sfs is not pointing at anything. Make sure its referencing the SmartFoxServer object you used to connect with.
Onion
Posts: 10
Joined: 26 Jan 2011, 05:29

Post by Onion »

Thanks for your help again but neither of those two fixed the issue.

My sfs is working fine and I even did an ip check and a connected check before I send the extension request. Both came back as connected and with the propery ip. Also changing to the params instead of what I had did not do the trick either. Same issue.

What is strange is the login request works fine where I even put in a username and password which checks the database and does work. Then inside of the onLogin function I send my extensionrequest. What I receive everytime I do this is the following response:

Edit:

Also I found this error before the error below:
ERROR [com.smartfoxserver.v2.controllers.ExtensionController-1]Controllers.ExtensionController -

End Edit

Exception: java.lang.NULLPointerException
Message: ******NULL******
Description: Error while handling client request in extension: ....
Extension Command: getModel

Then there is just a bunch of things in the Stack Trace.

Any other things to try?

Thanks again for your help.
tchen
Posts: 191
Joined: 11 Dec 2010, 14:14

Post by tchen »

You're not giving us enough information. List your handler code for getModel
Onion
Posts: 10
Joined: 26 Jan 2011, 05:29

Post by Onion »

Ok inside the Main Extension Class I have the following:
This is inside init function which is part of CWMain class.

Code: Select all

addRequestHandler("getModel", CWGetInfoHandler.class);
Then the handler class is :

Code: Select all

package cw.extensions;

import com.smartfoxserver.v2.annotations.Instantiation;
import com.smartfoxserver.v2.annotations.Instantiation.InstantiationMode;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;


	
@Instantiation(InstantiationMode.SINGLE_INSTANCE)
public class CWGetInfoHandler extends BaseClientRequestHandler
{
	private ISFSObject model;
	private WarehouseInfo[] warehouse;
		
	public CWGetInfoHandler()
	{
		trace("INSIDE CWGETINFOHANDLER");
		this.model = generateModel();
	}
		
	@Override
	public void handleClientRequest(User sender, ISFSObject params)
	{
		trace("Sending model to requester: " + sender);
			
		// We just send the data model as SFSObject
		   send("getModel", model, sender);
	}
	
	/*
	 * Generate the data model 
	 */
	private ISFSObject generateModel()
	{
		trace("GENERATING MODEL!!");
		
		CWMain ext = (CWMain) getParentExtension();
		warehouse = ext.getWarehouse();
		
		// --- Prepare SFSOBJECT --------------------------------------------------------------------
		ISFSObject sfsObj = SFSObject.newInstance();
		
		sfsObj = warehouse[0].toSFSObject();
		
		trace("ABOUT TO RETURN THE SFSOBJECT FOR SENDING");
		return sfsObj;
		
	}

}

warehouse is actually an array of a class but I am just specifically grabbing the first part of the array so that I can see it work before I make it do what I actually want.
tchen
Posts: 191
Joined: 11 Dec 2010, 14:14

Post by tchen »

Code: Select all

      ISFSObject sfsObj = SFSObject.newInstance();
      
      sfsObj = warehouse[0].toSFSObject();
      
      trace("ABOUT TO RETURN THE SFSOBJECT FOR SENDING");
      return sfsObj; 
You're overwriting sfsObj. So have you validated that the toSFSObject() on your warehouse object is actually returning a valid object?
Onion
Posts: 10
Joined: 26 Jan 2011, 05:29

Post by Onion »

Here is the code from WarehouseInfo:

Code: Select all

public ISFSObject toSFSObject() 
	{
		ISFSObject sfso = new SFSObject(); 
		
		sfso.putInt("id", id);
		sfso.putInt("owner_id", owner_id);
				
		return sfso;

	}
Problem is with all the trace commands I have in the requesthandler none show up in my server log, so I don't believe the requesthandler is even going to that point. Even the constructor isn't showing the trace.

I appreciate your help on this, it is driving me nuts.
Onion
Posts: 10
Joined: 26 Jan 2011, 05:29

Post by Onion »

Seems I run into a slight issue after testing some things out. First I cannot put a trace command inside the function generate model, it causes the NULL exception error. Next I cannot put

Code: Select all

 warehouse = ext.getWarehouse();
Edit:

Ok now I realize its because the constructor was causing the issue. I moved the function generate model out of the constructor and had it set model inside the handlerequest and it works.
Post Reply