on 09-04-2015 7:38 PM
Hello experts,
We have SFTP--->Proxy with attachment .
We have XML file which is being placed in SFTP server now we have to zip the XML file and send it as an attachment to proxy with the same name.
We have made javampping which will convert the XMl file to proxy attachment .
Please let me know the Payload zipbean parameters which i need to keep on sender SFTP adapter to zip the XMl file with the same name.
Below is the javmapping to convert xml to proxy attachment.
try{
GlobalContainer globalContainer = container.getGlobalContainer();
MappingTrace trace=container.getTrace();
byte[]convertedInput=input.getBytes("UTF-8");
OutputAttachments outputAttachments = globalContainer.getOutputAttachments();
Attachment outputAttachment;
String contentType="application/xml";//<could be changed>
DynamicConfiguration conf = ( (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key =DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
String fileName = (conf.get(key));
trace.addInfo("filename used for attachment "+ fileName);
outputAttachment = outputAttachments.create(fileName,contentType,convertedInput);
outputAttachments.setAttachment(outputAttachment);
}
catch(UnsupportedEncodingException e) {
e.printStackTrace();
throw new StreamTransformationException(e.getMessage());
}
return "";
Now can you please let me know what madification has to be done in abve javamapping to take input as zip file and create it as an proxy attachment with the same name.
Manoj,
You can try this Java Mapping, pick the file with no modules, set Adapter-Specific Message Attributes. FYI, I have not tested this code.
package javaapplication1;
import com.sap.aii.mapping.api.*;
import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class Test extends AbstractTransformation {
@Override
public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {
try {
InputStream inputstream = transformationInput.getInputPayload().getInputStream();
OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();
// Get File Name.
java.util.Map mapParameters = transformationInput.getInputHeader().getAll();
DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
String FileName = conf.get(key);
//Read input content into byte arrary.
byte[] b = new byte[inputstream.available()];
inputstream.read(b);
//Zip payload.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
zos.putNextEntry(new ZipEntry(FileName));
zos.write(b);
zos.closeEntry();
zos.close();
//Make zipped payload as attachment.
Attachment newopAttachment = transformationOutput.getOutputAttachments().create(FileName + ".zip", baos.toByteArray());
transformationOutput.getOutputAttachments().setAttachment(newopAttachment);
//Write some XML or text as payload for proxy.
outputstream.write("<xml>XML payload to proxy</xml>".getBytes());
} catch (Exception exception) {
getTrace().addDebugMessage(exception.getMessage());
throw new StreamTransformationException(exception.toString());
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Raghu,
I am able to zip the file through zipbean and send it to proxy as attachment with javamapping.
But however one problem is when i zip a file for ex : abc.xml and sent it to proxy as attachment ..they are receiving file as abc.zip but inside that the zipfile i getting renamed to untitled.bin
I tried using MTB bean for this and gave static name as abc.xml in modulefor content type then they were receiving inside zip file as abc.xml ...but as this name cant be constant is their any way this name can be handled dynamically.
Few blogs tell zip-bean with dynamic bean can be possible only by custom module !
Manoj,
Adding PayloadZipBean in the Module Processor try zip.filenameKey payloadName.
If above parameter does not work, pick the file and handle everything in Java Mapping.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.