In the enterprise world developing simple SOAP based web services are not enough and they have to deal with binary data like Imgae, PDF, Word, Xls and other documents. We will see simple SOAP client for streaming binary data.
Base64 Problem
The most popular way of sending the binary attachments to SOAP service is to encode the content as Base64. This method may well work for smaller size of attachments as the Base64 encoding is memory intensive operation. The entire content needs to loaded into memory and encoded using Base64. The encoded data needs to embedded within the SOAP body XML.
Also the encoded data size is roughly 37% more than the raw binary data. To make it work for large files you need to upgrade your JVM memory.
Streaming of Attachments (SOAP with attachments)
The memory intensive operation can be avoided using SOAP with attachments. The idea of SOAP with attachments is sames attaching the document to email. The SOAP Body contains only the reference to the binary file and binary file will be streamed outside of SOAP Envelope.
The following example shows the SOAP message and the attachments. This example is for Oracle UCM's CheckInUniversal operation.
The SOAP message package is constructed using the
Base64 Problem
The most popular way of sending the binary attachments to SOAP service is to encode the content as Base64. This method may well work for smaller size of attachments as the Base64 encoding is memory intensive operation. The entire content needs to loaded into memory and encoded using Base64. The encoded data needs to embedded within the SOAP body XML.
Also the encoded data size is roughly 37% more than the raw binary data. To make it work for large files you need to upgrade your JVM memory.
Streaming of Attachments (SOAP with attachments)
The memory intensive operation can be avoided using SOAP with attachments. The idea of SOAP with attachments is sames attaching the document to email. The SOAP Body contains only the reference to the binary file and binary file will be streamed outside of SOAP Envelope.
The following example shows the SOAP message and the attachments. This example is for Oracle UCM's CheckInUniversal operation.
The SOAP message package is constructed using the
Multipart/Related
media type. The rules for the construction of SOAP message packages are as follows:- The primary SOAP message must be carried in the root body part of the Multipart/Related structure. Consequently the type parameter of the
Multipart/Related
media header will always equal theContent-Type
header for the primary SOAP 1.1 message, i.e.,text/xml.
- Referenced MIME parts must contain either a
Content-ID
MIME header.
Content-Type: multipart/related; type="text/xml"; start="<test@example.com>"; boundary="----=_Part_12_21424854.1424891476173"
SOAPAction: "http://www.stellent.com/CheckIn/"
Content-Length: 1818
------=_Part_12_21424854.1424891476173
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: <test@example.com>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:chec="http://www.stellent.com/CheckIn/">
<soapenv:Header/>
<soapenv:Body>
<chec:CheckInUniversal>
<chec:dDocName/>
<chec:dDocTitle>TestStreaming-large</chec:dDocTitle>
<chec:dDocType>Records</chec:dDocType>
<chec:dDocAuthor>username</chec:dDocAuthor>
<chec:dSecurityGroup>group</chec:dSecurityGroup>
<chec:dDocAccount/>
<chec:CustomDocMetaData>
<chec:property>
<chec:name>xLibrary</chec:name>
<chec:value>library</chec:value>
</chec:property>
<chec:property>
<chec:name>xesd_proj_name</chec:name>
<chec:value>Test</chec:value>
</chec:property>
</chec:CustomDocMetaData>
<chec:primaryFile>
<chec:fileName>TestUCM-large</chec:fileName>
</chec:primaryFile>
</chec:CheckInUniversal>
</soapenv:Body>
</soapenv:Envelope>
------=_Part_12_21424854.1424891476173
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Content-ID: <primaryFile>
Hello
------=_Part_12_21424854.1424891476173--
The oracle UCM service expects the Content-ID of the attachment to be 'primaryFile' SOAP Part. The attachment file content is "Hello"
UploadStream Client
|
MimeMessageRequestEntity.java
|
RequestXmlDataSource.java
|
AttachmentDataSource.java
|