首先要检查的是您的服务(我假设是 MPGW)设置为Request data: JSON
and not XML
。如果JSON
作为请求数据不起作用,请尝试使用non-XML
. DataPower 根据内容数据类型运行不同的解析器/验证器,但只要 JSON 本身有效就JSON
可以工作,否则打开 PMR!
如果您仍然无法弄清楚,请测试传入的数据是否被检测为 UTF-8 而不是 Latin1。添加一个 GWS 操作并向其提供 INPUT 并尝试以下操作:
// 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);
}
}
});