cancel
Showing results for 
Search instead for 
Did you mean: 

Converting attachment to hexadecimal code in sap CPI

manemahesh
Participant
0 Kudos

Hi All,

I have requirement where ARIBA is sending xml payload along with pdf attachment to CPI. Requirement is to convert this attachment to Hexcode and send in some target field of MDG webservice along with other fields which are coming from ARIBA.

How can we achieve this in SAP CPI.

Note:- ARIBA sending this attachment over HTTP call and on Receiver MDG side we are connecting MDG webservice over SOAP call.

MortenWittrock
Active Contributor
0 Kudos

Hi Mahesh

Do you by any chance mean Base64? That's a fairly common way to move binary stuff around as text.

Regards,

Morten

manemahesh
Participant
0 Kudos

Hi Morten,

Yes this attachment has to be converted to Base64 and then this base64 converted string has to be passed in target field on MDG side.Pls help.

Regards

Mahesh Mane

MortenWittrock
Active Contributor
0 Kudos

So how did it work out? Please remember to follow up on your questions and accept correct answers. It's only fair to the community members who spent their time helping you out.

Regards,

Morten

Accepted Solutions (0)

Answers (1)

Answers (1)

MortenWittrock
Active Contributor
0 Kudos

Hi Mahesh

I've blogged about how to access attachments here. Here's some quick and dirty code that reads the attachment, Base64 encodes it and stores the result in a property:

import com.sap.gateway.ip.core.customdev.util.Message
import javax.activation.DataHandler

def Message processData(Message message) {
// Note: The next line assumes that there is exactly one attachment.
DataHandler attachment = message.getAttachments().values().iterator().next()
// Read the binary content of the attachment into memory. Don't do this for huge attachments!
byte[] content = attachment.getInputStream().getBytes()
// Base64 encode the binary content.
String base64 = content.encodeBase64().toString()
// Store the Base64 in a property.
message.setProperty('EncodedAttachment', base64)
// All done.
return message
}

You can then access the Base64 value through the property afterwards.

Regards,

Morten