"HTTP request failed" when testing Android html5 (Eclipse + Phonegap) app....

Apr 9, 2013 at 5:14 PM
Hi, first of all, Im sorry for any grammar mistakes, english is not my native... Im really new in app development so Im going to try and explain this in the best way...

I create and app for Android using html5 code (generate by the SAP Gateway plugin for Eclipse), basically the app calls up a service URL located in a remote but accessible server (a SAP Gateway Server), when I run the app in a J2EE server from Eclipse it runs perfectly, the problem is when i run it as an Android app, both on the device or in the emulator, it loads me the Error "HTTP request failed"...

From the server side I think its all ok, I can manually acces de Odata from any broswer (both mobile and local) so I think is jsut a matter of configuration within the datajs or the app itself...

Doing some research I found that it may be a problem that can be fixed by adding the code:

OData.defaultHttpClient.enableJsonpCallback = true;

The problem is that I dont understand the base of the problem and where to add this code (if it is the potential fix)...

Any help would be apreciated...
Thanks!
Apr 9, 2013 at 8:45 PM
I manage to trace back the error by executing the app from a browser and using the Developer Tools, It seems that the error is 401 Unanthorized type, It seems (and it makes sense) that within the aplication itself theres no popup windows that ask for the credentials that need to be supplied for gaining access, I say it makes sense because the only way I can execute my app is when I do it on a J2EE server and thats executed trough the IE enviroment... Im kind of lost here, how do I tell my app the credentials if by default they are not being requested?

Thanks!
Coordinator
Apr 9, 2013 at 10:10 PM
Hi AndrueDLT,
  • In order to give the service the credentials, you can embed the values in the request in the form:
    OData.read({requestUri: [uri], user: [user], password: [password]}, successHandler, errorHandler);
  • In order to overcome the problem of using datajs in browsers other than IE ( the problem of same-origin policy), you can set OData.defaultHttpClient.enableJsonpCallback = true;
    And that is before issuing any request, which will use JonP for cross domain requests.
    For more info on the same-origin policy problem you can check these links:
    OData Security
    Cross Domain Requests

Regards,
Hussein
Apr 10, 2013 at 1:17 AM
Hi Hussein,

Thanks a lot for the response!

I checked both links and kind of understand more the problem now, Im trying to fix it by enabling the JSonCallBack because I dont like the idea of manually imposing it the credentials, mainly because I want to deploy this app in Android devices...

enabling JSonCallBack as follow:
OData.defaultHttpClient.enableJsonpCallback = true;
OData.read(request, successCallback, displayError);
Seems to work at the beggining, because I executed the app trough Chrome (Chrome throw me the HTTP request failed error before) and I finally got that credentials logon window, the problem is that It doesn't bring my data, after a while I get a Request timed error, tracing it with the Chrome Development Tools I found out that now the problem is with the callback made from the endpoint, as I get an 500 INTERNAL SERVER ERROR in te GET method. Executing it from IE directly now gives me the same error, when without the JSonCallBack worked just fine.

The request URL related is: "XXXXXXXXXXXXXXXXXXX?$callback=parent.handleJSONP_0&$format=json"

where XXXXXXXXX is the correct service URL...

Hope I gave enough information for tracing this issue, thanks again for your response! Any ideas?
Coordinator
Apr 10, 2013 at 5:56 PM
In order to understand the source of the issue and clear things more:
  • What is the DataServiceVersion of the service ?
  • What is the version of DataJS you are using ?

Regards,
Hussein
Apr 10, 2013 at 6:17 PM
Edited Apr 10, 2013 at 6:19 PM
Hi,

I´m using DataJS: datajs-1.0.2, the DataServiceVersion I´m not quite sure on how to find it out...

Doing more investigation (a lot more..) and test I found out that apprently (yet to be confirmed) the SAP Netweaver Gateway Services does not support JSONP or CORS so I think thats why I recieve this error, if thats the case then I´m going to need to focus the problem in other ways rather than using JSONP to go trough the cross-domain issue...

I have found several posible solutions (without using the JSON implementations) and I found out something like:

For the mobile development that we do we simply write the HTML5 application locally using an XAMPP and Apache's mod_proxy which is enabled by default. In the httpd--proxy.conf configuration I simply but the following line in...


But my knowleage about servers and related issues are really low, and I think this solution goes way over in topic for this post, although any help related would be welcome....

Any ideas?

Thanks for all the help...
Andres