ibm-messaging / mq-mqi-nodejs

Calling IBM MQ from Node.js - a JavaScript MQI wrapper
Apache License 2.0
79 stars 42 forks source link

can't send MQRFH2 because rfh2.getBuffer() fails and also ignores original values #125

Closed underoll closed 3 years ago

underoll commented 3 years ago
const msg = 'SOME BODY'
const usr = '<usr><SomeExtraHeader>abc123</SomeExtraHeader></usr>';
const usrBuffer = Buffer.from(usr.padEnd(usr.length + (4 - usr.length % 4)));
const usrLength = Buffer.alloc(4);
usrLength.writeInt32LE(usrBuffer.length);
rfh2.StrucLength = rfh2.StrucLength + 4 + usrBuffer.length;
msg = Buffer.concat([rfh2.getBuffer(), usrLength, usrBuffer, Buffer.from(msg)]);

causes

    RangeError: Input string is too long for MQI field
        at Object.exports.setMQIString (/opt/mqtest/node_modules/ibmmq/lib/mqiutils.js:46:13)
        at _newMQRFH2ffi (/opt/mqtest/node_modules/ibmmq/lib/mqrfh2.js:105:5)
        at _copyRFH2toC (/opt/mqtest/node_modules/ibmmq/lib/mqrfh2.js:123:16)
        at exports.MQRFH2.getBuffer (/opt/mqtest/node_modules/ibmmq/lib/mqrfh2.js:159:10)

i've changed "RFH2 " to "RFH" (because setMQIString can pad strings with spaces) in https://github.com/ibm-messaging/mq-mqi-nodejs/blob/72fba926b7010a85ce2a2c6459d2e9c58fa066d7/lib/mqrfh2.js#L105

but then noticed that _copyRFH2toC just ignores StrucLength and NameValueCCSID from the original object

ibmmqmet commented 3 years ago

Included in 0.9.18