如何为工作海报 REST 调用定义 MFP javascript 适配器?
How to define the MFP javascript adapter for the working poster REST call?
我想编写一个与 Web 服务器通信的 MFP 适配器 (v8)。
服务器等待包含图像信息的参数图像。
移动客户端实现在 ionic cordova 中。
首先我检查了海报,这是正确的发送请求,但我找不到适合适配器的 configuration/implementation/call。
我做错了什么?
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 开发服务器:
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"/>
我有一个拼写错误 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);
}
客户端内部出现与 ("params", "['image']" ) 有关的错误,正确的是 ("params", [图片] ).
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"); }
}]
);
}
我想编写一个与 Web 服务器通信的 MFP 适配器 (v8)。 服务器等待包含图像信息的参数图像。 移动客户端实现在 ionic cordova 中。
首先我检查了海报,这是正确的发送请求,但我找不到适合适配器的 configuration/implementation/call。
我做错了什么?
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 开发服务器:
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"/>
我有一个拼写错误 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);
}
客户端内部出现与 ("params", "['image']" ) 有关的错误,正确的是 ("params", [图片] ).
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"); }
}]
);
}