use of com.sun.xml.ws.message.AttachmentSetImpl in project metro-jax-ws by eclipse-ee4j.
the class Messages method create.
/**
* Creates a {@link Message} from an {@link Element} that represents
* the whole SOAP message.
*
* @param soapEnvelope
* The SOAP envelope element.
*/
public static Message create(Element soapEnvelope) {
SOAPVersion ver = SOAPVersion.fromNsUri(soapEnvelope.getNamespaceURI());
// find the headers
Element header = DOMUtil.getFirstChild(soapEnvelope, ver.nsUri, "Header");
HeaderList headers = null;
if (header != null) {
for (Node n = header.getFirstChild(); n != null; n = n.getNextSibling()) {
if (n.getNodeType() == Node.ELEMENT_NODE) {
if (headers == null)
headers = new HeaderList(ver);
headers.add(Headers.create((Element) n));
}
}
}
// find the payload
Element body = DOMUtil.getFirstChild(soapEnvelope, ver.nsUri, "Body");
if (body == null)
throw new WebServiceException("Message doesn't have <S:Body> " + soapEnvelope);
Element payload = DOMUtil.getFirstChild(soapEnvelope, ver.nsUri, "Body");
if (payload == null) {
return new EmptyMessageImpl(headers, new AttachmentSetImpl(), ver);
} else {
return new DOMMessage(ver, headers, payload);
}
}
use of com.sun.xml.ws.message.AttachmentSetImpl in project metro-jax-ws by eclipse-ee4j.
the class JAXBMessage method create.
/**
* Creates a {@link Message} backed by a JAXB bean.
*
* @param bridge
* Specify the payload tag name and how {@code jaxbObject} is bound.
*/
public static Message create(XMLBridge bridge, Object jaxbObject, SOAPVersion soapVer) {
if (!bridge.context().hasSwaRef()) {
return new JAXBMessage(bridge, jaxbObject, soapVer);
}
try {
MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
AttachmentSetImpl attachments = new AttachmentSetImpl();
AttachmentMarshallerImpl am = new AttachmentMarshallerImpl(attachments);
bridge.marshal(jaxbObject, xsb.createFromXMLStreamWriter(), am);
am.cleanup();
// any way to reuse this XMLStreamBuffer in StreamMessage?
return new StreamMessage(null, attachments, xsb.readAsXMLStreamReader(), soapVer);
} catch (JAXBException | XMLStreamException e) {
throw new WebServiceException(e);
}
}
use of com.sun.xml.ws.message.AttachmentSetImpl in project metro-jax-ws by eclipse-ee4j.
the class DispatchImpl method setOutboundAttachments.
protected AttachmentSet setOutboundAttachments() {
HashMap<String, DataHandler> attachments = (HashMap<String, DataHandler>) getRequestContext().get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
if (attachments != null) {
List<Attachment> alist = new ArrayList();
for (Map.Entry<String, DataHandler> att : attachments.entrySet()) {
DataHandlerAttachment dha = new DataHandlerAttachment(att.getKey(), att.getValue());
alist.add(dha);
}
return new AttachmentSetImpl(alist);
}
return new AttachmentSetImpl();
}
Aggregations