Reputation: 471
I want to write a MFP adapter (v8) which communicate with a Web-Server. The server waits for a parameter image containing image information. The mobile client implementation is in ionic cordova.
First I did a check in the Poster which is the right request to send, but I am not able to find the right configuration/implementation/call for the adapter.
What I am doing wrong?
1) This is the working copied poster call
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) And this is the not working MFP adapter implementation:
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) This is the mobile client side adapter call:
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;
Loginformation in 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
Log on the MFP Dev Server:
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 information:
<procedure name="getTagsForPicture" secured="false"/>
<procedure name="uploadVacationInformationComplete" secured="false"/>
<procedure name="unprotected" secured="false"/>
Upvotes: 1
Views: 1051
Reputation: 471
I had a spelling error MPF and I found the solution for the configuration:
Here is the working implementation of the javascript adapter:
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);
}
Inside the Client there was an error related to ("params", "['image']" ) the right one is ("params", [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"); }
}]
);
}
Upvotes: 1