on ‎2018 Apr 12 3:47 PM
Hi Experts,
We have requirement to transform the input & output payload as shown below screen shot where it should parse payload and " < " should be replaced with < & " #62 "should be replaced with " > " .

If you observe the whole xml payload contains ServiceOrder string with set of characters should be replaced with < infront & > after that string.
Please suggest Java or XSLT mapping suits this requirement.
Thanks.
Ramu.
Request clarification before answering.
Hi Ramu!
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("<", "<").replaceAll(">", ">");
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();
}
}
Editor changes the representation of symbols, so, you should use your source values for "<" and ">" as the first argument in both replaceAll() methods.
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 Evgeniy,
Regarding this line payloadString = payloadString.replaceAll("<", "<").replaceAll(">", ">");
should it corrected to achieve my requirement to replace < with "<" and to replace > with ">" .
payloadString = payloadString.replaceAll("<", "<") ;
payloadString = payloadString.replaceAll(">", ">") ;
Thanks,
Ramu.
Hi Ramu!
I would read payload into string using java mapping and simply call replaceAll() method.
Regards, Evgeniy.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would try with XSLT first.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 9 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.