Soap 如何将参数传递给MobileFirst HTTP适配器

Soap 如何将参数传递给MobileFirst HTTP适配器,soap,ibm-mobilefirst,mobilefirst-adapters,Soap,Ibm Mobilefirst,Mobilefirst Adapters,我需要运行HTTP适配器来访问SOAP WSDL服务。它有两个字段userid和password 我已经通过发现后端服务自动生成了适配器。有谁能指导我如何从适配器最初传递值以访问服务吗 function userlogin_ep_process(params, headers){ var soapEnvNS = ''; soapEnvNS = 'http://schemas.xmlsoap.org/soap/envelope/'; var mappings = { r

我需要运行HTTP适配器来访问SOAP WSDL服务。它有两个字段
userid
password

我已经通过发现后端服务自动生成了适配器。有谁能指导我如何从适配器最初传递值以访问服务吗

function userlogin_ep_process(params, headers){
var soapEnvNS = '';

soapEnvNS = 'http://schemas.xmlsoap.org/soap/envelope/';

    var mappings = {
        roots: {
            'process': { nsPrefix: 'client', type: 'client:process' }               
        },

        types: {
            'client:process': {
                children: [
                    {'username': { nsPrefix: 'client' }},   
                    {'userpwd': { nsPrefix: 'client' }} 
                ]
            }
        }
    };

    var namespaces = 'xmlns:client="http://xmlns.oracle.com/InternetMobile/AbsManagement/BPELProcessUserLogin" xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype" ';
    var request = buildBody(params, namespaces, mappings, soapEnvNS);
    var soapAction = 'process';
    return invokeWebService(request, headers, soapAction);
}



function buildBody(params, namespaces, mappings, soapEnvNS){
    var body =
        '<soap:Envelope xmlns:soap="' + soapEnvNS + '">\n' +
        '<soap:Body>\n';

    var fixedParams = {};
    for (var paramName in params) {
        if (mappings['roots'][paramName]) { //There is mapping for this 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 the object that defines the mappings for the specific type

    // loop through the types and see if there is an input param defined
    for(var i = 0; i < 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] = [];
                    for (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 : '/soa-infra/services/Mobile/AbsManagement/userlogin_ep',
        body: {
            content : body.toString(),
            contentType : 'text/xml; charset=utf-8'
        }
    };

    //Adding custom HTTP headers if they were provided as parameter to the procedure call
    //Always add header for 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, '&amp;')
           .replace(/"/g, '&quot;')
           .replace(/'/g, '&apos;')
           .replace(/</g, '&lt;')
           .replace(/>/g, '&gt;');
}
函数userlogin\u ep\u进程(参数、标题){
var soapEnvNS='';
索本恩斯酒店http://schemas.xmlsoap.org/soap/envelope/';
变量映射={
根:{
'process':{nsPrefix:'client',键入:'client:process'}
},
类型:{
“客户端:进程”:{
儿童:[
{'username':{nsPrefix:'client'},
{'userpwd':{nsPrefix:'client'}
]
}
}
};
变量名称空间='xmlns:client='http://xmlns.oracle.com/InternetMobile/AbsManagement/BPELProcessUserLogin“xmlns:plnk=”http://docs.oasis-open.org/wsbpel/2.0/plnktype" ';
var request=buildBody(参数、名称空间、映射、soapEnvNS);
var soapAction='进程';
返回invokeWebService(请求、头、soapAction);
}
函数构建体(参数、名称空间、映射、soapEnvNS){
变位体=
“\n”+
“\n”;
var fixedParams={};
for(参数中的变量paramName){
if(mappings['roots'][paramName]){//此参数存在映射
var root=mappings['roots'][paramName];
var name=paramName;
if(根['nsPrefix'])
name=root['nsPrefix']+':'+paramName;
fixedParams[name]=handleMappings(params[paramName],根['type'],映射['types']);
}
否则{
fixedParams[paramName]=params[paramName];
}
}
body=jsonToXml(fixedParams、body、名称空间);
正文+=
“\n”+
“\n”;
返回体;
}
函数handleMappings(jsonObj、类型、映射){
var fixedObj={};
var typeMap=mappings[type]['children'];//获取为特定类型定义映射的对象
//循环遍历这些类型,查看是否定义了输入参数
对于(变量i=0;ifor(var i=0;i调用适配器并传递需要调用的参数
WL.Client.invokeProcedure
,在您的特定情况下,您可以使用

var invocationData = {
    adapter: 'YOUR_ADAPTER_NAME',
    procedure: 'userlogin_ep_process',
    parameters: {
        process: {
            username: 'YOUR_USERNAME',
            userpwd: 'YOUR_PASSWORD'
        }
    }
};
WL.Client.invokeProcedure(invocationData, {
    onSuccess: yourSuccessFunction,
    onFailure: yourFailureFunction
});

这两个变量应该放在哪里?你指的是基本身份验证吗?你能共享WSDL吗?我假设你想调用
invokeWebService
,对吗?你的适配器代码看起来不完整。在
soapEnvNS
之前应该有一个函数定义;我有一个WSDL,它是员工登录,具有userid和password。如果我输入正确的详细信息,它将显示员工详细信息。我对此非常陌生,所以我右键单击服务并发现后端服务,并提供wsdl url,它自动生成适配器内容。现在我的任务是在何处以及如何将参数传递给适配器,以便它显示员工详细信息??您可以发布来自adap的所有源代码吗ter,第一个函数定义似乎缺失。可能与