on 03-14-2016 9:24 PM
Hi Gurus
We have a synchronous interface which is transferring a field on the SOAP request which has the files in base64binary format.
I would like to know - how we can convert these to SOAP attachments to the receiver system.
Can we do this using a UDF / Java mapping - wat are the parameters we need to configure.
Scenario:
Request message :
Response message :
How can we convert the field which is carrying the base64binary characters in to a SOAP attachments and pass it on the SOAP request to the reciver system in the above scenario - can this be achieved just by a UDF - or do we need addl. configuration at the SOAP adapter as well ?!
Your help is greatly appreciated!!
Thanks,
Ritu
Hi Ritu,
You can achieved this by UDF. Please find the below UDF code for the same.
String response=""; |
String decodedContent="";
byte[] decodedValue = DatatypeConverter.parseBase64Binary(Content);
decodedContent=new String(decodedValue);
return decodedContent;
Add the library as well: javax.xml.bind.DatatypeConverter
Regards,
Bhavin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ritu,
Addition to the above Bhavin's code once the input filed is decrypted to make this as soap attachment use below code :
GlobalContainer globalContainer = container.getGlobalContainer();
byte[]convertedInput=decodedConten.getBytes();
OutputAttachments outputAttachments = globalContainer.getOutputAttachments();
Attachment outputAttachment;
String contentType="application/xml"; ( " this depends on your content type i.e file type for ex: if you want it as a xml attachment then application/xml , for plain text it is text/plain)
outputAttachment = outputAttachments.create("Myfile.xml",contentType,convertedInput);
outputAttachments.setAttachment(outputAttachment);
Br,
Manoj
Thank you for your inputs!! Manoj
I am able to get the attachment using the code as below - however, can you help me how me how I can update the code so that:
ContentType: "application/octet-stream" (this is fine)
BUT:
Type: "XOP" --> How can I set this in the below code?!
As the receiving system is still throwing error as below in a valid SOAP response in the Error detail section on the WSDL:
javax.activation.DataHandler cannot be cast to com.sun.xml.ws.developer.StreamingDataHandler
Is there anything I need to send in the Header and if so how do we need to send it ?!
Is there anything additional we need to do make it a MTOM attachment?!
Thank you so much for your valuable inputs!!
Thank you,
Ritu
GlobalContainer globalContainer = container.getGlobalContainer();
byte[] convertedInput = var1.getBytes();
OutputAttachments outputAttachments = globalContainer.getOutputAttachments();
Attachment outputAttachment;
String contentType= "application/octet-stream";
outputAttachment = outputAttachments.create("Myfile.xml", contentType, convertedInput);
outputAttachments.setAttachment(outputAttachment);
return "1";
Thanks!! Bharvin
Can you please help with the below posted query on how can we ADD:
GlobalContainer globalContainer = container.getGlobalContainer();
byte[] convertedInput = var1.getBytes();
OutputAttachments outputAttachments = globalContainer.getOutputAttachments();
Attachment outputAttachment;
String contentType= "application/octet-stream";
outputAttachment = outputAttachments.create("Myfile.xml", contentType, convertedInput);
outputAttachments.setAttachment(outputAttachment);
return "1";
Is there anything additional we need to do make it a MTOM attachment?!
Your help is greatly appreciated!!
Thank you,
Ritu
I have included a XSLT mapping in the operation mapping:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:stylesheet version="1.0" xmlns:ns0="http://www.w3.org/1999/XSL/Transform" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:ns2="xsl">
<ns0:template match="node() | @*">
<ns0:copy>
<ns0:apply-templates select="node() | @*"/>
</ns0:copy>
</ns0:template>
<ns0:template match="xop:Include"/>
</ns0:stylesheet>
Hi Ritu,
you can set type "XOP" as content type using below code:
String contentType= "application/xop+xml
";
Reference http://stackoverflow.com/questions/18150004/how-to-parse-xop-mtom-soap-response-using-java
In above code you did not perform any conversion.
First you need to convert input into binary.
You can try with below code.
GlobalContainer globalContainer = container.getGlobalContainer();
String decodedContent="";
byte[] decodedValue = DatatypeConverter.parseBase64Binary(Content);
decodedContent=new String(decodedValue);
byte[] convertedInput = decodedContent.getBytes();
OutputAttachments outputAttachments = globalContainer.getOutputAttachments();
Attachment outputAttachment;
String contentType= "application/xop+xml";
outputAttachment = outputAttachments.create("Myfile.xml", contentType, convertedInput);
outputAttachments.setAttachment(outputAttachment);
return "1";
Regards,
Bhavin
Thank you for your quick response!! Bhavin
Can you please let me know - if the attachment created using the above code - will this be a MTOM attachment ?!
Also, can I change the above code not to return "1"
Can you hep with the below error ?!
cannot find symbol symbol : variable DatatypeConverter location: class com.sap.xi.tf._MM_PLM_ATTACH_Request_ byte[] decodedValue = DatatypeConverter.parseBase64Binary(var1); ^ Note: /usr/sap/PID7/DVEMBGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map6bc3d8f9fba111e59d6000000032623e/source/com/sap/xi/tf/__MM_PLM_ATTACH_Request_.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error
Hi Bhavin
Library imported issue resolved!!
However, I am unsure of the content type and also the file name.
The file can be a txt or a PDF - can we zip it before sending it - so that we can stick with Myfile.zip instead of MyFile.xml ?!
Also, does the above UDF created attachment is an MTOM attachment ?!
We have been told so far that - the message has to have the below format for attachments:
"application/octet-stream" & "XOP"
Hence content type: "XOP" should be "application/octet-stream" so
Thank you,
Ritu
Hello!! Bhavin, All
Would you know how to cast attachment to MTOM: XOP Include - the below UDF is creating the attachment.
so that the final output come as below:
-<ns7:AttachmentDataHandler> (one of the fields on the XML message)
<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:cccb625678-ba29-412b-984a-78927caab5ea@example.jaxws.sun.com"/>
</ns7:AttachmentDataHandler>
so the below UDF - I am hoping can be updated to have the XOP Include to the AttachmentDataHandler Field ?! - Is this posssible using UDF - please advice!!
Your help is greatly appreciated!!
Thank you,
Ritu
GlobalContainer globalContainer = container.getGlobalContainer();
String decodedContent="";
byte[] decodedValue = DatatypeConverter.parseBase64Binary(Content);
decodedContent=new String(decodedValue);
byte[] convertedInput = decodedContent.getBytes();
OutputAttachments outputAttachments = globalContainer.getOutputAttachments();
Attachment outputAttachment;
String contentType= "application/octet-stream";
outputAttachment = outputAttachments.create("Myfile.xml", contentType, convertedInput);
outputAttachments.setAttachment(outputAttachment);
return "1";
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.