cancel
Showing results for 
Search instead for 
Did you mean: 

SFTP to Proxy with attachment with combined zip.

manoj_khavatkopp
Active Contributor
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

RaghuVamseedhar
Active Contributor
0 Kudos

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());

        }

    }

}

manoj_khavatkopp
Active Contributor
0 Kudos

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 !

RaghuVamseedhar
Active Contributor
0 Kudos

Manoj,

AFAIK, it is not possible using standard modules. Custom module is resource/effort intensive than Java Mapping.

Answers (1)

Answers (1)

RaghuVamseedhar
Active Contributor
0 Kudos

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.