on 2021 Oct 22 7:59 AM
Hi.
I need help in modifying below Java mapping code.
Request(payload) ->REST Lookupservice->Response(payload)->Combine request & response payload - > Receiver
Using rest lookup service, getting the response payload.
Requirement is to combine Request payload and response payload from rest lookup.
I need the combined payload to further process it for the subsequent call. I'm a bit of struggler with Java.
Kindly help in code to achieve the combined payload result.
package Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
import com.sap.aii.mapping.lookup.Channel;
import com.sap.aii.mapping.lookup.LookupService;
import com.sap.aii.mapping.lookup.Payload;
import com.sap.aii.mapping.lookup.SystemAccessor;
public class Test extends AbstractTransformation {
public void transform(TransformationInput in, TransformationOutput out)
throws StreamTransformationException {
Channel channel = LookupService.getChannel("BC_Info","CC_REST_REC_Test");
Payload payload = LookupService.getXmlPayload(in.getInputPayload().getInputStream());
SystemAccessor accessor = LookupService.getSystemAccessor(channel);
Payload resp1 = accessor.call(payload);
try{
String respayloadstring= covertInputStringStreamToString(resp1.getContent());
out.getOutputPayload().getOutputStream().write(respayloadstring.getBytes());
}catch (IOException e)
{
e.printStackTrace();
}
}
private static String covertInputStringStreamToString(InputStream inputstream) throws IOException{
ByteArrayOutputStream result=new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while((length=inputstream.read(buffer)) !=-1){
result.write(buffer, 0, length);
}
return result.toString(StandardCharsets.UTF_8.name());
}
}
Request clarification before answering.
User | Count |
---|---|
70 | |
21 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.