如何为工作海报REST调用定义MFP javascript适配器?

时间:2016-06-01 17:22:14

标签: javascript ibm-mobilefirst mobilefirst-adapters

我想编写与Web服务器通信的MFP适配器(v8)。 服务器等待包含图像信息的参数图像。 移动客户端的实现是离子线索。

首先,我在海报中检查了发送的正确请求,但我无法找到适配器的正确配置/实现/调用。

我做错了什么?

1)这是工作复制的海报电话

POST /GetImageKeywords HTTP/1.1
Host: XXXXXXX.mybluemix.net:443
Cache-Control: no-cache
Postman-Token: a98cac04-fe12-3e0f-2884-250bb5ff39ae
Content-Type: application/x-www-form-urlencoded

image=data%3..................

2)这是无效的MFP适配器实施:

function getTagsForPicture(urlimage) {
 var input = {
    method : 'post',
    returnedContentType : 'xml',
    path : 'GetImageKeywords',
  parameters: {'image': urlimage },
  headers: {"Accept":"application\/x-www-form-urlencoded",
            "Content-Type":"application\/x-www-form-urlencoded"}
 };
 return MPF.Server.invokeHttp(input);
}

3)这是移动客户端适配器调用:

var getTagsRequest = new WLResourceRequest(
              "/adapters/UploadPic/getTagsForPicture",
              WLResourceRequest.POST);

              getTagsRequest.setQueryParameter("params", "['image']" );
              getTagsRequest.send().then(
                  getTagsSuccess,
                  getTagsFailure
              );

           function getTagsSuccess (result){
                console.log('Success, getTags is : ', result);
                q.resolve(result);
                WL.SimpleDialog.show(
                      "Got Tags", "You can continue using the application",
                      [{text: "OK, thanks", handler: function() {WL.Logger.debug("Got Tags"); }
                      }]
                );             
           };

           function getTagsFailure (result){
                console.log('Failure, getTags is : ', result);
                q.reject(result);
                WL.SimpleDialog.show(
                        "Got NO Tags", "Try it again later.",
                              [{text: "OK, thanks", handler: function() {WL.Logger.debug("Got NO Tags"); }
                              }]
           ); 
           }
           console.log("Tags*** ", q);
           return q.promise;

Chrome中的登录信息

{responseHeaders: Object, status: 500, responseText: "{"errors":["Unexpected error in server, see logs"],"isSuccessful":false,"warnings":[],"info":[]}", responseJSON: Object, invocationContext: null}
invocationContext:null
responseHeaders:Object
responseJSON:Object
responseText
:"{"errors":["Unexpected error in server, see logs"],"isSuccessful":false,"warnings":[],"info":[]}"
status:500

登录MFP Dev服务器:

Error   FWLST0904E: Exception was thrown while invoking procedure: getTagsForPicture in adapter: UploadPic
Date    Wednesday, Jun 1, 2016, 9:27 PM
Server  fe80:0:0:0:a65e:60ff:fedc:5a99%4
Security Level  Error
Source Class    com.ibm.mfp.server.js.adapter.internal.JavascriptManagerImpl
Source Method Name  
Logger Name com.ibm.mfp.server.js.adapter.internal.JavascriptManagerImpl
Thread ID   1743
Message FWLST0904E: Exception was thrown while invoking procedure: getTagsForPicture in adapter: UploadPic

Config.xml信息:

<procedure name="getTagsForPicture" secured="false"/>
<procedure name="uploadVacationInformationComplete" secured="false"/>
<procedure name="unprotected" secured="false"/>

1 个答案:

答案 0 :(得分:1)

我有拼写错误 MPF ,我找到了配置解决方案:

以下是javascript适配器的工作实现:

function getTagsForPicture(urlimage) {
   var value = "image=" + urlimage;
   MFP.Logger.warn("Image input " + value.toString());
   var requestStructure = {
        method : 'post',
        returnedContentType : 'xml',
        path : 'GetImageKeywords',
      parameters: {'image': urlimage },
      headers: {"Accept":"application\/plain"}
     };
   MFP.Logger.warn("Preparing request structure " + JSON.stringify(requestStructure));
   return MFP.Server.invokeHttp(requestStructure);
 }

在客户端内部出现与相关的错误(&#34;参数&#34;,&#34; [&#39;图像&#39;]&#34;)右侧一个是(&#34; params&#34;,[image])

var getTagsRequest = new WLResourceRequest(
              "/adapters/UploadPic/getTagsForPicture",
              WLResourceRequest.POST);

              getTagsRequest.setQueryParameter("params", [image] );
              getTagsRequest.send().then(
                  getTagsSuccess,
                  getTagsFailure
              );

           function getTagsSuccess (result){
                console.log('Success, getTags is : ', result);
                q.resolve(result);
                WL.SimpleDialog.show(
                      "Got Tags", "You can continue using the application",
                      [{text: "OK, thanks", handler: function() {WL.Logger.debug("Got Tags"); }
                      }]
                );             
           };

           function getTagsFailure (result){
                console.log('Failure, getTags is : ', result);
                q.reject(result);
                WL.SimpleDialog.show(
                        "Got NO Tags", "Try it again later.",
                              [{text: "OK, thanks", handler: function() {WL.Logger.debug("Got NO Tags"); }
                              }]
           ); 
           }