JSON vs ActionScript Objects

Post here all your questions related with SmartFoxServer Java API

Moderators: Bax, Lapo, rjgtav

JSON vs ActionScript Objects

Postby rockycaam » 24 Mar 2010, 23:05

I'm having a weird issue with extension responses.

If I send the response as JSON the extension handler on the client-side does not get fired, but if I send it as ActionScriptObject everything works fine.

Here is the code that works on the server-side:
Code: Select all
ActionscriptObject response = new ActionscriptObject();

response.put("_cmd", CustomCommand.BUDDY_MESSAGE); //"buddyMessage"
response.put("buddyName", buddyName);
response.put("msg", buddyMessage);

LinkedList<SocketChannel> recipients = new LinkedList<SocketChannel>();

recipients.add(user.getChannel());

_parentExtension.sendResponse(response, user.getRoom(), user, recipients);


And here is the code that does not work:
Code: Select all
JSONObject response = new JSONObject ();

response.put("_cmd", CustomCommand.BUDDY_MESSAGE); //"buddyMessage"
response.put("buddyName", buddyName);
response.put("msg", buddyMessage);

LinkedList<SocketChannel> recipients = new LinkedList<SocketChannel>();

recipients.add(user.getChannel());

_parentExtension.sendResponse(response, user.getRoom(), user, recipients);


As you can see the only difference is the response type (one is ActionScriptObject, and the other one is JSONObject).

Both responses get to the client (I see the SmartFoxDebug debug "INFO [ RECEIVED ]: " message on my console), but the ExtensionHanlder only gets the xml-based response (the one that uses ActionScriptObject on the server), but not the json-based one.

I'm using Java for both server and client code.

Any clues?
rockycaam
 
Posts: 14
Joined: 08 Jan 2009, 19:47

Postby mauro » 16 Apr 2010, 07:02

I have the same problem.
I can't take the JSON response in my java client, beacause it throw a ClassCastException.
Below the full stack trace:

Code: Select all
java.lang.ClassCastException: org.json.JSONObject cannot be cast to
it.gotoandplay.smartfoxclient.data.SFSObject
   at it.gotoandplay.smartfoxclient.data.SFSObject.getObj(SFSObject.java:254)
   at it.sgs.smartfoxclient.view.frame.LoginFrame.handleEvent(LoginFrame.java:78)
   at it.gotoandplay.smartfoxclient.SFSEventDispatcher.
dispatchEvent(SFSEventDispatcher.java:96)
   at it.gotoandplay.smartfoxclient.handlers.ExtHandler.handleMessage(ExtHandler.java:64)
   at it.gotoandplay.smartfoxclient.SmartFoxClient.jsonReceived(SmartFoxClient.java:4321)
   at it.gotoandplay.smartfoxclient.SmartFoxClient.handleMessage(SmartFoxClient.java:4598)
   at it.gotoandplay.smartfoxclient.SmartFoxClient.onData(SmartFoxClient.java:4573)
   at it.gotoandplay.utils.net.xmlsocket.XMLSocket.fireDataEvent(XMLSocket.java:132)
   at it.gotoandplay.utils.net.xmlsocket.XMLSocketClientHandler.
messageReceived(XMLSocketClientHandler.java:31)
   at org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.
messageReceived(AbstractIoFilterChain.java:570)
   at org.apache.mina.common.support.AbstractIoFilterChain.
callNextMessageReceived(AbstractIoFilterChain.java:299)
   at org.apache.mina.common.support.AbstractIoFilterChain.
access$1100(AbstractIoFilterChain.java:53)
   at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.
messageReceived(AbstractIoFilterChain.java:648)
   at org.apache.mina.filter.codec.support.SimpleProtocolDecoderOutput.
flush(SimpleProtocolDecoderOutput.java:58)
   at org.apache.mina.filter.codec.ProtocolCodecFilter.
messageReceived(ProtocolCodecFilter.java:180)
   at org.apache.mina.common.support.AbstractIoFilterChain.
callNextMessageReceived(AbstractIoFilterChain.java:299)
   at org.apache.mina.common.support.AbstractIoFilterChain.
access$1100(AbstractIoFilterChain.java:53)
   at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.
messageReceived(AbstractIoFilterChain.java:648)
   at org.apache.mina.filter.executor.ExecutorFilter.processEvent(ExecutorFilter.java:220)
   at org.apache.mina.filter.executor.ExecutorFilter$ProcessEventsRunnable.
run(ExecutorFilter.java:264)
   at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
   at org.apache.mina.util.NamePreservingRunnable.
run(NamePreservingRunnable.java:51)
   at java.lang.Thread.run(Unknown Source)


My source code is:

Code: Select all
String type = event.getParams().getString("type");
         SFSObject obj = null;

         if (type.equals(SmartFoxClient.XTMSG_TYPE_JSON)) {

            try {
                obj = event.getParams().getObj("dataObj");
            } catch (Exception e) {
               e.printStackTrace();
            }

            System.out.println("Parametro #2: " + obj.getString("2"));
         }


Help me, please! Thanks
mauro
 
Posts: 12
Joined: 16 Apr 2010, 06:53
Location: Italy - Ribera (AG)

Postby mauro » 19 Apr 2010, 07:03

It's the same thing for raw type (String)? It's possible?!?!
:shock:
mauro
 
Posts: 12
Joined: 16 Apr 2010, 06:53
Location: Italy - Ribera (AG)

Postby mauro » 20 Apr 2010, 15:38

Sorry, it's only an error in my code!! :oops:

The correct code is:
Code: Select all
Object o = event.getParams().get("dataObj");
JSONObject obj = (JSONObject) o;


Sorry... :roll:
mauro
 
Posts: 12
Joined: 16 Apr 2010, 06:53
Location: Italy - Ribera (AG)


Return to Java2SE / Android Client API

Who is online

Users browsing this forum: No registered users and 1 guest