Custom module to add byte order mark (BOM) characters to output file:

package com.test;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import javax.ejb.Stateless;
import com.sap.aii.af.lib.mp.module.ModuleContext;
import com.sap.aii.af.lib.mp.module.ModuleData;
import com.sap.aii.af.lib.mp.module.ModuleException;
import com.sap.engine.interfaces.messaging.api.Message;
import com.sap.engine.interfaces.messaging.api.Payload;
@Stateless
public class PayloadAddBOMBean implements PayloadAddBOMBeanRemote, PayloadAddBOMBeanLocal {
	public PayloadAddBOMBean() {
	}
	public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData)throws ModuleException{
		try
		{
			Object obj = inputModuleData.getPrincipalData();
			Message msg = (Message)obj;
			Payload payload = msg.getDocument();
			InputStream inputStream = (InputStream)payload.getInputStream();
			byte[] inputBytes = new byte[inputStream.available()];
			inputStream.read(inputBytes);
			ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
			outputStream.write(0xEF);
			outputStream.write(0xBB);
			outputStream.write(0xBF);
			outputStream.write(inputBytes);
			byte[] outputBytes = outputStream.toByteArray();
			payload.setContent(outputBytes);
			inputModuleData.setPrincipalData(msg);
			return inputModuleData;
		}
		catch (Exception excep)
	    {
			 ModuleException modulExcep = new ModuleException( excep.getMessage());
			 throw modulExcep;
	    }
	}
}
SAP PI Custom Module PayloadAddBOMBean Development
Tagged on:     

Leave a Reply

Your email address will not be published.