powered by Jive Software

Sending multiple bodies in one message

Hi,

I am trying to send multiple bodies in “one” message using Smack. The message content seem to be fine in the sender side, however checking the raw packets shows that only one of the bodies is sent to the receiver. Has anyone successfully tried to send multiple bodies in one message using Smack?

Below is the code snippet and the packets.

  Thank you,
  • SmackUser

++++++++++++++++++++++++++++++++++++++++++++++++++++++++

                    message.addBody("en", "first body");

                    message.addBody("en", "second body");

                    message.addBody("en", "third body");    

                    bodies = message.getBodies();

                    **for** (Object body1 : bodies) {

                          Message.Body body = (Message.Body) body1;

                          System.*out*.println("\tBody : "+ body.getMessage());

                    } 

                    myMUC.sendMessage(message);

The sender’s side code correctly prints:

                       Body : first body

                       Body : third body

                       Body : second body

But the receiver gets only one body and only the following raw packets are sent from the sender:

MultiTextMessagesfirst body

After further investigation, I found out that my problem was with the language setting. I was creating all the bodies in English (“en”) language which is the default language in my setting. Because “en” is the default setting, the system does not create ‘xml:lang’ attribute for its XML representation, and uses that “body” is the default content of the message. Because there were multiple default bodies (bodies with “en” language), the system randomly chooses only one of them.

The following code provides the expected results:

                     …

                    message.addBody("en", "Hello");

                    message.addBody("fr", "Bonjour");

                    message.addBody("es", "Hola");   

                    bodies = message.getBodies();

                    for (Object body1 : bodies) {

                          Message.Body body = (Message.Body) body1;

                          System.out.println("\tBody : "+ body.getMessage());

                    }

                    myMUC.sendMessage(message);

The sender’s side code correctly prints:

                       Body : Bonjour

                       Body : Hello

                       Body : Hola

And the receiver gets all of the bodies:

MultiTextMessagesHelloBonjourHola

  • SmackUser