Hi!
I've been working on a testing framework and I'm using wsdlrdr to parse the SOAP API definition in our test project.
I would need a method to store the WSDL in cache programmatically based on promises so I can wait until the document is completely downloaded in cache directory.
I have an approach:
/**
* Wait for the WSDL content. Checks for the cached file and
* if t doesn't exist downloads and stores it in cache folder.
*/
waitForWsdlReady() {
return new Promise((resolve) => {
const params = {
host: WsConfig.SOAP_HOST,
path: WsConfig.SOAP_PATH,
wsdl: WsConfig.SOAP_WSDL,
};
const opts = { secure: WsConfig.SOAP_SECURE, failOnWrongContentType: false, };
wsdlrdr.getCachedWsdl(params, opts)
.then((wsdl) => {
// return cached wsdl if available
if (wsdl !== null) {
console.log('waitForWsdlReady - Already stored WSDL');
resolve(wsdl);
}
// create a params copy
const paramsCopy = Object.assign({}, params, {
path: params.wsdl
});
// refresh wsdl, save to cache
return wsdlrdr.doGetRequest(paramsCopy, opts)
.then((res) => {
if (res.response.statusCode !== 200) {
throw new Error(`fail to get wsdl: ${res.response.statusMessage}`);
}
const contentType = res.response.headers['content-type'];
if (contentType.indexOf('xml') === -1 &&
contentType.indexOf('wsdl') === -1) {
if (opts.failOnWrongContentType === void 0 ||
opts.failOnWrongContentType === true) {
throw new Error('no wsdl/xml response');
} else {
console.error('no wsdl/xml as content-type');
}
}
console.log('waitForWsdlReady - Caching WSDL');
wsdl.saveWsdlToCache(params, res.body).then(() => {
resolve();
});
});
});
});
}
Notice that I'm not resolving the promise until saveWsdlToCache has ended.
Thank you for providing such as great library. Greetings!
Hi!
I've been working on a testing framework and I'm using wsdlrdr to parse the SOAP API definition in our test project.
I would need a method to store the WSDL in cache programmatically based on promises so I can wait until the document is completely downloaded in cache directory.
I have an approach:
Notice that I'm not resolving the promise until saveWsdlToCache has ended.
Thank you for providing such as great library. Greetings!