users@saaj.java.net

RE: [SAAJ-USR] SOAPMessage.writeTo(ByteArrayOutputStream) works fine standalone, but fails from servlet

From: Karr, David <David.Karr_at_wamu.net>
Date: Fri, 19 Dec 2003 13:38:32 -0800

Well, I at least figured out where it was getting a DOMSource from. I
finally remembered that I was adding an attachment that was using
DOMSource to wrap an Element. So, since the OOTB XML API doesn't give
me any way to serialize XML (did I miss it?), I pulled in XercesImpl to
get the serializers.

So, my block of code was originally doing this:

        AttachmentPart attachmentPart =
            result.createAttachmentPart(new DOMSource(headerElem),
"text/xml");

I changed it to this:

        ByteArrayOutputStream byteArrayOutputStream =
            new ByteArrayOutputStream();
        XMLSerializer xmlSerializer =
            new XMLSerializer(byteArrayOutputStream, new
OutputFormat());
        xmlSerializer.serialize(headerElem);
        String serializedResult = byteArrayOutputStream.toString();
        AttachmentPart attachmentPart =
            result.createAttachmentPart(serializedResult, "text/xml");

This made the servlet test work. However, now the Junit test fails on
the same line (the place where the "SOAPMessage.writeTo()" method is
called (after this point in the code). It gives me the exception
following this.

I tried commenting out the code which creates the attachment, and that
makes both the junit and cactus tests work. That only tells me the
problem areas are in the attachment, not the "body" of the message (if
that wasn't already obvious).

java.io.IOException: Unable to run the JAXP transformer on a stream null
        at
com.sun.xml.messaging.saaj.soap.XmlDataContentHandler.writeTo(XmlDataCon
tentHandler.java:92)
        at
javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:839)
        at javax.activation.DataHandler.writeTo(DataHandler.java:295)
        at
javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1147)
        at
javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:668)
        at
javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:233)
        at
com.sun.xml.messaging.saaj.soap.MessageImpl.saveChanges(MessageImpl.java
:563)
        at
com.sun.xml.messaging.saaj.soap.MessageImpl.writeTo(MessageImpl.java:591
)

-----Original Message-----
From: Karr, David
Sent: Friday, December 19, 2003 10:08 AM
To: users_at_saaj.dev.java.net
Subject: [SAAJ-USR] SOAPMessage.writeTo(ByteArrayOutputStream) works
fine standalone, but fails from servlet


I have a method which takes a SOAPMessage (actually ends up being
"com.sun.xml.messaging.saaj.soap.ver1_1.Message1_1Impl"). The method
creates a ByteArrayOutputStream and calls
"SOAPMessage.writeTo(OutputStream)" to write the contents of the
SOAPMessage as a string to the stream (I assume that's the intent of
that).

I wrote several Junit tests which end up calling this method, and they
work perfectly fine.

I now have a servlet which ends up calling the same method, and a Cactus
test, with implicitly identical data to the Junit test, and when it gets
to the "writeTo()" call in this method, I get the stack trace which
follows this. I don't understand what is happening here.

java.io.IOException: "text/xml" DataContentHandler requires String
object, was given object of type class javax.xml.transform.dom.DOMSource
        at com.sun.mail.handlers.text_plain.writeTo(text_plain.java:97)
        at
javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:849)
        at javax.activation.DataHandler.writeTo(DataHandler.java:305)
        at
javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1089)
        at
javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:635)
        at
javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:233)
        at
com.sun.xml.messaging.saaj.soap.MessageImpl.saveChanges(MessageImpl.java
:563)
        at
com.sun.xml.messaging.saaj.soap.MessageImpl.writeTo(MessageImpl.java:591
)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_saaj.dev.java.net
For additional commands, e-mail: users-help_at_saaj.dev.java.net


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_saaj.dev.java.net
For additional commands, e-mail: users-help_at_saaj.dev.java.net