Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/soap/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ Client.prototype._invoke = function (method, args, location, callback) {
"</soap:Envelope>";

self.lastRequest = xml;
http.request(location, xml, function (err, response, body) {
http.request(location, xml, async function (err, response, body) {
var obj, result;
if (err) {
callback(err);
} else {
try {
obj = self.wsdl.xmlToObject(body);
obj = await self.wsdl.xmlToObject(body);
} catch (error) {
return callback(error, response, body);
}
Expand Down
65 changes: 38 additions & 27 deletions lib/soap/wsdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

'use strict';

var expat = require('node-expat'),
var ExpatWasm = import('@hpcc-js/wasm-expat'),
inherits = require('util').inherits,
http = require('./http'),
fs = require('fs'),
Expand Down Expand Up @@ -582,8 +582,8 @@ var WSDL = function(definition, uri, options) {
throw new Error('WSDL constructor takes either an XML string or service definition');
}

process.nextTick(function() {
fromFunc.call(self, definition);
process.nextTick(async function() {
await fromFunc.call(self, definition);

self.processIncludes(function(err) {
self.definitions.deleteFixedAttrs();
Expand Down Expand Up @@ -677,9 +677,11 @@ WSDL.prototype.toXML = function() {
return this.xml || '';
}

WSDL.prototype.xmlToObject = function(xml) {
WSDL.prototype.xmlToObject = async function(xml) {
const {Expat} = await ExpatWasm
const expat = await Expat.load()

var self = this,
p = new expat.Parser('UTF-8'),
objectName = null,
root = {},
schema = {
Expand All @@ -695,7 +697,9 @@ WSDL.prototype.xmlToObject = function(xml) {

var refs = {}, id; // {id:{hrefs:[],obj:}, ...}

p.on('startElement', function(nsName, attrs) {
const callbacks = {}

callbacks.startElement = function(nsName, attrs) {
var name = splitNSName(nsName).name,
top = stack[stack.length-1],
topSchema = top.schema,
Expand Down Expand Up @@ -747,9 +751,9 @@ WSDL.prototype.xmlToObject = function(xml) {

if (topSchema && topSchema[name+'[]']) name = name + '[]';
stack.push({name: originalName, object: obj, schema: topSchema && topSchema[name], id:attrs.id});
})
}

p.on('endElement', function(nsName) {
callbacks.endElement = function(nsName) {
var cur = stack.pop(),
obj = cur.object,
top = stack[stack.length-1],
Expand All @@ -774,9 +778,9 @@ WSDL.prototype.xmlToObject = function(xml) {
if(cur.id) {
refs[cur.id].obj = obj;
}
})
p.on('text', function(text) {
}

callbacks.characterData = function(text) {
text = trim(text);
if (!text.length) return;

Expand All @@ -798,12 +802,12 @@ WSDL.prototype.xmlToObject = function(xml) {
}
}
top.object = value;
});

if (!p.parse(xml, false)) {
throw new Error(p.getError());
}


if (!expat.parse(xml, callbacks)) {
throw new Error("Parsing failed");
}

for(var n in refs) {
var ref = refs[n];
var obj = ref.obj;
Expand Down Expand Up @@ -876,14 +880,18 @@ WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns) {
return parts.join('');
}

WSDL.prototype._parse = function(xml)
WSDL.prototype._parse = async function(xml)
{
const {Expat} = await ExpatWasm
const expat = await Expat.load()

var self = this,
p = new expat.Parser('UTF-8'),
stack = [],
root = null;

p.on('startElement', function(nsName, attrs) {
const callbacks = {}

callbacks.startElement = function(nsName, attrs) {
var top = stack[stack.length - 1];
if (top) {
try {
Expand Down Expand Up @@ -911,24 +919,27 @@ WSDL.prototype._parse = function(xml)
}
stack.push(root);
}
})
}

p.on('endElement', function(name) {
callbacks.endElement = function(name) {
var top = stack[stack.length - 1];
assert(top, 'Unmatched close tag: ' + name);

top.endElement(stack, name);
})

if (!p.parse(xml, false)) {
throw new Error(p.getError());
}

callbacks.characterData = function(text) {}


if (!expat.parse(xml, callbacks)) {
throw new Error("Parsing failed");
}

return root;
}

WSDL.prototype._fromXML = function(xml) {
this.definitions = this._parse(xml);
WSDL.prototype._fromXML = async function(xml) {
this.definitions = await this._parse(xml);
this.xml = xml;
}

Expand Down
Loading