Locating an attachment using swaref
Use this task to locate message attachments by retrieving the message URI and removing cid: from the beginning of the retrieved value.
When a Web Services-Interoperability (WS-I) Attachments Profile Version 1.0 message uses a SOAP with attachments reference (swaref) to refer to an attachment, the swaref might refer to either bound or non-bound attachments, and the swaref might refer to a single attachment several times. To allow us to locate the correct attachment, service integration technologies stores the value of the URI that is encoded in the message within the SDO data graph for the message body.
When storing the value of an element (or attribute) of type swaref in the data graph, service integration technologies stores the complete URI from the message instance. Therefore when you retrieve the URI you remove cid: from the beginning of the retrieved value to find the Content ID of the referenced attachment.
Example
The following example shows how to use the value of a swaref element to locate the correct attachment. This example uses the RPC/Literal WSDL and SOAP message from section 4.4 of Web Services-Interoperability (WS-I) Attachments Profile Version 1.0:
DataObject infoNode = graph.getRootObject().getDataObject("info"); String contentId = infoNode.getString("body/ClaimDetail/ClaimForm"); // Cut off the "cid:" part of the string contentId = contentId.substring(4); // Locate the value of the attachment DataObject attachmentEntry = infoNode.getDataObject("attachments[contentId=" + contentId + "]"); byte[] data = attachmentEntry.getBytes("data");
Related:
SOAP with attachments: A definition Mapping of SDO data graphs for web services messages SOAP Messages with Attachments: WSDL examples Supporting bound attachments: WSDL examples