Introduction
Service-clients and service-providers are often facing the need for transmitting both binary content and text data in a reliable and efficient way.
This document presents implementation outlines for this scenario. The service-provider has been implemented using the Oracle Service Bus (version 11.1.1.7) while the service-client has been realized using SOAPUI.
W3C Notes and Recommendations.
This document follows the documents SOAP Messages with Attachments: W3C Note 11 December 2000 and the SOAP Message Transmission Optimization Mechanism: W3C Recommendation – 25 January 2005 that describe standards on SOAP Message Transmission.
SOAP-with-Attachments (SwA)
The „SOAP Messages with Attachments: W3C Note 11 December 2000“ states:
„This document defines a binding for a SOAP 1.1 message to be carried within a MIME multipart/related message in such a way that the processing rules for the SOAP 1.1 message are preserved. The MIME multipart mechanism for encapsulation of compound documents can be used to bundle entities related to the SOAP 1.1 message such as attachments. Rules for the usage of URI references to refer to entities bundled within the MIME package are specified.“ |
![]() |
Implementation
Service Provider
We define the xml schema as follows:
<?xml version="1.0" encoding="UTF-8" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.svi.de/SWA" targetNamespace="http://www.svi.de/SWA" elementFormDefault="qualified"> <xsd:element name="payload" type="PayloadType" /> <xsd:complexType name="DocMetaType"> <xsd:sequence> <xsd:element name="Fname" type="xsd:string" /> <xsd:element name="Fpath" type="xsd:string" /> <xsd:element name="text" type="xsd:string" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name="PayloadType"> <xsd:sequence> <xsd:element name="docInfo" type="DocMetaType" /> </xsd:sequence> </xsd:complexType> <xsd:element name="payloadResponse" type="PayloadResponseType" /> <xsd:complexType name="PayloadResponseType"> <xsd:sequence> <xsd:element name="Fname" type="xsd:string" /> <xsd:element name="action" type="xsd:string" /> <xsd:element name="text" type="xsd:string" /> </xsd:sequence> </xsd:complexType> </xsd:schema>
We use a file adapter for saving the attachment. Since the file adapter needs a base64-encoded-string we have to use a Java Callout to encode the byte array from:
$attachments/ctx:attachment/ctx:body/ctx:binary-content
The result string will be passed straight forward to the file adapter.
Service Client
For the Service-Client we use a default request from SOAPUI.
Example:
Request
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:swa="http://www.svi.de/SWA"> <soapenv:Header/> <soapenv:Body> <swa:payload> <swa:docInfo> <swa:Fname>MASTERING_BLOCKCHAIN.pdf</swa:Fname> <swa:Fpath>/home/oracle/Downloads/</swa:Fpath> <swa:text>some text</swa:text> </swa:docInfo> </swa:payload> </soapenv:Body> </soapenv:Envelope>
Response:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header xmlns:mtom="http://www.svi.de/SWA"/> <soapenv:Body xmlns:mtom="http://www.svi.de/SWA"> <swa:payloadResponse> <swa:Fname>MASTERING_BLOCKCHAIN.pdf</swa:Fname> <swa:action>ok</swa:action> <swa:text>some text. Message contains 1 attachment</swa:text> </swa:payloadResponse> </soapenv:Body> </soapenv:Envelope>
Load Tests
The detailed results:
Various files (pdf, zip, docx, etc.) have been transmitted, with a total of 137 MB. The mean total time was 23 sec., which means an average throughput of 5,9MB/sec.
Attachments over 70 MB were rejected by an Out-Of-Memory Exception.
SOAP Message Transmission Optimization Mechanism (MTOM)
MTOM optimizes element content that is in the canonical lexical representation of the xsd:base64Binary data type.
Implementation
Service Provider
We define the xml schema as follows:
<?xml version="1.0" encoding="UTF-8" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.svi.de/MTOM" targetNamespace="http://www.svi.de/MTOM" elementFormDefault="qualified"> <xsd:element name="payload" type="PayloadType" /> <xsd:complexType name="DocMetaType"> <xsd:sequence> <xsd:element name="Fname" type="xsd:string" /> <xsd:element name="Fpath" type="xsd:string" /> <xsd:element name="text" type="xsd:string" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name="PayloadType"> <xsd:sequence> <xsd:element name="docInfo" type="DocMetaType" /> <xsd:element name="document" type="xsd:base64Binary" /> </xsd:sequence> </xsd:complexType> <xsd:element name="payloadResponse" type="PayloadResponseType" /> <xsd:complexType name="PayloadResponseType"> <xsd:sequence> <xsd:element name="Fname" type="xsd:string" /> <xsd:element name="action" type="xsd:string" /> <xsd:element name="text" type="xsd:string" /> </xsd:sequence> </xsd:complexType> </xsd:schema>
We use a file adapter for saving the attachment. Since the file adapter needs a base64-encoded-string we have to use a Java Callout to encode the byte array from
$body/mtom:payload/mtom:document/ctx:binary-content
The result will be passed straight forward to the file adapter.
Service Client
In SOAPUI we create a Request and we enable the MTOM parameter
Example:
Request
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mtom="http://www.svi.de/MTOM"> <soapenv:Header/> <soapenv:Body> <mtom:payload> <mtom:docInfo> <mtom:Fname>MASTERING_BLOCKCHAIN.pdf</mtom:Fname> <mtom:Fpath>/home/oracle/Downloads/</mtom:Fpath> <mtom:text>some Text</mtom:text> </mtom:docInfo> <mtom:document>cid:9781787125445-MASTERING_BLOCKCHAIN.pdf</mtom:document> </mtom:payload> </soapenv:Body> </soapenv:Envelope>
Response:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header xmlns:mtom="http://www.svi.de/MTOM"/> <soapenv:Body xmlns:mtom="http://www.svi.de/MTOM"> <mtom:payloadResponse> <mtom:Fname>MASTERING_BLOCKCHAIN.pdf</mtom:Fname> <mtom:action>ok</mtom:action> <mtom:text>some Text</mtom:text> </mtom:payloadResponse> </soapenv:Body> </soapenv:Envelope>
Load-Tests
The detailed results:
Various files (pdf, zip, docx, etc.) have been transmitted, with a total of 137 MB. The mean total time was 15 sec., which means an average throughput of 9.1 MB/sec.
Attachments over 70 MB were rejected by an out-of-Memory Exception.
Simple base64 Java Encoder
The following code for the java base64-encoder can be used by the Java Callout
package de.svi.att.tools; import weblogic.utils.encoders.BASE64Encoder; public class SVIBase64Encoder{ public static String encode(byte[] bytes){ BASE64Encoder encoder = new BASE64Encoder(); String encodedString = encoder.encodeBuffer(bytes); return encodedString; } }
Conclusion
We have implemented a client using SOAPUI and a service provider using OSB and a VM with the oracle SOA Suite Appliance 11.1.1.7 in order to compare the methods SwA and MTOM.
The MTOM mechanism has a performance advantage of 15%-30% compared to the SwA method.
None of the load tests led to a drop of server-performance due to garbage collection actions.
No Problems when dealing with special characters have been observed.