1

The adapter worked before and now the adapter does not work. Mobile Foundation 8.0 beta on my local machine and did a migration to MobileFirst Foundation 8.0 GA release.

The .java server send the image to alchemy and just returns the alchemy xml result to MobileFirst adapter.

The Debug information from Android and iOS are different, so I list both.

a) iOS MobileClient:

The information on the iOS is different from android. It seems there could be a bug in the cordova mfp-pluging implementation for XML adapter:

Because it seems the adapter expects a "responseJSON" in the response json structure, this is what I think, based on the debug information.. The response, with is show by xCode debugger automatically, does NOT contain "responseJSON", but it contains all valid values from the alchemy result.

Just take a look here in the xCode Debug output:

Reason the it sames

016-07-14 11:37:54.021 Check[5996:5470887] >>> Image to get Tags formParams :  [object Object]
2016-07-14 11:37:54.021 Check[5996:5470887] >>> Image to get Tags formParams :  [object Object]
2016-07-14 11:37:54.810 Check[5996:5470887] >>> Failure, getTags is :  [object Object]
2016-07-14 11:37:54.810 Check[5996:5470887] >>> Failure, getTags is :  {"responseHeaders":{"Connection":"Keep-Alive","Content-Type":"application/json","X-Powered-By":"Servlet/3.1","X-Backside-Transport":"FAIL FAIL","X-Global-Transaction-ID":"610291743","Date":"Thu, 14 Jul 2016 09:37:54 GMT","Transfer-Encoding":"Identity"},"status":500,"responseText":"{\"statusReason\":\"Internal Server Error\",\"responseHeaders\":{\"Transfer-Encoding\":\"chunked\",\"X-Backside-Transport\":\"FAIL FAIL\",\"Connection\":\"Keep-Alive\",\"X-Global-Transaction-ID\":\"78953555\",\"Content-Language\":\"en-US\",\"Date\":\"Thu, 14 Jul 2016 09:37:54 GMT\",\"Content-Type\":\"text/html;charset=UTF-8\",\"X-Powered-By\":\"Servlet/3.1\"},\"isSuccessful\":false,\"responseTime\":164,\"totalTime\":174,\"warnings\":[],\"errors\":[\"org.xml.sax.SAXParseException: The element type \\\"meta\\\" must be terminated by the matching end-tag \\\"</meta>\\\".\",\"Failed to parse the payload from backend (procedure: getTagsForPicture)\"],\"info\":[],\"statusCode\":500}","responseJSON":{"statusReason":"Internal Server Error","responseHeaders":{"Transfer-Encoding":"chunked","X-Backside-Transport":"FAIL FAIL","Connection":"Keep-Alive","X-Global-Transaction-ID":"78953555","Content-Language":"en-US","Date":"Thu, 14 Jul 2016 09:37:54 GMT","Content-Type":"text/html;charset=UTF-8","X-Powered-By":"Servlet/3.1"},"isSuccessful":false,"responseTime":164,"totalTime":174,"warnings":[],"errors":["org.xml.sax.SAXParseException: The element type \"meta\" must be terminated by the matching end-tag \"</meta>\".","Failed to parse the payload from backend (procedure: getTagsForPicture)"],"info":[],"statusCode":500},"errorCode":500,"errorMsg":"Request failed: internal server error (500)","invocationContext":null}
2016-07-14 11:37:54.814 Check[5996:5470887] ERROR GET TAGS***** [object Object]
2016-07-14 11:38:09.341 Check[5996:5470887] Response Content : {"statusReason":"OK","responseHeaders":{"Transfer-Encoding":"chunked","X-Backside-Transport":"OK OK","Connection":"Keep-Alive","X-Global-Transaction-ID":"336117367","Content-Language":"en-US","Date":"Thu, 14 Jul 2016 09:38:09 GMT","Content-Type":"text/xml;charset=ISO-8859-1","X-Powered-By":"Servlet/3.1"},"isSuccessful":true,"responseTime":2055,"totalTime":2057,"warnings":[],"results":{"totalTransactions":"4","NOTICE":"THIS API FUNCTIONALITY IS DEPRECATED AND HAS BEEN MIGRATED TO WATSON VISUAL RECOGNITION. THIS API WILL BE DISABLED ON MAY 19, 2017.","usage":"By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing to be bound by the AlchemyAPI Terms of Use: http://www.alchemyapi.com/company/terms.html","imageKeywords":{"keyword":[{"score":"0.574443","text":"large"},{"score":"0.5","text":"building"}]},"url":"","status":"OK"},"errors":[],"info":[],"statusCode":200}

