Skip to Content
0
Aug 07, 2020 at 11:14 AM

Unable to post files to HTTP Receiver using Groovy Script in SAP CPI Returning HTTP Status code 500

469 Views Last edit Aug 07, 2020 at 11:21 AM 4 rev

receiveradapter.png

monitoring.png

Hi Experts,

I am unable to post files other than text using message.setBody() in Groovy script.I am reading attachments from SOAP UI using groovy script getAttachments() method. I am unable to post content in setBody method for files other than text(png,pdf etc..)

Please find code here.

Map<String, DataHandler> attachments = message.getAttachments()

Iterator<DataHandler> it = attachments.values().iterator()

Iterator<String> it1 = attachments.keySet().iterator()

List<String> aList = new ArrayList<String>();

for (String x : attachments.keySet())

{

aList.add(x);

}

def bads=new ByteArrayDataSource(attachments.get(aList.get(0)).getInputStream().getBytes(),'image/png')

DataHandler dh = new DataHandler(bads)

message.setBody(dh.getInputStream().getBytes())

message.setHeader("fName",attachments.get(aList.get(0)).getName())

return message

HTTP Receiver Adapter

Error in Monitoring

Regards,

Sachin Belide

Attachments

monitoring.png (48.5 kB)