0% found this document useful (0 votes)
168 views

How To Add Attachment Using JAVA Mapping

How to implement a java mapping in PI

Uploaded by

mvrooyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
168 views

How To Add Attachment Using JAVA Mapping

How to implement a java mapping in PI

Uploaded by

mvrooyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

How to add attachment using JAVA Mapping (SAP PO) | SAP Blogs https://blogs.sap.com/2015/05/16/how-to-add-attachment-using-java-ma...

Home / Community / Blogs

How to add attachment using JAVA Mapping


(SAP PO)
May 16, 2015 | 666 Views |

Ashutosh Upadhyay
more by this author

SAP Cloud Platform Integration for process services

share
0 share
0 tweet share
0

Follow

Share & Follow


Privacy Terms of Use Legal Disclosure Copyright Trademark Sitemap Newsletter

1 of 4 2017/10/10, 12:06 PM
How to add attachment using JAVA Mapping (SAP PO) | SAP Blogs https://blogs.sap.com/2015/05/16/how-to-add-attachment-using-java-ma...

Hi,

I was having a requirement to pick a PDF file from a file server, send it
as attachment and PDF file name as field to the target server.

As a solution I created a JAVA code and used it as JAVA mapping in PI.


I hope this code will help PI consultants if they have similar kind of
requirement.

/*

* Created on May 14, 2015

* To change the template for this generated file go to

* Window>Preferences>Java>Code Generation>Code and


Comments

*/

package attach;

/**

* @author ashutosh upadhyay

* To change the template for this generated type comment go to

* Window>Preferences>Java>Code Generation>Code and


Comments

*/

import java.io.InputStream;

import java.io.OutputStream;

import com.sap.aii.mapping.api.AbstractTransformation;

import com.sap.aii.mapping.api.Attachment;

import com.sap.aii.mapping.api.DynamicConfigurationKey;

2 of 4 2017/10/10, 12:06 PM
How to add attachment using JAVA Mapping (SAP PO) | SAP Blogs https://blogs.sap.com/2015/05/16/how-to-add-attachment-using-java-ma...

2 Comments
You must be Logged on to comment or reply to a post.

String fresult= ;

// creating the xml

fresult=<?xml version=\1.0\ encoding=\UTF-8\?>;

3 of 4 2017/10/10, 12:06 PM
How to add attachment using JAVA Mapping (SAP PO) | SAP Blogs https://blogs.sap.com/2015/05/16/how-to-add-attachment-using-java-ma...

fresult = fresult.concat(<ns0:MT_Payload xmlns:ns0=\http://test\>);

fresult = fresult.concat(<FileName>);

fresult = fresult.concat(fileName);

fresult = fresult.concat(</FileName>);

fresult = fresult.concat(</ns0:MT_Payload>);

outputstream.write(fresult.getBytes(UTF-8));

// Write attachment

OutputAttachments outputAttachments =
transformationOutput.getOutputAttachments();

byte[] b = new byte[inputstream.available()];

inputstream.read(b);

Attachment newAttachment =
outputAttachments.create(fileName,application/pdf, b);

outputAttachments.setAttachment(newAttachment);

catch (Exception e) {

getTrace().addDebugMessage(e.getMessage());

Output:

Alert Moderator

4 of 4 2017/10/10, 12:06 PM

You might also like