Skip to Content
0
Former Member
Jan 28, 2013 at 05:57 AM

PI 7.31 Extra Byte in Java Mapping in HTTP with attachments to FTP scenario

149 Views

Hi Gurus,

I have a HTTP with attachments(jpg files) to FTP scenario in SAP PI 7.31 environment.

I use a Java mapping to get an attachment incoming http request message(adapter type HTTP_AAE) and put this attachment as binary file type in binary transfer mode. Scenario works fine except one thing: in ftp server I receive a file with some extra bytes 0D. You can see an example.

I think it is a problem with usage of method attachments.getContent(). Please, help to solve this question.

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Java_Test;


import java.io.*;
import java.util.*;
import com.sap.aii.mapping.api.*;

public class Java_For_SCN extends AbstractTransformation {

private Map param;
TransformationInput transformationInput = null;
InputAttachments inputAttachments = null;
InputStream in = null;

public Java_For_SCN() {
}

public void setParameter(Map map) {
param = map;
if (param == null) {
param = new HashMap();
}
}


public void transform(TransformationInput tranIn, TransformationOutput tranOut) throws StreamTransformationException {
transformationInput = tranIn;
//GET INPUT ATTACHEMENTS OBJECT
inputAttachments = tranIn.getInputAttachments();
this.execute((InputStream) tranIn.getInputPayload().getInputStream(), (OutputStream) tranOut.getOutputPayload().getOutputStream());
}

public void execute(InputStream inputstream, OutputStream outputstream) {
try {
if (transformationInput != null)
{
if (inputAttachments != null)
{
//Important: First Enable the "Read Attachments" check box in Operation mapping if your code needs to handle attachments.
if (inputAttachments.areAttachmentsAvailable())
{
String AttachmentID = "";
Collection<String> CollectionIDs = inputAttachments.getAllContentIds(true);
Object[] arrayObj = CollectionIDs.toArray();
int attachmentCount = arrayObj.length;
this.getTrace().addInfo("attachmentCount = " + Integer.toString(attachmentCount));

if ( attachmentCount >=1 ) {
attachmentCount = 1; // temporary
}

for (int i = 0; i < attachmentCount; i++) {

this.getTrace().addInfo("i = " + Integer.toString(i) );
AttachmentID = (String) arrayObj[i];
this.getTrace().addInfo("AttachemntID = " + AttachmentID);
Attachment attachments = inputAttachments.getAttachment(AttachmentID);
this.getTrace().addInfo("Attachment ContentType = " + attachments.getContentType());
outputstream.write(attachments.getContent());
}
}
}
}
} catch (Exception e2) {
e2.printStackTrace();
this.getTrace().addDebugMessage(e2.toString());
}

}
}

Attachments

BadPayload.jpg (200.6 kB)
GoodPayload.jpg (200.0 kB)