Repository navigation
Select the SOAP binding that matches the request envelope - #1335
2836048681 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Thanks for the contributions @2836048681. Please do the DCO signoff as yourself (the human operating the agent) instead of the coding agent itself. Note that the email address can be your GitHub hidden email address (ending in @users.noreply.github.com)
Please do note the implications of a DCO sign off (which used in place of a CLA): https://loopback.io/doc/en/contrib/code-contrib.html#developer-certificate-of-origin-dco.
Please also follow Conventional Commits for the commit message.
I've added some comments for your kind amendments.
A change on (incorrect) behaviour to note:
On the old fallback path, serviceName and portName came from the last port the loop visited, while binding came from the first. This PR fixes this as well. Though setups that (incorrectly) only implemented handlers for the last port worked before by accident and will now break. No changes needed for this. Just documenting it here for posterity.
| const SOAP11_ENVELOPE = 'http://schemas.xmlsoap.org/soap/envelope/'; | ||
| const SOAP12_ENVELOPE = 'http://www.w3.org/2003/05/soap-envelope'; |
There was a problem hiding this comment.
Thanks for the refactor. Can we go one step and get rid of these in favour of helper.namespaces.soap / .soap12?
| } | ||
|
|
||
| xmlToJson(nsContext, xml, descriptor) { | ||
| xmlToJson(nsContext, xml, descriptor, onRootElement) { |
There was a problem hiding this comment.
Note this signature change to include a callback. May lead to argument bloat over time if we keep adding callbacks.
One potential alternative is a dedicated static helper to extract the root element:
// src/parser/xmlHandler.js
static parseRootQName(xml) {
const parser = sax.parser(true, {xmlns: true});
let root;
parser.onopentag = function(node) {
if (!root) root = new QName(node.uri, node.local, node.prefix);
};
parser.onerror = function() { parser.error = null; parser.resume(); };
// Only feed until the root tag has been seen
for (let i = 0; i < xml.length && !root; i += 1024) {
parser.write(xml.slice(i, i + 1024));
}
return root;
}Then it can be used as such:
// src/server.js _process
const root = XMLHandler.parseRootQName(input);
const soapVersion = root && root.name === 'Envelope' &&
{[SOAP11_ENVELOPE]: '1.1', [SOAP12_ENVELOPE]: '1.2'}[root.nsURI];
const obj = this.xmlHandler.xmlToJson(null, input);Not a big blocker for me, but to consider for long-term maintainability.
Signed-off-by: MingYang Lu <121647131+2836048681@users.noreply.github.com>
e9180f3 to
40ffffb
Compare
When SOAP 1.1 and SOAP 1.2 WSDL ports share a URL, the server uses the first port listed at that path. With the SOAP 1.1 port listed first, a SOAP 1.2 request can run the SOAP 1.1 handler and receive a SOAP 1.1 Fault.
Record the SOAP version from each WSDL binding and prefer the port at the request path whose binding matches the envelope namespace. Fall back to the first port at that path when no version matches, or to the first WSDL port when no path matches.
Closes #345
Tests
npm run buildpassed on Node.js 24.22.1.npm testreported 255 passing and 5 pending, with one timeout in a test that calls a public Marketo endpoint. The same test timed out on the unmodified base. Rerunning with only that test excluded produced 255 passing and 5 pending.Fixes #345.