First thing to check is that your service (a MPGW I assume) is set to Request data: JSON
and not XML
.
If JSON
as request data isn't working either try with non-XML
.
DataPower runs different parsers/validators depending on the content data type but as long as the JSON itself is valid JSON
should work, else open a PMR!
If you still can't figure it out test that the incoming data is detected as UTF-8 and not as Latin1. Add a GWS action and feed the INPUT to it and try something like:
// This is where we start, grab the INPUT as a buffer
session.input.readAsBuffers(function(readAsBuffersError, data) {
if (readAsBuffersError) {
console.error('Error on readAsBuffers:', readAsBuffersError);
} else {
let content = data.toString();
if (content.length === 0) {
console.error('Empty message found for Request message!');
} else {
try {
// This seems like an overkill solution but we need to know if data fetched is UTF-8 or Latin1
// If Latin1 we need to wobble it around to not wreck "double-bytes", e.g. Å, Ä or Ö
const util = require('util');
const td = new util.TextDecoder('utf8', { fatal: true });
td.decode(Buffer.from(content));
console.log('Buffer data is UTF-8!');
} catch (err) {
// It is not UTF-8, since it failed so we'll assume it is Latin1. If not it will throw it's own Buffer error or transformation will fail...
if (err.message === 'The encoded data was not valid for encoding utf-8') {
const l1Buffer = Buffer.from(content, 'latin1');
const l1String = l1Buffer.toString('latin1');
content = Buffer.from(l1String, 'utf8');
console.log('Buffer data was Latin1, now converted into UTF-8 successfully!');
}
}
session.output.write(content);
}
}
});