b) Android MobileClient:

I get following error when I execute the javascript adapter XML from a cordova mobile android client.

1.  Array[2]
1.  0:"org.xml.sax.SAXParseException: The element type "meta" must be terminated by the matching end-tag "</meta>"."
2.  1:"Failed to parse the payload from backend (procedure: getTagsForPicture)"

The full error information in the chrome console for the android app:

enter image description here

When I inspect the XML on the server log or in a poster, I don’t see any information.

a) poster xml result:

enter image description here

b) .java server logs in bluemix:

enter image description here

The implementation of the Apdater and the MobileClient:

a) The adapter code:

function getTagsForPicture(urlimage) {
var value = "image=" + urlimage;

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);
}

b) The cordova client code:

 var formParams = {"params":"['"+ image + "']"}; 
 var getTagsRequest = new WLResourceRequest(
          "/adapters/UploadPic/getTagsForPicture",
          WLResourceRequest.POST);
          console.log('>>> Image to get Tags formParams : ', formParams); 

          getTagsRequest.sendFormParameters(formParams);
          getTagsRequest.send().then(
              getTagsSuccess,
              getTagsFailure
          );
  • 1
    I suggest to work with JSON. Because it is more natural to the JS and you won't have to worry about the meta tags etc.. In the AlchemyAPI you have the option to control the return type. – Ishai Jul 12 '16 at 07:48
  • @Ishai I agree, but I did not the server programming on the websphere liberty profile on the _.java server_ in Bluemix. So I must handle the XML and as I said, it worked before. I don't know why this XML appears. I tried to implement the Alchemy connection using a own node.js server, but here I have Troubles with the Image Stream and maybe to convert in the right _binary_ format. – Thomas Suedbroecker Jul 12 '16 at 09:45
  • @Ishai: Here I create a question related to the node.js post. http://stackoverflow.com/questions/38325741/how-to-post-a-image-correctly-to-alchemy-node-js-server – Thomas Suedbroecker Jul 12 '16 at 10:06
  • @ThomasSuedbroecker, if you suspect a bug in MobileFirst then remove the question and open a PMR instead. – Idan Adar Jul 22 '16 at 07:25
  • @IdanAdar The Problem is not related to **alchemy**, because a webapp on a _.java runtime in Bluemix_ provides the result from the alchemy service. I will create a PMR and when I got the confirmation it is a bug, I will remove the entry. – Thomas Suedbroecker Aug 08 '16 at 12:10
  • @ThomasSuedbroecker, any news? – Idan Adar Nov 01 '16 at 05:05

1 Answers1

1

I think the problem is related to the code in the client:

var formParams = {"params":"['"+ image + "']"}; 
var getTagsRequest = new WLResourceRequest(
      "/adapters/UploadPic/getTagsForPicture",
      WLResourceRequest.POST);
      console.log('>>> Image to get Tags formParams : ', formParams); 

      getTagsRequest.sendFormParameters(formParams);
      getTagsRequest.send().then(
          getTagsSuccess,
          getTagsFailure
      );

Because the getTagsRequest.sendFormParameters(formParams); does the same as getTagsRequest.send().then . I removed the getTagsRequest.send() with this result in the code:

  getTagsRequest.sendFormParameters(formParams);
  getTagsRequest.send().then(

After I changed the code in

sendRequest.sendFormParameters(formParams).send().then(
//sendRequest.send().then(
         sendSuccess,
         sendFailure
);

it worked.

@Thanks: To all persons who did provide feedback. Special to @Idan Adar.