Reputation: 364
I am trying to use JavaScript HTTP Adapters in order to get some data from a SOAP Web Service. For that, I am using MFP8 and Ionic with TypeScript.
I have the following adapter implementation file,
function getFeed(params) {
var sr =
"<soapenv:Envelope " +
"xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
"xmlns:len=\"targetNamespace HERE" >" +
"<soapenv:Header/>"+
"<soapenv:Body>" +
"<len:authentication>" +
"<username>"+params[0]+"</username>"+
"<password>"+params[1]+"</password>"+
"</authentication></soapenv:Body></soapenv:Envelope>";
var input = {
method : 'post',
returnedContentType : 'xml',
path : 'PATH HERE',
body: {
content: sr,
contentType: 'text/xml; charset=utf-8',
},
};
return MFP.Server.invokeHttp(input);
}
And here is the adapter.xml,
<mfp:adapter name="http"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mfp="http://www.ibm.com/mfp/integration"
xmlns:http="http://www.ibm.com/mfp/integration/http">
<displayName>http</displayName>
<description>http</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>DOMAIN NAME HERE</domain>
<port>PORT NO HERE</port>
<connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds>
<socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds>
<maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode>
</connectionPolicy>
</connectivity>
<procedure name="getFeed"/>
</mfp:adapter>
So, following the API documentation, I did the following to call the adapter within my ionic provider,
var resourceRequest = new WLResourceRequest("adapters/http/getFeed", WLResourceRequest.GET);
resourceRequest.setQueryParameter("params", "['username', 'password']");
resourceRequest.send().then(
function(response) {
alert('response '+JSON.stringify(response.responseText));
},
function(response) {
alert("HTTP Failure "+JSON.stringify(response));
}
);
Since, I need to get a specific data from the SOAP service. For that, I need to pass a parameters as well as method.
Reading in the Knowledge center, I found something about calling the paremeters with a querystring, I can able to pass the parameters.
My requirement is to pass the method name also.
Can anyone tell me how to pass the method name?
Anyone help will be Appreciated!!!
Upvotes: 3
Views: 370
Reputation: 181
You can pass as many parameters as you wish, for example you can do something like this:
in the adapter:
function getFeed(method, username, password) {
var sr =
"<soapenv:Envelope " +
"xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
"xmlns:len=\"targetNamespace HERE" >" +
"<soapenv:Header/>"+
"<soapenv:Body>" +
"<len:authentication>" +
"<method>"+method+"</method>"+
"<username>"+username+"</username>"+
"<password>"+password+"</password>"+
"</authentication></soapenv:Body></soapenv:Envelope>";
var input = {
method : 'post',
returnedContentType : 'xml',
path : 'PATH HERE',
body: {
content: sr,
contentType: 'text/xml; charset=utf-8',
},
};
return MFP.Server.invokeHttp(input);
}
and in the client:
var resourceRequest = new WLResourceRequest("adapters/http/getFeed", WLResourceRequest.GET);
resourceRequest.setQueryParameter("params", "['myMethod', 'myUsername', 'myPassword']");
resourceRequest.send().then(
function(response) {
alert('response '+JSON.stringify(response.responseText));
},
function(response) {
alert("HTTP Failure "+JSON.stringify(response));
}
);
The JSON array syntax in the request is just the way the parameters are being passed over the network, it does not mean that you get an array back in the adapter. It works by assigning the first element in the array to the first function parameter, the second element to the second parameter, etc...
Upvotes: 2