ibm mobilefirst - how to invoke soap adapters when i have wsdl -
i try build hybrid application , have wsdl soap adapter follow step step in ibm site http adapter – communicating http back-end systems
then want invoke adapter invoking adapter procedures hybrid client applications
this code try :
index.html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>emoney</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"> <!-- <link rel="shortcut icon" href="images/favicon.png"> <link rel="apple-touch-icon" href="images/apple-touch-icon.png"> --> <link href="jquerymobile/jquery.mobile-1.4.0.css" rel="stylesheet"> <link rel="stylesheet" href="css/main.css"> <link rel="stylesheet" href="jquerymobile/jquery.mobile-1.4.0.css"> <script>window.$ = window.jquery = wljq;</script> <script src="jquerymobile/jquery.mobile-1.4.0.js"></script> </head> <body style="display: none;"> <div id="header"> <h1>inquiry</h1> </div> <div id="wrapper"> <ul id="itemslist"></ul> </div> <script src="js/initoptions.js"></script> <script src="js/main.js"></script> <script src="js/messages.js"></script> </body> </html>
main.js
//function wlcommoninit(){ // /* // * use of wl.client.connect() api before connectivity mobilefirst server required. // * api should called once, before other wl.client methods communicate mobilefirst server. // * don't forget specify , implement onsuccess , onfailure callback functions wl.client.connect(), e.g: // * // * wl.client.connect({ // * onsuccess: onconnectsuccess, // * onfailure: onconnectfailure // * }); // * // */ // // // common initialization code goes here // // //} // // // $('#inquiry').on('click', function(){ // $.mobile.changepage('#inquiry'); // dogetinquiry(); // }); // //// function dogetinquiry(){ //// $.mobile.loading("show"); //// var invocationdata = { //// adapter : 'inquiryadapters', //// procedure : 'getinquiry', //// parameters : [] //// }; //// //// var options = { //// onsuccess: dogetinquiryfinish, //// onfailure: dogetinquiryfinish //// }; //// wl.client.invokeprocedure(invocationdata, options); //// } // // function dogetinquiry(){ // $.mobile.loading("show"); // var invocationdata = { // adapter : 'inquiryadapters', // procedure : 'getfeedsfiltered', // parameters : [] // }; // // var options = { // onsuccess: dogetinquiryfinish, // onfailure: dogetinquiryfinish // }; // wl.client.invokeprocedure(invocationdata, options); // } // // function dogetinquiryfinish(result){ // if(result.invocationresult.inquiry.length>0){ // buildinquirylist(result.invocationresult.inquiry); // }else{ // $.mobile.loading("hide"); // alert("please try again later!"); // } // } // // function buildinquirylist(inquiry){ // var ul = $('#inquirytlist'); // (var = 0; < inquiry.length; i++) { // var li = $('<li/>').text(inquiry[i].title); // var pubdate = $('<div/>', { // 'class': 'pubdate' // }).text(inquiry[i].pubdate); // // li.append(pubdate); // // ul.append(li); // } // // // // //// console.log("in buildinquirylist()"); //// $("#inquirytlist").empty(); //// var item, i; //// for(i=0;i<inquiry.length;i++){ //// item = inquiry[i]; //// var html = ""; ////// html += "<h3 class='ui-li-heading'>" + item.accountname + "</h3>"; ////// html += "<p class='ui-li-desc'>" + item.accountnumber + "</p>"; ////// if(item.accountbalance.indexof("(")>-1){ ////// html += "<div class='righttext negative'>$" + item.accountbalance + "</div>"; ////// }else{ ////// html += "<div class='righttext'>$" + item.accountbalance + "</div>"; ////// } ////// var listitem = $('<li class="acctitem" acct_name="' + item.accountname + '" data="' + item.accountnumber + '"><a href="#">' + html + '</a></li>'); ////// $("#accountlist").append(listitem); //// } ////// $("#accountheaderlabel").html("account list"); ////// $('#accountlist:visible').listview('refresh'); //// $.mobile.loading("hide"); //// // } /* * copyright license: information contains sample code provided in source code form. may copy, modify, , distribute these sample programs in form without payment ibm® purposes of developing, using, marketing or distributing application programs conforming application programming interface operating platform sample code written. notwithstanding contrary, ibm provides sample source code on "as is" basis , ibm disclaims warranties, express or implied, including, not limited to, implied warranties or conditions of merchantability, satisfactory quality, fitness particular purpose, title, , warranty or condition of non-infringement. ibm shall not liable direct, indirect, incidental, special or consequential damages arising out of use or operation of sample source code. ibm has no obligation provide maintenance, support, updates, enhancements or modifications sample source code. */ var busyindicator = null; function wlcommoninit(){ busyindicator = new wl.busyindicator(); loadfeeds(); } function loadfeeds(){ busyindicator.show(); var invocationdata = { adapter : 'soapadapter1', procedure : 'inquiryimpl_getamount', parameters : [] }; wl.client.invokeprocedure(invocationdata,{ onsuccess : loadfeedssuccess, onfailure : loadfeedsfailure }); } function loadfeedssuccess(result){ wl.logger.debug("feed retrieve success"); busyindicator.hide(); if (result.invocationresult.items.length>0) displayfeeds(result.invocationresult.items); else loadfeedsfailure(); } function loadfeedsfailure(result){ wl.logger.error("feed retrieve failure"); busyindicator.hide(); wl.simpledialog.show("inquiry", "service not available. try again later.", [{ text : 'reload', handler : wl.client.reloadapp }, { text: 'close', handler : function() {} }] ); } function displayfeeds(items){ var ul = $('#itemslist'); (var = 0; < items.length; i++) { var li = $('<li/>').text(items[i].owner); var amount = $('<div/>', { 'class': 'amount' }).text(items[i].amount); li.append(amount); ul.append(li); } }
soapadapter-impl
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // generated code - not edit // // // // soap adapter auto-generated worklight invocation of specific soap-based services. // // adapter may invoke more 1 service long same enpdpoint (server host). // // each adapter procedure matches single operation same endpoint server , accepts: // // params - serialized json representation of xml-based soap body sent service // // headers - custom http headers specified when invoking remote service. json object // // headers names , values. e.g. { 'name1' : 'value1', 'name2' : 'value2' } // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function inquiryimpl_getamount(params, headers){ var soapenvns = ''; // value of 'soapenvns' set based on version of soap used (i.e. 1.1 or 1.2). soapenvns = 'http://www.w3.org/2003/05/soap-envelope'; // following mappings object autogenerated xml schema of input message service. // being used support params json when invoking procedure don't specify namespace // prefix nor specifying whether property attribute or not. // // 'roots' object has list of message parts within invocation soap message. each entry has // mapping between root element name , namespace prefix , type. // each root object may define 'nsprefix' , 'type'. both optional - if there no need ns prefix // 'nsprefix' should not specified. if element simple type 'type' should not // specified. // // 'types' object has list of types each defining children of type , definition of each // child. if child complext type, 'type' property has reference child type definition. // each child object may define: // 'nsprefix' (optional) - holds namespace prefix attached element. if there no need // ns prefix 'nsprefix' should not specified. // 'type' (optional) - if element simple type 'type' should not specified. if // attribute 'type' should have value of '@'. otherwise value of 'type' reference // type definition within 'types' object. var mappings = { roots: { 'getamount': { nsprefix: 'ns', type: 'ns:getamount' } }, types: { 'ax27:inquiryrequest': { children: [ {'channelid': { nsprefix: 'ax29' }}, {'rrn': { nsprefix: 'ax29' }}, {'stan': { nsprefix: 'ax29' }}, {'phoneno': { nsprefix: 'ax27' }} ] }, 'ns:getamount': { children: [ {'request': { nsprefix: 'ns', type: 'ax27:inquiryrequest' }} ] } } }; var namespaces = 'xmlns:ax29="http://services.mik.co.id/xsd" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ax212="http://beans.common.sentrapay.mik.co.id/xsd" xmlns:ns="http://inquiry.services.mik.co.id" xmlns:ax27="http://inquiry.services.mik.co.id/xsd" xmlns:ax28="http://services.mik.co.id/xsd" xmlns:ax210="http://inquiry.services.mik.co.id/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ax211="http://beans.common.sentrapay.mik.co.id/xsd" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" '; var request = buildbody(params, namespaces, mappings, soapenvns); var soapaction = 'urn:getamount'; return invokewebservice(request, headers, soapaction); } function buildbody(params, namespaces, mappings, soapenvns){ var body = '<soap:envelope xmlns:soap="' + soapenvns + '">\n' + '<soap:body>\n'; var fixedparams = {}; (var paramname in params) { if (mappings['roots'][paramname]) { //there mapping param var root = mappings['roots'][paramname]; var name = paramname; if (root['nsprefix']) name = root['nsprefix'] + ':' + paramname; fixedparams[name] = handlemappings(params[paramname], root['type'], mappings['types']); } else { fixedparams[paramname] = params[paramname]; } } body = jsontoxml(fixedparams, body, namespaces); body += '</soap:body>\n' + '</soap:envelope>\n'; return body; } function handlemappings(jsonobj, type, mappings) { var fixedobj = {}; var typemap = mappings[type]['children']; //get object defines mappings specific type // loop through types , see if there input param defined for(var = 0; < typemap.length; i++) { var childtype = typemap[i]; for(var key in childtype) { if(jsonobj[key] !== null) { // input param exists var childname = key; if (childtype[key]['nsprefix']) childname = childtype[key]['nsprefix'] + ':' + key; if (!childtype[key]['type']) //simple type element fixedobj[childname] = jsonobj[key]; else if (typeof jsonobj[key] === 'object' && jsonobj[key].length != undefined) { //array of complex type elements fixedobj[childname] = []; (var i=0; i<jsonobj[key].length; i++) fixedobj[childname][i] = handlemappings(jsonobj[key][i], childtype[key]['type'], mappings); } else if (typeof jsonobj[key] === 'object') //complex type element fixedobj[childname] = handlemappings(jsonobj[key], childtype[key]['type'], mappings); else if (childtype[key]['type'] == '@') //attribute fixedobj['@' + childname] = jsonobj[key]; } } } return fixedobj; } function getattributes(jsonobj) { var attrstr = ''; for(var attr in jsonobj) { if (attr.charat(0) == '@') { var val = jsonobj[attr]; attrstr += ' ' + attr.substring(1); attrstr += '="' + xmlescape(val) + '"'; } } return attrstr; } function jsontoxml(jsonobj, xmlstr, namespaces) { var toappend = ''; for(var attr in jsonobj) { if (attr.charat(0) != '@') { var val = jsonobj[attr]; if (typeof val === 'object' && val.length != undefined) { for(var i=0; i<val.length; i++) { toappend += "<" + attr + getattributes(val[i]); if (namespaces != null) toappend += ' ' + namespaces; toappend += ">\n"; toappend = jsontoxml(val[i], toappend); toappend += "</" + attr + ">\n"; } } else { toappend += "<" + attr; if (typeof val === 'object') { toappend += getattributes(val); if (namespaces != null) toappend += ' ' + namespaces; toappend += ">\n"; toappend = jsontoxml(val, toappend); } else { toappend += ">" + xmlescape(val); } toappend += "</" + attr + ">\n"; } } } return xmlstr += toappend; } function invokewebservice(body, headers, soapaction){ var input = { method : 'post', returnedcontenttype : 'xml', path : '/web_service/services/inquiryimpl.inquiryimplhttpsoap12endpoint/', body: { content : body.tostring(), contenttype : 'text/xml; charset=utf-8' } }; //adding custom http headers if provided parameter procedure call //always add header soap action headers = headers || {}; if (soapaction != 'null') headers.soapaction = soapaction; input['headers'] = headers; return wl.server.invokehttp(input); } function xmlescape(obj) { if(typeof obj !== 'string') { return obj; } return obj.replace(/&/g, '&') .replace(/"/g, '"') .replace(/'/g, ''') .replace(/</g, '<') .replace(/>/g, '>'); }
soapadapter.xml
<?xml version="1.0" encoding="utf-8" standalone="no"?> <wl:adapter xmlns:wl="http://www.ibm.com/mfp/integration" xmlns:http="http://www.ibm.com/mfp/integration/http" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" name="soapadapter1"> <displayname>soapadapter1</displayname> <description></description> <connectivity> <connectionpolicy xsi:type="http:httpconnectionpolicytype"> <protocol>http</protocol> <domain>localhost</domain> <port>8080</port> <connectiontimeoutinmilliseconds>30000</connectiontimeoutinmilliseconds> <sockettimeoutinmilliseconds>30000</sockettimeoutinmilliseconds> <maxconcurrentconnectionspernode>2</maxconcurrentconnectionspernode> </connectionpolicy> </connectivity> <procedure name="inquiryimpl_getamount"/> </wl:adapter>
result if invoke adapters :
{ "envelope": { "body": { "fault": { "detail": "", "faultcode": "soapenv:versionmismatch", "faultstring": "transport level information not match soap message namespace uri" } }, "header": { "action": "http:\/\/www.w3.org\/2005\/08\/addressing\/soap\/fault", "wsa": "http:\/\/www.w3.org\/2005\/08\/addressing" }, "soapenv": "http:\/\/schemas.xmlsoap.org\/soap\/envelope\/" }, "errors": [ ], "info": [ ], "issuccessful": true, "responseheaders": { "connection": "close", "content-type": "text\/xml;charset=utf-8", "date": "wed, 01 apr 2015 04:12:43 gmt", "server": "apache-coyote\/1.1", "transfer-encoding": "chunked" }, "responsetime": 47, "statuscode": 500, "statusreason": "internal server error", "totaltime": 49, "warnings": [ ] }
have "statusreason": "internal server error"
it looks adapter expecting soap 1.2, service soap 1.1.
adapter: soapenvns = 'http://www.w3.org/2003/05/soap-envelope';
return val: "soapenv": "http://schemas.xmlsoap.org/soap/envelope/"
you try changing namespace in adapter match service. need see wsdl know why generated adapter has wrong namespace.
Comments
Post a Comment