Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
类强制转换:java.lang.String不能强制转换为org.mozilla.javascript.Scriptable_Javascript_Ibm Mobilefirst_Worklight Adapters_Worklight Server - Fatal编程技术网

类强制转换:java.lang.String不能强制转换为org.mozilla.javascript.Scriptable

类强制转换:java.lang.String不能强制转换为org.mozilla.javascript.Scriptable,javascript,ibm-mobilefirst,worklight-adapters,worklight-server,Javascript,Ibm Mobilefirst,Worklight Adapters,Worklight Server,在调用http适配器过程时,它弹出一个带有ProcedureName、Signature和Paramaters的对话框,当我在输入两个字符串类型参数后点击Run按钮时,我得到了“Class Cast:java.lang.string不能转换为org.mozilla.javascript.Scriptable”错误 function CurrencyConvertor_ConversionRate(params, headers){ var soapEnvNS; soapEnvN

在调用http适配器过程时,它弹出一个带有ProcedureName、Signature和Paramaters的对话框,当我在输入两个字符串类型参数后点击Run按钮时,我得到了“Class Cast:java.lang.string不能转换为org.mozilla.javascript.Scriptable”错误

function CurrencyConvertor_ConversionRate(params, headers){
    var soapEnvNS;

    soapEnvNS = 'http://schemas.xmlsoap.org/soap/envelope/';
    var request = buildBody(params, 'xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.webserviceX.NET/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" ', soapEnvNS);
    return invokeWebService(request, headers);
}



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

    body = jsonToXml(params, body, namespaces);

    body += 
        '</soap:Body>\n' +
        '</soap:Envelope>\n';
    return body;
}

function getAttributes(jsonObj) {
    var attrStr = '';
    for(var attr in jsonObj) {
        var val = jsonObj[attr];
        if (attr.charAt(0) == '@') {
            attrStr += ' ' + attr.substring(1);
            attrStr += '="' + val + '"';
        }
    }
    return attrStr;
}

function jsonToXml(jsonObj, xmlStr, namespaces) {
    var toAppend = '';
    for(var attr in jsonObj) {
        var val = jsonObj[attr];
        if (attr.charAt(0) != '@') {
            toAppend += "<" + attr;
            if (typeof val  === 'object') {
                toAppend += getAttributes(val);
                if (namespaces != null)
                    toAppend += ' ' + namespaces;
                toAppend += ">\n";
                toAppend = jsonToXml(val, toAppend);
            }
            else {
                toAppend += ">" + val;
            }
            toAppend += "</" + attr + ">\n";
        }
    }
    return xmlStr += toAppend;
}


function invokeWebService(body, headers){
    var input = {
        method : 'post',
        returnedContentType : 'xml',
        path : '/CurrencyConvertor.asmx',
        body: {
            content : body.toString(),
            contentType : 'text/xml; charset=utf-8'
        }
    };

    //Adding custom HTTP headers if they were provided as parameter to the procedure call 
    headers && (input['headers'] = headers);

    return WL.Server.invokeHttp(input);
}
仅供参考,我使用worklight application framework数据对象编辑器创建了worklight适配器(自动生成.xml和impl.js文件)

function CurrencyConvertor_ConversionRate(params, headers){
    var soapEnvNS;

    soapEnvNS = 'http://schemas.xmlsoap.org/soap/envelope/';
    var request = buildBody(params, 'xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.webserviceX.NET/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" ', soapEnvNS);
    return invokeWebService(request, headers);
}



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

    body = jsonToXml(params, body, namespaces);

    body += 
        '</soap:Body>\n' +
        '</soap:Envelope>\n';
    return body;
}

function getAttributes(jsonObj) {
    var attrStr = '';
    for(var attr in jsonObj) {
        var val = jsonObj[attr];
        if (attr.charAt(0) == '@') {
            attrStr += ' ' + attr.substring(1);
            attrStr += '="' + val + '"';
        }
    }
    return attrStr;
}

