on 10-17-2016 3:13 PM
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Evgeniy,
Thanks for the reply.
I have tried that already. But it is zipping only one file and not all.
Regards,
Mandar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
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.