I don't' know if it is anohter bug in
com.sun.xml.messaging.saaj.soap.XmlDataContentHandler, specifically
the writeTo method.
When I mix in the same JVM (Java 5) Axiom Swa and SAAJ MTOM I first
encountered the problem referred here
https://saaj.dev.java.net/servlets/ReadMsg?list=users&msgNo=83.
After downloading the saaj patched version from here
https://saaj.dev.java.net/servlets/ProjectDocumentList?folderID=5118&exp
andFolder=5118&folderID=5118
I solved this problem, but then when I use an Axiom SwA web service
client after using SAAJ I got this new error:
java.io.IOException: Unable to run the JAXP transformer on a stream
java.lang.String
23:09:25,187 ERROR [STDERR] at
com.sun.xml.messaging.saaj.soap.XmlDataContentHandler.writeTo....
After some debugging I discovered the problem is the casting of the
Object to write to javax.xml.transform.Source (last line of following
coe fragment from XmlDataContentHandler):
....
if (obj instanceof DataSource) {
// Streaming transform applies only to javax.xml.transform.StreamSource
transformer.transform((Source) getContent((DataSource)obj), result);
}
else {
transformer.transform((Source) obj, result);
}
....
the real Exception is a ClassCastException because obj is a String.
I don't know if the Axiom way to create the MimePart content as a String
is correct but a simple change to the previous lines in
XmlDataContentHandler solves the problem:
if (obj instanceof DataSource) {
// Streaming transform applies only to
javax.xml.transform.StreamSource
transformer.transform((Source)
getContent((DataSource) obj),
result);
} else {
Source src=null;
if (obj instanceof String) {
src= new StreamSource(new
java.io.StringReader((String) obj));
} else
src=(Source) obj;
transformer.transform(src, result);
}
Luciano