function jsonToXml(jsonObj, xmlStr, namespaces) {
    var toAppend = '';
    for(var attr in jsonObj) {
        var val = jsonObj[attr];
        if (attr.charAt(0) != '@') {
            toAppend += "<" + attr;
            if (typeof val  === 'object') {
                toAppend += getAttributes(val);
                if (namespaces != null)
                    toAppend += ' ' + namespaces;
                toAppend += ">\n";
                toAppend = jsonToXml(val, toAppend);
            }
            else {
                toAppend += ">" + val;
            }
            toAppend += "</" + attr + ">\n";
        }
    }
    return xmlStr += toAppend;
}


function invokeWebService(body, headers){
    var input = {
        method : 'post',
        returnedContentType : 'xml',
        path : '/CurrencyConvertor.asmx',
        body: {
            content : body.toString(),
            contentType : 'text/xml; charset=utf-8'
        }
    };

    //Adding custom HTTP headers if they were provided as parameter to the procedure call 
    headers && (input['headers'] = headers);

    return WL.Server.invokeHttp(input);
}
impl.js文件

function CurrencyConvertor_ConversionRate(params, headers){
    var soapEnvNS;

    soapEnvNS = 'http://schemas.xmlsoap.org/soap/envelope/';
    var request = buildBody(params, 'xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.webserviceX.NET/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" ', soapEnvNS);
    return invokeWebService(request, headers);
}



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

    body = jsonToXml(params, body, namespaces);

    body += 
        '</soap:Body>\n' +
        '</soap:Envelope>\n';
    return body;
}

function getAttributes(jsonObj) {
    var attrStr = '';
    for(var attr in jsonObj) {
        var val = jsonObj[attr];
        if (attr.charAt(0) == '@') {
            attrStr += ' ' + attr.substring(1);
            attrStr += '="' + val + '"';
        }
    }
    return attrStr;
}

function jsonToXml(jsonObj, xmlStr, namespaces) {
    var toAppend = '';
    for(var attr in jsonObj) {
        var val = jsonObj[attr];
        if (attr.charAt(0) != '@') {
            toAppend += "<" + attr;
            if (typeof val  === 'object') {
                toAppend += getAttributes(val);
                if (namespaces != null)
                    toAppend += ' ' + namespaces;
                toAppend += ">\n";
                toAppend = jsonToXml(val, toAppend);
            }
            else {
                toAppend += ">" + val;
            }
            toAppend += "</" + attr + ">\n";
        }
    }
    return xmlStr += toAppend;
}


function invokeWebService(body, headers){
    var input = {
        method : 'post',
        returnedContentType : 'xml',
        path : '/CurrencyConvertor.asmx',
        body: {
            content : body.toString(),
            contentType : 'text/xml; charset=utf-8'
        }
    };

    //Adding custom HTTP headers if they were provided as parameter to the procedure call 
    headers && (input['headers'] = headers);

    return WL.Server.invokeHttp(input);
}
函数CurrencyConvertor\u转换率(参数、标头){
var soapEnvNS;
索本恩斯酒店http://schemas.xmlsoap.org/soap/envelope/';
var request=buildBody(参数,'xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/“xmlns:tm=”http://microsoft.com/wsdl/mime/textMatching/“xmlns:s=”http://www.w3.org/2001/XMLSchema“xmlns:wsdl=”http://schemas.xmlsoap.org/wsdl/“xmlns:tns=”http://www.webserviceX.NET/“xmlns:http=”http://schemas.xmlsoap.org/wsdl/http/“xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/“xmlns:mime=”http://schemas.xmlsoap.org/wsdl/mime/“xmlns:soap12=”http://schemas.xmlsoap.org/wsdl/soap12/“,soapEnvNS);
返回invokeWebService(请求、头);
}
函数buildBody(参数、名称空间、soapEnvNS){
变位体=
“\n”+
“\n”;
body=jsonToXml(参数、body、名称空间);
正文+=
“\n”+
“\n”;
返回体;
}
函数getAttributes(jsonObj){
var attrStr='';
for(jsonObj中的var attr){
var val=jsonObj[attr];
如果(属性字符(0)='@'){
属性字符串+=''+属性子字符串(1);
attrStr+='=''+val+''';
}
}
返回属性str;
}
函数jsonToXml(jsonObj、xmlStr、名称空间){
var toAppend='';
for(jsonObj中的var attr){
var val=jsonObj[attr];
如果(属性字符(0)!=“@”){
toAppend+=“\n”;
toAppend=jsonToXml(val,toAppend);
}
否则{
toAppend+=“>”+val;
}
toAppend+=“\n”;
}
}
返回xmlStr+=toAppend;
}
函数invokeWebService(主体、标题){
变量输入={
方法:“post”,
returnedContentType:'xml',
路径:'/CurrencyConvertor.asmx',
正文:{
内容:body.toString(),
contentType:'text/xml;字符集=utf-8'
}
};
//添加自定义HTTP头(如果它们作为过程调用的参数提供)
标题&(输入['headers']=标题);
返回WL.Server.invokeHttp(输入);
}

