[JDEV] Message sent is blank

Chris Chen ckchris at idream.net
Wed Aug 20 12:24:18 CDT 2003


Hi,

I just realized what you have to put in for your setHTMLBody().

You must include the <html xmlns="http://www.w3.org/1999/xhtml"></html> tag
inside.

In essence, the string that you pass into setHTMLBody() should be a full
HTML document, not just parts of it.  That's why you're getting that No Root
Element error.

So for instance, your following code :

> String jabMessage = "<span
> style='font-size:large'>OMG, i'm </span><span
> style='color:green'>green</span> with <em>envy</em>!";

Should be changed to something like:

String jabMessage = "<html xmlns="http://www.w3.org/1999/xhtml"><body><span
style='font-size:large'>OMG, i'm </span><span
style='color:green'>green</span> with <em>envy</em>!</body></html>";

My memory is failing me and I had to refresh it by looking at the source
code.

Hope this will help you out.

Thanks,
Chris


----- Original Message ----- 
From: "Cunningham, Steven" <Steven.Cunningham at LibertyMutual.com>
To: <jdev at jabber.org>
Sent: Wednesday, August 20, 2003 6:56 AM
Subject: RE: [JDEV] Message sent is blank


> Ok, debug is working.
>
> Here's the output
>
> --- Code ---
>
> Preparing message...
>
> DEBUG [jabber/msg/outgoing] - <?xml version="1.0" encoding="UTF-8"
> ?><stream:stream to="insomnia.lmig.com" xmlns="jabber:client"
> xmlns:stream="http://etherx.jabber.org/streams">
> DEBUG [jabber/msg/incoming] - <stream:stream from="insomnia.lmig.com"
> id="3F437DF5">
> DEBUG [jabber/msg/outgoing] - <iq xmlns="jabber:client" type='get'
> id='id_10029'><query
> xmlns="jabber:iq:auth"><username>user</username></query></iq>
> DEBUG [jabber/msg/incoming] - <iq xmlns="jabber:client" type='result'
> id='id_10029'><query
> xmlns="jabber:iq:auth"><username>user</username><password /><digest
> /><sequence>347</sequence><token>3F37B40F</token><resource
> /></query></iq>
> DEBUG [jabber/msg/outgoing] - <iq xmlns="jabber:client" type='set'
> id='id_10031'><query
> xmlns="jabber:iq:auth"><username>user</username><hash>6d11d3f5f1cc7f7a8c
> a4f014b30c5eb98f9145c3</hash><resource>Home</resource></query></iq>
> DEBUG [jabber/msg/incoming] - <iq xmlns="jabber:client" type='result'
> id='id_10031'></iq>
> DEBUG [jabber/msg/outgoing] - <message xmlns="jabber:client" type='chat'
> id='id_10033' to='StevenCunningham at insomnia.lmig.com'><thread
> xmlns="jabber:client">id_10034</thread></message>
>
> Message sent!
>
> --- End code ---
>
> And again here's my java code on how I'm sending the message:
>
> --- Java code ---
>
> import com.echomine.jabber.*;
> public class JabberTestSteveMain
> {
>
> public static void main(String[] args)
> {
> System.out.println("Preparing message...\n");
> sendJabber();
> System.out.println("\nMessage sent!");
> }
>
>
> public static void sendJabber()
> {
> try
> {
> String jabTo      =
> "StevenCunningham at server.com";
> String jabMessage = "<span
> style='font-size:large'>OMG, i'm </span><span
> style='color:green'>green</span> with <em>envy</em>!";
> // Initialize the Jabber context
> JabberContext jc = new JabberContext("user",
> "pass", "server");
>
> // Create an instance of the Jabber session
> factory
> Jabber jabber = new Jabber();
>
> // Create the new session
> JabberSession jabberSession =
> jabber.createSession(jc);
>
> // Connect to the server
> jabberSession.connect("server", port#);
>
> // Log in to the Jabber server
> jabberSession.getUserService().login();
>
> /* Construct test message
> JabberChatMessage msg = new
> JabberChatMessage(JabberChatMessage.TYPE_HEADLINE);
> msg.setSubject(subject);
> msg.setBody(message);
> msg.setTo(to);
> // Send the message
> jabberSession.sendMessage(msg);
> */
>
> JabberChatMessage msg = new
> JabberChatMessage(JabberChatMessage.TYPE_CHAT);
> msg.setTo(jabTo);
> msg.setHTMLBody(jabMessage);
> msg.setSynchronized(false);
> jabberSession.sendMessage(msg);
> }
> catch (Exception e)
> {
> System.out.println("Jabber Message failed to
> send for the following reason:");
> System.out.println(e.getLocalizedMessage());
> }
> }
> }
>
> --- End  Code ---
>
> Steven Cunningham
> Aspiring J-Developer
>
>
> -----Original Message-----
> From: Chris Chen [mailto:ckchris at idream.net]
> Sent: Tuesday, August 19, 2003 4:52 PM
> To: jdev at jabber.org
> Subject: Re: [JDEV] Message sent is blank
>
>
> Just as a precaution and to make sure you went through the proper steps,
> you should run the following ANT task.
>
> "ant clean"  -- to clean off the previous compiled files to be safe "ant
> jar-with-logging" -- creates the muse-xxx.jar file, compiling the code
> first automatically for you.
>
> You then take that JAR file and use that new file rather than the one
> distributed with Muse.
>
> I just want to make sure you actually compiled and jarred up the proper
> files that contains the logging info.
>
> Change and modify your log4j.properties before doing the
> jar-with-logging.
>
> I've tested this and it should work properly.  I haven't had other
> people complaining about it much, so let me know if this goes well.
>
> Thanks,
> Chris
>
> ----- Original Message ----- 
> From: "Cunningham, Steven" <Steven.Cunningham at LibertyMutual.com>
> To: <jdev at jabber.org>
> Sent: Tuesday, August 19, 2003 1:27 PM
> Subject: RE: [JDEV] Message sent is blank
>
>
> > I changed the logger to what you said, as well as included
> > aspectjrt.jar into my classpath, still nothing in the console but the
> > text I print out after the message is sent.
> >
> > Is there any special java code I need or should put in that'll spit it
>
> > out?
> >
> > Steven Cunningham
> > Aspiring J-Developer
> >
> >
> > -----Original Message-----
> > From: Chris Chen [mailto:ckchris at idream.net]
> > Sent: Tuesday, August 19, 2003 4:04 PM
> > To: jdev at jabber.org
> > Subject: Re: [JDEV] Message sent is blank
> >
> >
> > The message sent should not be blank, which is strange indeed.
> >
> > When you set the log4j.properties, by default it outputs the logs and
> > XML data to the console (ie. your dos prompt window, your IDE console
> > output window, your linux terminal window, etc.).  Try changing the
> > first line's log4j.rootLogger to
> >
> > log4j.rootLogger=DEBUG,console
> >
> > And see if you see any output.
> >
> > Also make sure that you are using the newly compiled muse library and
> > that you have aspectjrt.jar in your classpath.
> >
> > Let me know if it works and if you see anything XML outputs.
> >
> > Good luck,
> > Chris
> >
> > ----- Original Message -----
> > From: "Cunningham, Steven" <Steven.Cunningham at LibertyMutual.com>
> > To: <jdev at jabber.org>
> > Sent: Tuesday, August 19, 2003 12:22 PM
> > Subject: RE: [JDEV] Message sent is blank
> >
> >
> > > Where exactly does this output go?
> > > I recompiled muse for just jabber, and with compile-with-logging
> > > enabled. (Also edited the log4j.properties file, and I believe it's
> > > right.)
> > >
> > > log4j:
> > >
> > > # Default Logging is DEBUG, thus enabling all messages to be logged
> > > log4j.rootLogger=INFO, console
> > > log4j.appender.console=org.apache.log4j.ConsoleAppender
> > > log4j.appender.console.layout=org.apache.log4j.PatternLayout
> > > # Conversion pattern: Priority [Category] Message
> > > log4j.appender.console.layout.ConversionPattern=%-5p [%c] - %m%n #
> > > Conversion pattern: Date Priority [Category] Message
> > > #log4j.appender.console.layout.ConversionPattern=%d %-5p [%c] - %m%n
>
> > > #------------------Jabber Module---------------------------#
> > > #-- logs all incoming parsed messages under DEBUG
> > > log4j.logger.jabber/msg/incoming=DEBUG
> > > #-- logs all outgoing parsed messages under DEBUG
> > > log4j.logger.jabber/msg/outgoing=DEBUG
> > > #-- logs all incoming raw packets under DEBUG
> > > log4j.logger.jabber/packet/incoming=DEBUG
> > > #-- logs all outgoing raw packets under DEBUG
> > > log4j.logger.jabber/packet/outgoing=DEBUG
> > >
> > > Also, JAJC has the option of viewing the xml transmitted. Here's
> > > what it
> > > sends:
> > >
> > > <message xmlns='jabber:client' type='chat' id='id_10033'
> > > to='to at site.com' from='from at site.com/Home'><thread
> > > xmlns='jabber:client'>id_10034</thread></message>
> > >
> > > Here's what I send to setHTMLBody():
> > >
> > > Test<br /><b>TEST!</b> Test Test <span style="font-size: 10px;
> > > font-family: 'Verdana,Arial,sans-seriff';">Test!</span>
> > >
> > > Steven Cunningham
> > > Aspiring J-Developer
> > >
> > >
> > > -----Original Message-----
> > > From: Chris Chen [mailto:ckchris at idream.net]
> > > Sent: Monday, August 18, 2003 1:34 PM
> > > To: jdev at jabber.org
> > > Subject: Re: [JDEV] Message sent is blank
> > >
> > >
> > > Try reading the README file of the Muse package distribution.
> > > Inside,
> >
> > > it will tell you how to enable debugging inside muse.  Simply
> > > compile the debugging into muse and then you will be able to see the
>
> > > incoming and outgoing XML messages outputted (You will need to
> > > configure log4j.properties file as well).
> > >
> > > Then you can see if the message is sending the proper XML data.
> > >
> > > Thanks,
> > > Chris
> > >
> > > ----- Original Message -----
> > > From: "Cunningham, Steven" <Steven.Cunningham at LibertyMutual.com>
> > > To: <jdev at jabber.org>
> > > Sent: Monday, August 18, 2003 6:12 AM
> > > Subject: [JDEV] Message sent is blank
> > >
> > >
> > > > I've been trying to get a jabber message to accept xhtml
> > > > formatting,
> >
> > > > but without much luck. The message is sent all right, but it shows
>
> > > > nothing in the message (Shows who sent it, but then the message
> > > > itself
> > >
> > > > is blank.)
> > > >
> > > > Here's the code that sends it (java)
> > > >
> > > > String message = "<span style='font-size:large'>OMG, i'm
> > > > </span><span style='color:green'>green</span> with
> > > > <em>envy</em>!"; JabberChatMessage msg = new
> > > > JabberChatMessage(JabberChatMessage.TYPE_CHAT);
> > > > msg.setTo(jabTo);
> > > > msg.setHTMLBody(message);
> > > > msg.setSynchronized(false); jabberSession.sendMessage(msg);
> > > > System.out.println("--- Jabber messages sent successfully!\n");
> > > >
> > > > When I included the <html> and <body> tags, I got the
> > > > SendMessageFailedException popped up.
> > > > SendMessageFailedException.getLocalizedMessage() returns this: The
>
> > > > element "html" could not be added as a child of "message": The
> > > > element
> > >
> > > > already has an existing parent (the document root)
> > > >
> > > > Steven Cunningham
> > > > Aspiring J-Developer
> > > > _______________________________________________
> > > > jdev mailing list
> > > > jdev at jabber.org
> > > > http://mailman.jabber.org/listinfo/jdev
> > > >
> > >
> > > _______________________________________________
> > > jdev mailing list
> > > jdev at jabber.org
> > > http://mailman.jabber.org/listinfo/jdev
> > > _______________________________________________
> > > jdev mailing list
> > > jdev at jabber.org
> > > http://mailman.jabber.org/listinfo/jdev
> > >
> >
> > _______________________________________________
> > jdev mailing list
> > jdev at jabber.org
> > http://mailman.jabber.org/listinfo/jdev
> > _______________________________________________
> > jdev mailing list
> > jdev at jabber.org
> > http://mailman.jabber.org/listinfo/jdev
> >
>
> _______________________________________________
> jdev mailing list
> jdev at jabber.org
> http://mailman.jabber.org/listinfo/jdev
> _______________________________________________
> jdev mailing list
> jdev at jabber.org
> http://mailman.jabber.org/listinfo/jdev
>




More information about the JDev mailing list