// If we have swaRef, then that means we might have attachments.
// to comply with the packet API, we need to eagerly turn the JAXB object into infoset
// to correctly find out about attachments.
try {
MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
Marshaller m = context.createMarshaller();
AttachmentMarshallerImpl am = new AttachmentMarshallerImpl(attachments);
m.setAttachmentMarshaller(am);
am.cleanup();
m.marshal(jaxbObject,xsb.createFromXMLStreamWriter());
// any way to reuse this XMLStreamBuffer in StreamMessage?
return new StreamMessage(headers,attachments,xsb.readAsXMLStreamReader(),soapVersion);
} catch (JAXBException e) {
throw new WebServiceException(e);
} catch (XMLStreamException e) {
throw new WebServiceException(e);
}