该错误表示代码中的某个地方存在无效的JSON对象

function CurrencyConvertor_ConversionRate(params, headers){
    var soapEnvNS;

    soapEnvNS = 'http://schemas.xmlsoap.org/soap/envelope/';
    var request = buildBody(params, 'xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.webserviceX.NET/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" ', soapEnvNS);
    return invokeWebService(request, headers);
}



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

    body = jsonToXml(params, body, namespaces);

    body += 
        '</soap:Body>\n' +
        '</soap:Envelope>\n';
    return body;
}

function getAttributes(jsonObj) {
    var attrStr = '';
    for(var attr in jsonObj) {
        var val = jsonObj[attr];
        if (attr.charAt(0) == '@') {
            attrStr += ' ' + attr.substring(1);
            attrStr += '="' + val + '"';
        }
    }
    return attrStr;
}

function jsonToXml(jsonObj, xmlStr, namespaces) {
    var toAppend = '';
    for(var attr in jsonObj) {
        var val = jsonObj[attr];
        if (attr.charAt(0) != '@') {
            toAppend += "<" + attr;
            if (typeof val  === 'object') {
                toAppend += getAttributes(val);
                if (namespaces != null)
                    toAppend += ' ' + namespaces;
                toAppend += ">\n";
                toAppend = jsonToXml(val, toAppend);
            }
            else {
                toAppend += ">" + val;
            }
            toAppend += "</" + attr + ">\n";
        }
    }
    return xmlStr += toAppend;
}


function invokeWebService(body, headers){
    var input = {
        method : 'post',
        returnedContentType : 'xml',
        path : '/CurrencyConvertor.asmx',
        body: {
            content : body.toString(),
            contentType : 'text/xml; charset=utf-8'
        }
    };

    //Adding custom HTTP headers if they were provided as parameter to the procedure call 
    headers && (input['headers'] = headers);

    return WL.Server.invokeHttp(input);
}
使用
body.toString()
as
toString
将返回无效的JSON对象值(既不是有效字符串,也不是有效数组)

function CurrencyConvertor_ConversionRate(params, headers){
    var soapEnvNS;

    soapEnvNS = 'http://schemas.xmlsoap.org/soap/envelope/';
    var request = buildBody(params, 'xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.webserviceX.NET/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" ', soapEnvNS);
    return invokeWebService(request, headers);
}



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

    body = jsonToXml(params, body, namespaces);

    body += 
        '</soap:Body>\n' +
        '</soap:Envelope>\n';
    return body;
}

function getAttributes(jsonObj) {
    var attrStr = '';
    for(var attr in jsonObj) {
        var val = jsonObj[attr];
        if (attr.charAt(0) == '@') {
            attrStr += ' ' + attr.substring(1);
            attrStr += '="' + val + '"';
        }
    }
    return attrStr;
}

function jsonToXml(jsonObj, xmlStr, namespaces) {
    var toAppend = '';
    for(var attr in jsonObj) {
        var val = jsonObj[attr];
        if (attr.charAt(0) != '@') {
            toAppend += "<" + attr;
            if (typeof val  === 'object') {
                toAppend += getAttributes(val);
                if (namespaces != null)
                    toAppend += ' ' + namespaces;
                toAppend += ">\n";
                toAppend = jsonToXml(val, toAppend);
            }
            else {
                toAppend += ">" + val;
            }
            toAppend += "</" + attr + ">\n";
        }
    }
    return xmlStr += toAppend;
}


