调用http适配器过程失败

时间:2016-03-02 12:06:34

标签: ibm-mobilefirst mobilefirst-adapters

参考我之前的post

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

  

[错误] FWLSE0099E:调用过程时发生错误[project OfflineReaderAppProject] LoginAdapter / getVerifyFWLSE0100E:parameters:[project OfflineReaderAppProject]   过程返回值必须是Javascript对象,它当前是一个String。   FWLSE0101E:引起:[project OfflineReaderAppProject] nulljava.lang.RuntimeException:过程返回值必须是Javascript对象,它当前是一个String。

...

  

[错误] FWLSE0332E:服务器上不存在用于环境android的应用程序OfflineReaderApp。无法注册此客户端。 [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>

LoginAdapter-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
}

请帮助我。谢谢。

2 个答案:

答案 0 :(得分:0)

  1. 您有错误说wlapp文件未部署到服务器;部署它。

  2. 如果您没有提供适配器的JavaScript实现,则表示您返回的是string而不是object。因此,只能假设您确实返回了一个字符串而不是一个对象。验证您的代码和/或提供适配器JavaScript实现。

答案 1 :(得分:0)

首先,您必须从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/

调用适配器过程