StreamTransformation
.
public class JavaMapping extends AbstractTransformation {
public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException{
try{
getTrace().addInfo("Trace : Entering Java Mapping");
String receiverName = (String) in.getInputHeader().getReceiverInterface();
// Read Import Parameter for Parameterized mapping/Channel ID for LookupService- SystemAccessor
String inputParameter = (String) in.getInputParametrs().getString("parInputParam");
Channel lookupChannel = (String) in.getInputParametrs().getChannel("parLookupChannel");
//Read the Source Payload as InputStream
InputStream ins = in.getInputPayload().getInputStream();
String sourcexml = convertInputStreamToString(ins)
// Write the Target String as byte with OutputStream
String targetxml = "OUTPUTDATA";
out.getOutputPayload().getOutputStream().write(targetxml.getBytes());
}
catch (Exception e) { throw new StreamTransformationException(e.getMessage()); }
}
}
public String convertInputStreamToString(InputStream ins) {
StringBuffer sourcexml = new StringBuffer();
BufferedReader br = new BufferedReader( new InputStreamReader(ins));
while ((line = br.readLine()) != null) sourcexml.append(line); br.close();
return sourcexml.toString();
}
Reference: