{
reqMsg = (SOAPMessageImpl)factory.createMessage();
SOAPBodyImpl soapBody = (SOAPBodyImpl)reqMsg.getSOAPBody();
SOAPContentElement bodyElement = new SOAPBodyElementDoc(SOAPBodyElementDoc.GENERIC_PARAM_NAME);
bodyElement = (SOAPContentElement)soapBody.addChildElement(bodyElement);
XMLFragment xmlFragment = new XMLFragment(source);
bodyElement.setXMLFragment(xmlFragment);
// validate payload if necessary
if (validateDispatch)
{
// expand to DOM will validate the contents
xmlFragment.toElement();
}
}
if (mode == Mode.MESSAGE)
{
TransformerFactory tf = TransformerFactory.newInstance();
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
tf.newTransformer().transform(source, new StreamResult(baos));
reqMsg = (SOAPMessageImpl)factory.createMessage(null, new ByteArrayInputStream(baos.toByteArray()));
}
}
else if (jaxbContext != null)
{
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
marshaller.marshal(obj, baos);
reqMsg = (SOAPMessageImpl)factory.createMessage();
SOAPBodyImpl soapBody = (SOAPBodyImpl)reqMsg.getSOAPBody();
SOAPContentElement bodyElement = new SOAPBodyElementDoc(SOAPBodyElementDoc.GENERIC_PARAM_NAME);
bodyElement = (SOAPContentElement)soapBody.addChildElement(bodyElement);
StreamSource source = new StreamSource(new ByteArrayInputStream(baos.toByteArray()));
bodyElement.setXMLFragment(new XMLFragment(source));
}
}
catch (RuntimeException rte)
{
throw rte;