function invokeWebService(body, headers){
    var input = {
        method : 'post',
        returnedContentType : 'xml',
        path : '/CurrencyConvertor.asmx',
        body: {
            content : body.toString(),
            contentType : 'text/xml; charset=utf-8'
        }
    };

    //Adding custom HTTP headers if they were provided as parameter to the procedure call 
    headers && (input['headers'] = headers);

    return WL.Server.invokeHttp(input);
}
使用
json.stringify(body)
来代替,它应该能让你达到你的目的

function CurrencyConvertor_ConversionRate(params, headers){
    var soapEnvNS;

    soapEnvNS = 'http://schemas.xmlsoap.org/soap/envelope/';
    var request = buildBody(params, 'xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.webserviceX.NET/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" ', soapEnvNS);
    return invokeWebService(request, headers);
}



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

    body = jsonToXml(params, body, namespaces);

    body += 
        '</soap:Body>\n' +
        '</soap:Envelope>\n';
    return body;
}

function getAttributes(jsonObj) {
    var attrStr = '';
    for(var attr in jsonObj) {
        var val = jsonObj[attr];
        if (attr.charAt(0) == '@') {
            attrStr += ' ' + attr.substring(1);
            attrStr += '="' + val + '"';
        }
    }
    return attrStr;
}

function jsonToXml(jsonObj, xmlStr, namespaces) {
    var toAppend = '';
    for(var attr in jsonObj) {
        var val = jsonObj[attr];
        if (attr.charAt(0) != '@') {
            toAppend += "<" + attr;
            if (typeof val  === 'object') {
                toAppend += getAttributes(val);
                if (namespaces != null)
                    toAppend += ' ' + namespaces;
                toAppend += ">\n";
                toAppend = jsonToXml(val, toAppend);
            }
            else {
                toAppend += ">" + val;
            }
            toAppend += "</" + attr + ">\n";
        }
    }
    return xmlStr += toAppend;
}


function invokeWebService(body, headers){
    var input = {
        method : 'post',
        returnedContentType : 'xml',
        path : '/CurrencyConvertor.asmx',
        body: {
            content : body.toString(),
            contentType : 'text/xml; charset=utf-8'
        }
    };

    //Adding custom HTTP headers if they were provided as parameter to the procedure call 
    headers && (input['headers'] = headers);

    return WL.Server.invokeHttp(input);
}
此外,尝试添加一些日志行以便于跟踪错误

function CurrencyConvertor_ConversionRate(params, headers){
    var soapEnvNS;

    soapEnvNS = 'http://schemas.xmlsoap.org/soap/envelope/';
    var request = buildBody(params, 'xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.webserviceX.NET/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" ', soapEnvNS);
    return invokeWebService(request, headers);
}



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

    body = jsonToXml(params, body, namespaces);

    body += 
        '</soap:Body>\n' +
        '</soap:Envelope>\n';
    return body;
}

function getAttributes(jsonObj) {
    var attrStr = '';
    for(var attr in jsonObj) {
        var val = jsonObj[attr];
        if (attr.charAt(0) == '@') {
            attrStr += ' ' + attr.substring(1);
            attrStr += '="' + val + '"';
        }
    }
    return attrStr;
}

function jsonToXml(jsonObj, xmlStr, namespaces) {
    var toAppend = '';
    for(var attr in jsonObj) {
        var val = jsonObj[attr];
        if (attr.charAt(0) != '@') {
            toAppend += "<" + attr;
            if (typeof val  === 'object') {
                toAppend += getAttributes(val);
                if (namespaces != null)
                    toAppend += ' ' + namespaces;
                toAppend += ">\n";
                toAppend = jsonToXml(val, toAppend);
            }
            else {
                toAppend += ">" + val;
            }
            toAppend += "</" + attr + ">\n";
        }
    }
    return xmlStr += toAppend;
}


function invokeWebService(body, headers){
    var input = {
        method : 'post',
        returnedContentType : 'xml',
        path : '/CurrencyConvertor.asmx',
        body: {
            content : body.toString(),
            contentType : 'text/xml; charset=utf-8'
        }
    };

    //Adding custom HTTP headers if they were provided as parameter to the procedure call 
    headers && (input['headers'] = headers);

    return WL.Server.invokeHttp(input);
}