Page 1 of 1

JSON vs ActionScript Objects

Posted: 24 Mar 2010, 23:05
by rockycaam
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?

Posted: 16 Apr 2010, 07:02
by mauro
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

Posted: 19 Apr 2010, 07:03
by mauro
It's the same thing for raw type (String)? It's possible?!?!
:shock:

Posted: 20 Apr 2010, 15:38
by mauro
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: