Merge pull request #14948 from mtgto/soap-httpclient

[soap] Add HttpClient.
This commit is contained in:
Mine Starks
2017-03-09 10:32:20 -08:00
committed by GitHub
2 changed files with 49 additions and 5 deletions
+28 -1
View File
@@ -49,4 +49,31 @@ export interface Server extends events.EventEmitter {
log(type: any, data: any): any;
}
export function listen(server: any, path: string, service: any, wsdl: string): Server;
declare function createClient(wsdlPath: string, options: any, fn: (err: any, client: Client) => void): void;
declare function createClient(wsdlPath: string, options: Option, fn: (err: any, client: Client) => void): void;
export interface Option {
attributesKey?: string;
disableCache?: boolean;
endpoint?: string;
envelopeKey?: string;
escapeXML?: boolean;
forceSoap12Headers?: boolean;
httpClient?: HttpClient;
ignoreBaseNameSpaces?: boolean,
ignoredNamespaces?: string[] | {namespaces: string[], override: boolean};
overrideRootElement?: {namespace: string, xmlnsAttributes?: string[]};
request?: (options: any, callback?: (error: any, res: any, body: any) => void) => void;
stream?: boolean;
valueKey?: string;
wsdl_headers?: { [key: string]: any };
wsdl_options?: { [key: string]: any };
xmlKey?: string;
}
export class HttpClient {
constructor(options?: Option);
buildRequest(rurl: string, data: any | string, exheaders?: { [key: string]: any }, exoptions?: { [key: string]: any }): any;
handleResponse(req: any, res: any, body: any | string): any | string;
request(rurl: string, data: any | string, callback: (err: any, res: any, body: any | string) => void, exheaders?: { [key: string]: any }, exoptions?: { [key: string]: any }): any;
requestStream(rurl: string, data: any | string, exheaders?: { [key: string]: any }, exoptions?: { [key: string]: any }): any;
}
+21 -4
View File
@@ -1,10 +1,27 @@
import * as soap from 'soap';
import * as events from 'events';
import * as fs from "fs";
import * as http from "http";
import * as fs from 'fs';
import * as http from 'http';
const url = 'http://example.com/wsdl?wsdl';
const wsdlOptions = { name: 'value' };
// wsdlOptions set only default values
const wsdlOptions = <soap.Option>{
attributesKey: 'attributes',
disableCache: false,
endpoint: url,
envelopeKey: 'soap',
escapeXML: true,
forceSoap12Headers: false,
httpClient: new soap.HttpClient(),
ignoreBaseNameSpaces: false,
ignoredNamespaces: ['tns', 'targetNamespace', 'typedNamespace'],
request: require('request'),
stream: false,
wsdl_headers: [],
wsdl_options: [],
valueKey: '$value',
xmlKey: '$xml'
};
soap.createClient(url, wsdlOptions, function(err: any, client: soap.Client) {
let securityOptions = { hasTimeStamp: false };
@@ -74,7 +91,7 @@ var myService = {
var xml = fs.readFileSync('myservice.wsdl', 'utf8'),
server = http.createServer(function(request,response) {
response.end("404: Not Found: " + request.url);
response.end('404: Not Found: ' + request.url);
});
server.listen(8000);