Skip to Content
avatar image
Former Member

zip multiple text files

Hello,

My requirement is to zip multiple text files and zip file should have same name as input file.I have gone through many blogs and have tried implmenting different solutions like payloadzipbean, custom adapter module and OS command, but i did not manage to achieve the result. Could you please help.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

7 Answers

  • avatar image
    Former Member
    Oct 18, 2016 at 07:49 AM

    Hello Praveen,

    Thanks for your reply.

    I have done exactly same. Only difference is i have changed the content type (hardcoded values like .txt and .zip) in adapter module code and then zip the file using zipoutputstream. However then it only zip the single file. My requirement is to zip multiple text files.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Mandar,

      Can you explain your requirement clearly.

      • Do you need to pick up all files from source directory as single XI message?
      • Do you need to zip all the files into one zip file? if yes you have multiple files what will be the zip file name??

      Regards,

      Praveen.

  • avatar image
    Former Member
    Oct 20, 2016 at 08:04 AM

    Hello Praveen,

    Indeed, I need to zip all files into one zip file. For example,

    file names are:

    000123_ABC.txt

    000123_ABCXYZ.txt

    Zip file name: 000123_ABC.zip. However getting the correct zip filename is not an issue for me, as i am able to achive it through DynamicConfiguration Class and then using substring function to retrive the required filename in adapter module code.

    Also, I have seen content of both files into XI message payload in message monitoring. Still after execution of adapter module, zip file on target directory has only first file.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 28, 2016 at 11:27 AM

    Hello Evgeniy,

    Thanks for the reply.

    I have tried that already. But it is zipping only one file and not all.

    Regards,

    Mandar

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 28, 2016 at 08:15 PM

    Hi Mandar!

    Do you set your files besides the first one as additional files?

    You should have the first file as main payload and the rest ones as attachments.

    Regards, Evgeniy.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 29, 2016 at 06:15 PM

    Hello Evgeniy,

    Yes, i have marked my other files under additional files. I think both files are main payload, as message payload has content of both files.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Can you provide screen shot of your sender channel and message monitoring screen shot which shows payloads.

  • avatar image
    Former Member
    Oct 31, 2016 at 02:35 PM

    Hi Mandar,

    If you configure the sender file channel with additional file option.

    Configure receiver channel like below.

    Use below java mapping to change the extension from .txt to .zip.

    import org.apache.commons.io.IOUtils;
    import com.sap.aii.mapping.api.AbstractTransformation;
    import com.sap.aii.mapping.api.DynamicConfiguration;
    import com.sap.aii.mapping.api.DynamicConfigurationKey;
    import com.sap.aii.mapping.api.StreamTransformationException;
    import com.sap.aii.mapping.api.TransformationInput;
    import com.sap.aii.mapping.api.TransformationOutput;
    public class DynamicFileNameJavaMap extends AbstractTransformation {
    	@Override
    	public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)
    			throws StreamTransformationException {
    		try {
    			DynamicConfiguration dynConfig = transformationInput.getDynamicConfiguration();
    			DynamicConfigurationKey FILE_NAME = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
    			dynConfig.put(FILE_NAME, dynConfig.get(FILE_NAME).replace(".txt", ".zip"));
    			IOUtils.copy(transformationInput.getInputPayload().getInputStream(), transformationOutput.getOutputPayload()
    					.getOutputStream());
    		} catch (Exception e) {
    			throw new StreamTransformationException(e.getMessage());
    		}
    	}
    }
    

    Regards,

    Praveen.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 03, 2016 at 01:45 PM

    Hello Praveen,

    Sorry for late reply. Before trying out your solution, could you please first look at sender and receiver file channel configuration.

    Also i am using dummy SIs and namespace for ICO, no ESR objects created.

    Add comment
    10|10000 characters needed characters exceeded