Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added custom envelope key option for server
Browse files Browse the repository at this point in the history
Gamze Oguz authored and w666 committed Aug 20, 2024
1 parent 08cecb5 commit 629110b
Showing 4 changed files with 78 additions and 6 deletions.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -229,6 +229,7 @@ Note: for versions of node >0.10.X, you may need to specify `{connection: 'keep-
- `crl` (*string* | *string[]*: PEM encoded CRLs (Certificate Revocation List)
- `ciphers` (*string*): A description of the ciphers to use or exclude, separated by `:`. The default cipher suite is:
- `enableChunkedEncoding` (*boolean*): Controls chunked transfer encoding in response. Some clients (such as Windows 10's MDM enrollment SOAP client) are sensitive to transfer-encoding mode and can't accept chunked response. This option lets users disable chunked transfer encoding for such clients. (**Default:** `true`)
- `envelopeKey` (*string*): Set a custom envelope key. (**Default:** `'soap'`)
- `services` (*Object*)
- `wsdl` (*string*): An XML string that defines the service.
- `callback` (*Function*): A function to run after the server has been initialized.
12 changes: 6 additions & 6 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -199,6 +199,7 @@ export class Server extends EventEmitter {
this.wsdl.options.attributesKey = options.attributesKey || 'attributes';
this.onewayOptions.statusCode = this.onewayOptions.responseCode || 200;
this.onewayOptions.emptyBody = !!this.onewayOptions.emptyBody;
this.wsdl.options.envelopeKey = options.envelopeKey || 'soap';
}

private _processRequestXml(req: Request, res: Response, xml) {
@@ -599,13 +600,14 @@ export class Server extends EventEmitter {
const ns = defs.$targetNamespace;
const encoding = '';
const alias = findPrefix(defs.xmlns, ns);
const envelopeKey = this.wsdl.options.envelopeKey;

const envelopeDefinition = this.wsdl.options.forceSoap12Headers
? 'http://www.w3.org/2003/05/soap-envelope'
: 'http://schemas.xmlsoap.org/soap/envelope/';

let xml = '<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:soap="' + envelopeDefinition + '" ' +
'<' + envelopeKey + ':Envelope' + ' xmlns:' + envelopeKey + '=' + ' "' + envelopeDefinition + '" ' +
encoding +
this.wsdl.xmlnsInEnvelope + '>';

@@ -627,12 +629,10 @@ export class Server extends EventEmitter {
}

if (headers !== '') {
xml += '<soap:Header>' + headers + '</soap:Header>';
xml += '<' + envelopeKey + ':Header>' + headers + '</' + envelopeKey + ':Header>';
}

xml += body ? '<soap:Body>' + body + '</soap:Body>' : '<soap:Body/>';

xml += '</soap:Envelope>';
xml += body ? '<' + envelopeKey + ':Body>' + body + '</' + envelopeKey + ':Body>' : '<' + envelopeKey + ':Body/>';
xml += '</' + envelopeKey + ':Envelope>';
return xml;
}

1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -156,6 +156,7 @@ export interface IServerOptions extends IWsdlBaseOptions {
oneWay?: IOneWayOptions;
/** A boolean for controlling chunked transfer encoding in response. Some client (such as Windows 10's MDM enrollment SOAP client) is sensitive to transfer-encoding mode and can't accept chunked response. This option let user disable chunked transfer encoding for such a client. Default to true for backward compatibility. */
enableChunkedEncoding?: boolean;
envelopeKey?: string;
}

export interface IMTOMAttachments {
70 changes: 70 additions & 0 deletions test/server-options-test.js
Original file line number Diff line number Diff line change
@@ -625,4 +625,74 @@ describe('SOAP Server with Options', function () {
});
});

it('should return soapenv as envelope key when it is set to soapenv', function(done) {
test.server.listen(15099, null, null, function() {
test.soapServer = soap.listen(test.server, {
path: '/stockquote',
services: test.service,
xml: test.wsdl,
uri: __dirname + '/wsdl/strict/',
envelopeKey: 'soapenv'
}, test.service, test.wsdl);
test.baseUrl = 'http://' + test.server.address().address + ":" + test.server.address().port;

//windows return 0.0.0.0 as address and that is not
//valid to use in a request
if (test.server.address().address === '0.0.0.0' || test.server.address().address === '::') {
test.baseUrl = 'http://127.0.0.1:' + test.server.address().port;
}
// console.log(test.baseUrl);
request.post({
url: test.baseUrl + '/stockquote',
body: '<soapenv:Envelope' +
' xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"' +
' xmlns:soap="http://service.applicationsnet.com/soap/">' +
' <soapenv:Header/>' +
' <soapenv:Body>' +
'</soapenv:Envelope>'
}, function(err, res, body) {
assert.ifError(err);
assert.ok(
body.indexOf('soapenv:Envelope') > -1
)
done();
});
});
});

it('should return soap as envelope key by default', function(done) {
test.server.listen(15099, null, null, function() {
test.soapServer = soap.listen(test.server, {
path: '/stockquote',
services: test.service,
xml: test.wsdl,
uri: __dirname + '/wsdl/strict/',
forceSoap12Headers : true
}, test.service, test.wsdl);
test.baseUrl = 'http://' + test.server.address().address + ":" + test.server.address().port;

//windows return 0.0.0.0 as address and that is not
//valid to use in a request
if (test.server.address().address === '0.0.0.0' || test.server.address().address === '::') {
test.baseUrl = 'http://127.0.0.1:' + test.server.address().port;
}
// console.log(test.baseUrl);
request.post({
url: test.baseUrl + '/stockquote',
body: '<soapenv:Envelope' +
' xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"' +
' xmlns:soap="http://service.applicationsnet.com/soap/">' +
' <soapenv:Header/>' +
' <soapenv:Body>' +
'</soapenv:Envelope>'
}, function(err, res, body) {
assert.ifError(err);
assert.ok(
body.indexOf('soap:Envelope') > -1
)
done();
});
});
});

});

0 comments on commit 629110b

Please sign in to comment.