调用 http 适配器过程失败

Invoking http adapter procedure fails

参考我之前的

我正在尝试从混合移动应用程序调用该过程,但我在 logcat 中收到以下错误:

[ERROR ] FWLSE0099E: An error occurred while invoking procedure [project OfflineReaderAppProject]LoginAdapter/getVerifyFWLSE0100E: parameters: [project OfflineReaderAppProject] Procedure return value must be a Javascript Object, it is currently a String. FWLSE0101E: Caused by: [project OfflineReaderAppProject]nulljava.lang.RuntimeException: Procedure return value must be a Javascript Object, it is currently a String.

...

[ERROR ] FWLSE0332E: The application OfflineReaderApp for the environment android does not exist on the server. Cannot register this client. [project OfflineReaderAppProject]

这里是index.html:

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="UTF-8">
        <title>OpenPdf</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 rel="stylesheet" href="css/main.css">
        <script>window.$ = window.jQuery = WLJQ;</script>
        <script>
        function mobgetVerify(pName) {
          var invocationData = {
                 adapter : 'LoginAdapter',
                 procedure : 'getVerify',
                 parameters : [ pName ]
          };

          WL.Client.invokeProcedure(invocationData, {
                 onSuccess : getVerifySuccess,
                 onFailure : getVerifyFailure,
          });
   };

        function getVerifySuccess(res) {
          var httpStatusCode = res.status;
          if (200 == httpStatusCode) {
                 var invocationResult = res.invocationResult;
                 var isSuccessful = invocationResult.isSuccessful;
                 if (true == isSuccessful) {
                       var val = invocationResult.res;
                      // var lng = invocationResult.lng;
                       alert("Success: Value=" + res);
                 } else {
                       alert("Error. isSuccessful=" + isSuccessful);
                 }
          } else {
                 alert("Error. httpStatusCode=" + httpStatusCode);
          }


   };




    function getVerifyFailure(result){
      alert("Verification Failure");


    };
        </script>
    </head>
    <body style="display: none;">
        <!--application UI goes here-->
        Hello MobileFirst
        <br />
        <br />
        <br />
        <p> 
<button onclick="mobgetVerify( 'kevin' )">send value="kevin"</button>
<p> 
        <p id="demo"></p> <br />        
        <br />
        <br />
        <br />
        <br />
        <script src="js/initOptions.js"></script>
        <script src="js/main.js"></script>
        <script src="js/messages.js"></script>
    </body>

LoginAdapter.xml

<description>LoginAdapter</description>
<connectivity>
    <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
        <protocol>http</protocol>
        <domain>mfpreader.comze.com</domain>
        <port>80</port>
        <connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds>
        <socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds>

登录适配器-impl.js

function getVerify(pName) {

var input = {
    method : 'get',
    returnedContentType : 'plain',
    path : '/login.php',
    parameters : {
        'username' : pName,
        'password' : 'pass'   // hard-coded
            }


};


var response= WL.Server.invokeHttp(input);

if (response.statusCode==200 && response.isSuccessful==true){

    var val =response.text

        return {

            data:val

        }


}
else{

    return null
}

请问有什么帮助吗?谢谢。

  1. 你报错说wlapp文件没有部署到服务器;部署它。

  2. 你有一个错误指出你返回的是 string 而不是 object,但是你没有提供你的 适配器的 JavaScript 实施。因此只能假定您返回的确实是一个字符串而不是一个对象。验证您的代码 and/or 提供您的适配器 JavaScript 实现。

首先 all.you 必须从 index.html 页面删除调用 HttpAdpater 客户端代码并实施任何 js 文件(即 main.js),部署适配器 wlapp。

试试这个方法

main.js:

function wlCommonInit(){


    }
    function mobgetVerify(pName) {

        alert("Hi"+pName);
        var invocationData = {
               adapter : 'LoginAdapter',
               procedure : 'getVerify',
               parameters : [ pName ]
        };

        WL.Client.invokeProcedure(invocationData, {
               onSuccess : getVerifySuccess,
               onFailure : getVerifyFailure,
        });
    };

     function getVerifySuccess(res) {
            var httpStatusCode = res.status;

            var httpStatusCode = res.status;
            if (200 == httpStatusCode) {
                   var invocationResult = res.invocationResult;
                   var isSuccessful = invocationResult.isSuccessful;
                   if (true == isSuccessful) {

                       $("#demo").html(JSON.stringify(res.responseJSON));     

                         alert("Success: Value=" + res.responseJSON.data);

                   } else {
                         alert("Error. isSuccessful=" + isSuccessful);
                   }
            } else {
                   alert("Error. httpStatusCode=" + httpStatusCode);
            }

    };

    function getVerifyFailure(result){
        alert("Verification Failure");
    };

从混合客户端应用程序调用适配器过程https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-6-3/server-side-development/invoking-adapter-procedures-hybrid-client-applications/