on 04-25-2018 8:27 AM
Hi Experts,
In PO , for IDOC mappings we need to pass "1" for Segment , begin and IDOC. I just need to do pass through the Java mapping , only change required is segment and IDOC with 1. I know we can do one to one mapping, but we have jumbled segments with mapping. So tried the java mapping like below but not working. Can some help here.
import java.io.*;
import com.sap.aii.mapping.api.*;
public class WellformedXML_JavaMapping extends AbstractTransformation {
@Override
public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {
try {
InputStream inputstream = transformationInput.getInputPayload().getInputStream();
OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();
byte[] b = new byte[inputstream.available()];
inputstream.read(b);
String inputContent = new String(b);
inputContent = inputContent.replaceAll("SEGMENT", "SEGMENT='1'");
outputstream.write(inputContent.getBytes());
} catch (Exception exception) {
getTrace().addDebugMessage(exception.getMessage());
throw new StreamTransformationException(exception.toString());
}
}
}
Regards,
Ram.
Hi Evgeniy,
Thankyou very much , working.
Regards,
Vijay.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vijay!
And what exactly doesn't work?
Regards, Evgeniy.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vijay!
It's hard to say what's wrong with your code at first sight. Here is my class doing the same:
public class StringReplacer extends AbstractTransformation {
@Override
public void transform(TransformationInput in, TransformationOutput out)throws StreamTransformationException {
executeMapping(in.getInputPayload().getInputStream(), out.getOutputPayload().getOutputStream());
}
public void executeMapping(InputStream is, OutputStream os) throws StreamTransformationException {
try {
byte[] payloadBytes = getByteArrayFromInputStream(is);
String payloadString = new String(payloadBytes, "UTF-8");
payloadString = payloadString.replaceAll("SEGMENT", "SEGMENT=\"1\"");
os.write(payloadString.getBytes("UTF-8"));
}
catch (Exception e) {
throw new StreamTransformationException(e.getMessage());
}
}
public byte[] getByteArrayFromInputStream(InputStream is) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = is.read(data, 0, data.length)) != -1)
buffer.write(data, 0, nRead);
buffer.flush();
is.close();
return buffer.toByteArray();
}
}
It works as expected.
Regards, Evgeniy.
User | Count |
---|---|
81 | |
24 | |
11 | |
9 | |
7 | |
5 | |
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.