cancel
Showing results for 
Search instead for 
Did you mean: 

Converting StringValue (base64binary) in SOAP request to SOAP attachment to receiver

Former Member
0 Kudos

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  :

  • External vendor (SOAP XML with Attachment)<<-----PI(Need to convert 1 field base64binary field to SOAP Attachment)<<----Internal 3rd party application (SOAP XML Payload with 1 field having base64binaryfomatfile)


Response message :

  • External vendor    ---------------------------------------->>(only Data)---------------PI----------------------->>(Only Data)---Internal 3rd party application .

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

manoj_khavatkopp
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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";

Former Member
0 Kudos

Thanks!! Bharvin

Can you please help with the below posted query on how can we ADD:

  • Type: "XOP" --> How can I set this in the below code?! - please see XSLT mapping which is being used - I do see the attachment in MONI after adding it.
  • Also, the below code is not converting to base64binary - can yo please help modify it ?!

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>

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Ritu,

1)You can change the function return type as void.

2) for below Error:

          cannot find symbol symbol  : variable DatatypeConverte


can you please confrim have imported  library :javax.xml.bind.DatatypeConverter



Regards,

Bhavin

Former Member
0 Kudos

HI Bhavin

Where and how can I import this library ?!

sorry I havent done this before ...

Thank you,

Ritu

Former Member
0 Kudos

HI Ritu,

You can import library as per below screenshot.

Former Member
0 Kudos

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

Former Member
0 Kudos

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";

Former Member
0 Kudos

Hi Bhavin, All

The message was originally opened with the query on converting base64binary - which has been resolved

However, I have another issue related to the same object - which I think will address on a different thread - closing this thread.

Thank you ALL!!

Thanks,

Ritu

Answers (1)

Answers (1)

Harish
Active Contributor
0 Kudos

Hi Ritu,

Please check the blog from Eng Swee

regards,

Harish