sending a public message as xml

Post here all your questions related with SmartFoxServer Java API

Moderators: Lapo, Bax

sakhapour
Posts: 1
Joined: 08 May 2009, 03:39

sending a public message as xml

Postby sakhapour » 08 May 2009, 03:50

Hi,

I am trying to post XML messages to the users of a room. I am using the client API sendPublicMessage. However, I noticed the special charters in XML are not handled properly when I receive the message on public message handler. Am I using the right API for this purpose?

Any information is greatly appreciated.

Thanks,

AB
patso
Posts: 380
Joined: 13 Nov 2006, 13:44
Location: Sofia, Bulgaria

Re: sending a public message as xml

Postby patso » 12 May 2009, 06:37

Hi,

sakhapour wrote:However, I noticed the special charters in XML are not handled properly

Because SFS uses XML based protocol all string that include XML special characters are encoded - for example "<" becomes "&lt;". Is that what you see?

sakhapour wrote:when I receive the message on public message handler.

Is this the public message handler on client side or it's the server side one?

sakhapour wrote:Am I using the right API for this purpose?

Actually depends on the purpose. Why you need to send XML? In general you should be able to send XML messages using public messages without problems.
asakhapour
Posts: 9
Joined: 08 May 2009, 03:35

Postby asakhapour » 12 May 2009, 16:55

Yes, I have noticed that the message is encoded no matter what. It seems that it is not decoding properly on handler side. Our application needs to send xml messages to users in the room and the user will process that xml appropriately.

I noticed sendObject is encoding as well. They way I got around this for now modified the open source code not to encode. In my source code I am implementing the:

public void handleEvent(SFSEvent event) {
...
}

However, when I send an XML through sendPublicMessage or sendObject it should be decoded properly when the callback gets called on handleEvent but is not getting decoded!!

Am I missing some step or configuration here?

Thanks.
patso
Posts: 380
Joined: 13 Nov 2006, 13:44
Location: Sofia, Bulgaria

Postby patso » 12 May 2009, 17:20

The messages are decoded before they are passed to the public message event handler. You can check the example provided with the API - if you send XML special characters they are send and received without a problem.

Could you give the debug output from the client API?
asakhapour
Posts: 9
Joined: 08 May 2009, 03:35

Postby asakhapour » 16 May 2009, 01:07

Here is the xml I am sending:

<msg t='sys'><body action='setting'><get src='controlfile' name='siteid'/></body></msg>

The followings are the messages send and received through smartfox:

INFO: [Sending]: <msg t ='sys'><body action='pubMsg' r='1'><txt><![CDATA[&lt;msg t=&apos;sys&apos;&gt;&lt;body action=
pos;setting&apos;&gt;&lt;get src=&apos;controlfile&apos; name=&apos;siteid&apos;/&gt;&lt;/body&gt;&lt;/msg&gt; ]]></tx
</body></msg>

INFO: [ RECEIVED ]: <msg t='sys'><body action='pubMsg' r='1'><user id='3928' /><txt><![CDATA[&lt;msg t=&apos;sys&apos;
t;&lt;body action=&apos;setting&apos;&gt;&lt;get src=&apos;controlfile&apos; name=&apos;siteid&apos;/&gt;&lt;/body&gt;
t;/msg&gt; ]]></txt></body></msg>, (len: 253)

I can see it is getting encoded on send side, but on receive side some how is not getting decoded.
patso
Posts: 380
Joined: 13 Nov 2006, 13:44
Location: Sofia, Bulgaria

Postby patso » 16 May 2009, 03:57

Well, the debug output looks normal. How you understood the XML is not decoded? I can't reproduce the problem - tried the same string and everything is working perfectly.
asakhapour
Posts: 9
Joined: 08 May 2009, 03:35

Postby asakhapour » 18 May 2009, 20:00

Look at the content of the CDATA on “receivedâ€
patso
Posts: 380
Joined: 13 Nov 2006, 13:44
Location: Sofia, Bulgaria

Postby patso » 19 May 2009, 18:27

The debug output is the exact trance of what is received from the server. The message is decoded before it's passed to the on public message handler. The debug output shows what is received from the server - not what is passed to the handler.

Return to “Java2SE / Android Client API”

Who is online

Users browsing this forum: No registered users and 19 guests