4 Replies Latest reply on Sep 1, 2009 1:46 PM by Chris Custine

    Servicemix-mail throwing "Content is not allowed in prolog"

    David Hill Newbie

      I am using servicemix.mail (in Fuse 3.4.0.4-fuse) to fetch emails from an exchange server.  It fetches the email fine, and I can see all the properties in the NormalizedMessage if logged out.  But the NMR doesn't seem to like the format.  I get the error message:

       

      :1:1: Content is not allowed in prolog.

       

      Which, after many searches on this forum, servicemix's and other sites, seems to indicate improperly formed XML (or in some rare cases no data at all).

       

      It seems the DefaultMailMarshaler doesn't convert this message to XML that the NMR will accept.  I am assuming that is it's job?  Without explicitly defining a marshaler I get the same error as when I explicitly define the DefaultMailMarshaler or my own marshaler which extends it. 

       

      I thought it might be that I was reading the stream when logging and then it was consumed, but it is the same as when I do not read the contents.  Also, the unaltered DefaultMailMarshaler throws the same error.

       

      I have a camel route defined to catch the incoming mail message, but I believe the error is happening before it even reaches the camel's JBI endpoint.

       

      I have attached MyMailMarshaler and the relevant chunk of the xbean.  As you can see they are quite simple, so I am assuming I am doing something incorrectly.  Any help is appreciated.

       

      DHill

        • 1. Re: Servicemix-mail throwing "Content is not allowed in prolog"
          Chris Custine Newbie

          What is the actual content of your message (is it text or html)?  It would help to see the Content-Type of the mail message, the message body, and the complete stack trace if possible.

           

          Chris

          • 2. Re: Servicemix-mail throwing "Content is not allowed in prolog"
            David Hill Newbie

            Thank you for your response.

             

            Plain text.  The content of the email is "Test Message"

             

            I believe I have just figured out a workaround (or maybe this is the designed course of action?).  If I use my own Marshaler and extend DefaultMailMarshaler to override convertMailToJBI similar to the following:

             

             

            public class MyMailMarshaler extends DefaultMailMarshaler {

            public void convertMailToJBI(MessageExchange exchange,

            NormalizedMessage nmsg, MimeMessage mailMsg)

            throws MessagingException {

            super.convertMailToJBI(exchange, nmsg, mailMsg);

            String mailContent = nmsg.getProperty("org.apache.servicemix.mail.text").toString();

            mailContent = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><emailMessage>" + mailContent + "</emailMessage>";

            try {

            nmsg.setContent(new StringSource(mailContent));

            } catch (javax.jbi.messaging.MessagingException e) {

            e.printStackTrace();

            }

            }

            }

             

            (Also attached)

             

             

            This seems to work.  I am simply taking the plain text of the email, wrapping it with an XML tag, and setting the Content of the message to it.  Without this, the DefaultMailMarshaler drops the plain text into the message content and I get the SAX parsing error because it is not XML.  At least, that is what seems to be happening.

             

            I am not sure if I would want DefaultMailMarshaler doing this, but it would probably beat it throwing an error.  If all things reading the normalized message are looking for the content of the body of the email to be in the "org.apache.servicemix.mail.text" property then the content of the normalized message could be a simple <message/> or some other non-null and SAX parsable XML string.  Perhaps DefaultMailMarshaler should drop in a dummy XML to the message content?

             

            I hope this helps someone else.  Thanks again for the response.

             

            DHill

             

            Edited by: dhillahbelo on Aug 31, 2009 6:56 PM

             

            Edited by: dhillahbelo on Aug 31, 2009 7:03 PM

            • 3. Re: Servicemix-mail throwing "Content is not allowed in prolog"
              Chris Custine Newbie

              You are correct, this looks like a bug in DefaultMailMarshaler.  I don't think it is actually putting your message in the content, it appears to be putting a simple non-XML string ("no content").  I will open an issue on the Apache ServiceMix Jira and address this.

               

              Your approach should work just fine, but to fix this I will more than likely put some dummy xml in there to keep the overhead low (in the case of a large text message) or at least make it an option in the marshaller config.  In this case you will just be using the nmr message properties to get the message.

               

              Chris

              • 4. Re: Servicemix-mail throwing "Content is not allowed in prolog"
                Chris Custine Newbie

                This is now fixed at Apache and should be included in the next Fuse 4.1.0.x release and 4.2.  New behavior adds <no-content /> as message content.