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: Thu, 08 Jan 2004 09:06:37 -0800

Ok, well, I guess I've resolved this. I changed the content type of the
attachment from "text/xml" to "text/plain" and that made it work for
both my Junit and Cactus tests. I'm not sure why this makes a
difference, but it does work.

-----Original Message-----
From: Karr, David
Sent: Monday, December 29, 2003 12:00 PM
To: users_at_saaj.dev.java.net
Subject: RE: [SAAJ-USR] SOAPMessage.writeTo(ByteArrayOutputStream) works
fine standalone, but fails from servlet


I imagine most of the people that would need to see this have been off
the previous week, so I'm resending this.

To reiterate, I had code that appeared to work, which took an XML string
from a particular schema, then created a SOAPMessage object from the
pieces of the original XML. My test case then printed out the resulting
SOAP XML. This was working fine with "standalone" Junit tests.

I then wrote a Servlet test case, using Tomcat and Cactus, with
essentially the same test case, but this started failing, apparently
because I was adding an AttachmentPart from a DOMSource object.

So I changed the code which created the DOMSource object to instead
serialize the result to a string and use that to create the
AttachmentPart. This made the servlet test case work. Unfortunately,
this now caused the Junit test to fail when I try to write the result to
an OutputStream.

I can get both tests to "succeed" if I don't use attachments at all, but
that's the whole point for me using this.

I'm sure this is a CLASSPATH issue with the XML parser libraries, but I
don't see what it could be.

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


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


---------------------------------------------------------------------
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