SOAP MTOM Attachment Download for SOAP 1.1 BW 5.12

When I was working in one of integration solution with ORACLE CLOUD using SOAP services I noticed MTOM attachment with BW 5. 12 is not supported you cannot use SOAP activities for calling Oracle Cloud Web Services. As a workaround, I used java activity for calling MTOM soap services and able to download files from oracle CLoud. Below are the detail JAVA code for calling web services.

 

/* Available Variables: DO NOT MODIFY
In : String in_RequestId
In : String in_FileType
In : String in_SoapAction
In : String in_URL
In : String in_File_Path
In : String in_Filename_Element
In : int in_ConectTimeout_ms
In : int in_ReadTimeout_ms
Out : String message
Out : String out_file_path
Out : String out_Stack_Trace
Out : String out_SOAP_Response
* Available Variables: DO NOT MODIFY *****/
try{
String password=PluginProperties.getProperty(“tibco.clientVar.Supplier/Password_Service”);
String userName=PluginProperties.getProperty(“tibco.clientVar.Supplier/UserName_Service”);
String originalInput=userName+”:”+password;

String Auth=DatatypeConverter.printBase64Binary(originalInput.getBytes(“UTF-8”));

// creating URL with Time out
URL endpoint = new URL(new URL(in_URL), “”,
new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL url) throws IOException {
URL target = new URL(url.toString());
URLConnection connection = target.openConnection();
// Connection settings
connection.setConnectTimeout(in_ConectTimeout_ms); // 10000=10 sec
connection.setReadTimeout(in_ReadTimeout_ms); // 60000=1 min
return(connection);
}
});

MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
soapEnvelope.addNamespaceDeclaration(“typ”, “http://xmlns.oracle.com/apps/financials/commonModules/shared/model/erpIntegrationService/types/”);
SOAPBody soapBody = soapEnvelope.getBody();
SOAPElement soapElement = soapBody.addChildElement(“downloadESSJobExecutionDetails”, “typ”);
SOAPElement element1 = soapElement.addChildElement(“requestId”, “typ”);
element1.addTextNode(in_RequestId);
SOAPElement element2 = soapElement.addChildElement(“fileType”, “typ”);
element2.addTextNode(in_FileType);
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader(“SOAPAction”, in_SoapAction);
headers.addHeader(“Authorization”, “Basic “+Auth);
soapMessage.saveChanges();

SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();

SOAPMessage soapResponse = soapConnection.call(soapMessage, endpoint);

TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source sourceContent = soapResponse.getSOAPPart().getContent();

Iterator attachments = soapResponse.getAttachments();

//System.out.println(“\n———-SOAP Response———–“);
//StreamResult result = new StreamResult(System.out);
StringWriter sw = new StringWriter();
//transformer.transform(sourceContent, result);
transformer.transform(sourceContent, new StreamResult(sw));

soapConnection.close();

String SoapXML=sw.toString();
System.out.println(“\n———-SOAP Response———–“+SoapXML);
out_SOAP_Response=SoapXML;
String filename;
if(SoapXML.contains(in_Filename_Element))
{
filename = SoapXML.substring(SoapXML.indexOf(in_Filename_Element+”>”) );
filename=filename.substring(filename.indexOf(“>”)+1,filename.indexOf(“</”) );
System.out.println(“\n———-Filename———–“+filename);

while (attachments.hasNext()) {
AttachmentPart att = (AttachmentPart)attachments.next();

InputStream is = att.getDataHandler().getInputStream();
FileOutputStream os = new FileOutputStream(in_File_Path +filename);
out_file_path=in_File_Path +filename;
byte[] buff = new byte[16 * 1024 * 1024];
int read = 0;
while ((read = is.read(buff, 0, buff.length)) != -1) {
os.write(buff, 0, read);
}
os.flush();
os.close();

}
message=”success”;
}
else
{
message=”Element “+in_Filename_Element+ ” Not found in XML”;
}
}
catch (Exception e) {
message=e.getMessage();
StackTraceElement[] stack = e.getStackTrace();
String exception = “”;
for (StackTraceElement s : stack) {
exception = exception + s.toString() + “\n\t\t”;
}
out_Stack_Trace=exception;
}