cancel
Showing results for 
Search instead for 
Did you mean: 

Adding attachment from PI level

former_member209575
Contributor
0 Kudos

Hi all,

I am trying to add some attachment to payload using JAVA Mapping.

*********************************************************************

public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException

{

try{

System.out.println("JAVA Mapping is Initiated");

//getTrace().addInfo("JAVA Mapping HMAC is Initiated");

InputStream stream1 = arg0.getInputPayload().getInputStream();

String inputPayload = convertInputStreamToString(stream1);

System.out.println("input file "+inputPayload);

String outputPayload = "";

outputPayload = inputPayload;

byte[] b = inputPayload.getBytes();

System.out.println("JAVA Mapping "+b.length);

try{

*OutputAttachments outputAttachments = arg1.getOutputAttachments();

Attachment attachments = outputAttachments.create("sd", b); *

outputAttachments.setAttachment(attachments);

} catch (Exception e)

{//getTrace().addInfo("JAVA Mapping Trace "+e);

System.out.println("test "+e);}

arg1.getOutputPayload().getOutputStream().write(outputPayload.getBytes("UTF-8"));

} catch (Exception e)

{System.out.println(e.getStackTrace());}

}

**********************************************************************************************************

I am getting null pointer exception from below line

*Attachment attachments = outputAttachments.create("sd", b); *

feels like

outputAttachments = arg1.getOutputAttachments(); is returning null.

Please help me in solving same

Regards

Pradeep

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Pradeep,

Ref: /people/stefan.grube/blog/2007/04/17/xi-mail-adapter-an-approach-for-sending-emails-with-attachment-with-help-of-java-mapping - An approach for sending emails with attachment with help of Java mapping

Thanks,

former_member209575
Contributor
0 Kudos

Hi Hareen,

My requirement is to send attachment to a proxy scenario from java mapping

Regards

Pradeep P N

Answers (2)

Answers (2)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Pradeep,

Please check this link.. solution using simple udf

Hope that helps

stefan_grube
Active Contributor
0 Kudos

Have you checked "read attachments" in operation mappings?

Former Member
0 Kudos

Hi,

Please check the below mentioned link

http://wiki.sdn.sap.com/wiki/display/XI/SampleJAVAMappingcodeusingPI7.1+API

Thanks

Suma

former_member209575
Contributor
0 Kudos

Hi Stefan,

I tried with read attachment option also.

Here message is coming from R3 system as payload. I need to take some 5 fields and put it as attachment along with payload and need to send to other PI system.

Regards

Pradeep P N

Former Member
0 Kudos

Have you tried working with the addAttachment() method of the Message interface (http://help.sap.com/javadocs/pi/SP3/xpi/com/sap/engine/interfaces/messaging/api/Message.html#addAttachment%28com.sap.engine.interfaces.messaging.api.Payload%29) ... It may require some (major) redesign of your JAVA mapping (I'm still on XI, so I can't validate this assumption)

Chris