cancel
Showing results for 
Search instead for 
Did you mean: 

HCPMS : HTTP request to backend system cannot return data

Former Member
0 Kudos

Hi colleagues,

I am encountering an error while querying the backend system from an Android application via HCP Mobile Services.

De   Detailed scenario 

  • A Cordova application deployed on an Android platform reads data from a web application via the Mobile services platform.
  • Web application deployed on HCP, running, contains data.
  • HCP account uses the default local service provider and the default trusted identity provider.
  • The application, at launch, successfully authenticates against the mobile services using basic authentication configuration. The username and password are correct.
  • After authentication, application sends successive Ajax queries to the mobile services, which redirects them to the backend system, in order to retrieve data. An error occurs on the first call.

The error: detailed 

  • Instead of the expected Json data, the following HTML is returned. The page is the same regardless of which client is used (Android app or Postman). (Apologies for the poor formatting, the "Insert Raw HTML" option isn't working too well).

<html>

    <head>

        <meta http-equiv="cache-control" content="no-cache" />

        <meta http-equiv="pragma" content="no-cache" />

    </head>

    <body style="background-color:#FFFFFF" onload="var url=window.location.hash;if(url&&0!==url.length){var anchorCookie='oucrswcyzlzsqgnrqjjsuklxd_anchor=&quot;'+encodeURIComponent(url)+'&quot;';document.cookie=anchorCookie}document.forms[0].submit()">

        <p>

            <script language="javascript">document.write("Please wait ...");</script>

        </p>

        <noscript>

            <p>Note: Your browser does not support JavaScript or it is turned off. Press the button to proceed.</p>

        </noscript>

        <form method="post" action="https://accounts.sap.com/saml2/idp/sso/accounts.sap.com">

            <input type="hidden" name="SAMLRequest" value="PEF1dGhuUmVxdWVzdCB4bWxucz0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOnByb3RvY29sIiB4bWxuczpuczI9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDphc3NlcnRpb24iIHhtbG5zOm5zMz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC8wOS94bWxkc2lnIyIgeG1sbnM6bnM0PSJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGVuYyMiIEFzc2VydGlvbkNvbnN1bWVyU2VydmljZVVSTD0iaHR0cHM6Ly9yb290YzUyMjc4MzB0c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obT0iaHR0cDovL3d3dy53My5vcmcvMjAwMS8xMC94bWwtZXhjLWMxNG4jIi8+PC9kczpUcmFuc2Zvcm1zPjxkczpEaWdlc3RNZXRob2QgQWxnb3JpdGhtPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwLzA5L3htbGRzaWcjc2hhMSIvPjxkczpEaWdlc3RWYWx1ZT5pVTRmNGhjblRYdEx2TytwMFErMnA4bGRKOVU9PC9kczpEaWdlc3RWYWx1ZT48L2RzOlJlZmVyZW5jZT48L2RzOlNpZ25lZEluZm8+PGRzOlNpZ25hdHVyZVZhbHVlPmJSYlNwTnBaUWhpN2ttcjRGM3ptZHZxZzBpbEZrTGt3L09qQ3Y3RndmYzFnLzFlQ1J5Y2Q0cUdxZGMyc2J6S3FWTXFFSjR1czY0ZFhrZ3FmMXg1TXZCdFFqcFRtekJETUxjc3lET1MyT09CS1hiMHAvNm11QWdsVk82dlFFdUpRdFlSd2Jaa2lZeWZkWThRTTF3SEMxRG1kK09WdERMNTlMUVNtWUJFbThSKzErNUw1VG8rME5MTGtkWmkrNEZHOTBFSXhrcXhFUy9admZMcW9RQ3VCdkZRSW1qV05NbUtJVDJad2ozVUFCR3d6Qjl4blhIRXNVeGF4ZXNIZlFZM0Rid3pJa2UycXFDUWVzRlV3eEFvV21ZZ2NSUkozSm1ZRE5SY1hwcnhCYkZQazdreUV3bExzQy9UMFFaLzFzVCttT011Q3Y2L0VCamFpSWRjZlprSk8rZz09PC9kczpTaWduYXR1cmVWYWx1ZT48L2RzOlNpZ25hdHVyZT48L0F1dGhuUmVxdWVzdD4="/>

            <input type="hidden" name="RelayState" value="oucrswcyzlzsqgnrqjjsuklxd"/>

            <noscript>

                <input type="submit" value="Continue"/>

            </noscript>

        </form>

    </body>

</html>

  • When run in a web browser, the HTML page redirects to the backend system URL, and then displays an error in Json format : “The request dispatcher does not allow the HTTP method used for the request”. The link to which the page redirects, when executed independently, returns the correct data from the backend system. The error, therefore, seems to be in the authentication of the mobile services system against the backend. The Javascript code which needs to be executed to authenticate cannot be run, seemingly.

What I have tried 

  • I have tried regenerating the authentication request, as detailed in this post : https://scn.sap.com/thread/3333160 , to no avail. This is not a "session expired after 30 minutes" issue.
  • Not a credentials issue (the authentication process cannot begin).
  • I tried setting the local service provider to "None" on HCP, and configuring the authentication type of the backend of the Mobile Services application to "No authentication", unsuccessfully.
  • I have ensured that the HTTP request header with key X-SMP-APPCID matched a key registered with the mobile services.
  • Different configuration scenarios for the Mobile Services application, with no differences in the Ajax query response.
  • I contacted the SAP ID services support team, this is not an issue with SAP ID.

I really don't know where to look anymore. Has anyone ever encountered this error?

Thanks,

Christopher.

Accepted Solutions (1)

Accepted Solutions (1)

midhun_vp
Active Contributor
0 Kudos

Hi Christopher,

What is the type of backend url configured for your app in HCPms admin portal? If it is an Odata service you could use an HTTP request to get the response then parse it and show the data easily. You could even use sapui5.

If the backend url is a non Odata service you have to find the way on how to make a request and get the response then parsing it to show the data in the app.

You could have a look at this blog on how to use Logon plugin and use Odata requests: If using SMP SDK SP09+:

Note: If you are using a non Odata service as backend url you will not get all the benefits of HCPms since the SDK is developed for Odata based data sources.

Regards, Midhun

SAP Technology RIG

Former Member
0 Kudos

Hi Midhun,

Yes, I am using an OData service. I am using SAP UI5 as well in fact. I think this is not so much related to the Logon plugin though, because my application can successfully register with the HCPms application. Each registration appears in the HCPms cockpit and I use the corresponding registration ID in the Ajax query. The error occurs when the HCPms application sends the Ajax query over to the backend system. The backend system requires a SAP ID authentication before it sends back any data and the Javascript needed for that to go through can't be executed. I can't figure out why.

midhun_vp
Active Contributor
0 Kudos

Hi Christopher,

I hope that you are sending the credentials and application connection ID with all the requests you are making. Could you provide the code you used.

There is a sample code on how to make an Odata request to a backend through SMP here: (specifically you have to look at the read() inside the file register3.html).

Regards, Midhun

SAP Technology RIG

Former Member
0 Kudos

Hi,

Yes, I do send the correct credentials and the application connection ID (or any one registered connection ID) in each request I make.

I had a look at that read() method. My way of sending the Ajax call was slightly different, but I was returned the same error when I tried the sample's way of doing it.

Here is my code :

function ajaxCall1(locId) {

     jQuery.ajax(

          {

               url: applicationContext.applicationEndpointURL + "/CompanyLocations?$format=json",

               type: 'GET',

               headers: oHeaders,

               contentType: 'application/json',

               async: false,

               success: function(data, textStatus, jqXHR) {

                    oResult.companyLocations = data.d.results;

                    ajaxCall2(locId);

               },

               error: function(responseData, textStatus, errorThrown){

                    alert("Error retrieving odata 1: " + responseData);

                    alert(textStatus);

                    alert(errorThrown);

               }

          }

     );

}

At debug time :

  • oHeaders = {Authorization: "Basic <private-base64encoded-uname-and-pw>", DataServiceVersion: "2.0", MaxDataServiceVersion: "2.0", X-SMP-APPCID: "<application connection ID>"}
  • The code fails in the success function, at line oResult.companyLocations = data.d.results; with message Uncaught TypeError: Cannot read property 'results' of undefined (the expected data return type is JSON and the HTML cannot be parsed)
  • The value of data, at that point, is the HTML page posted in my first message. readyState 4, status 200
midhun_vp
Active Contributor
0 Kudos

Hi Christopher,

This means that the response format is HTML. You have to find a way how to parse HTML. This is not related to Kapsel or SMP.

Are you sure that you are using Odata as end point url? Because Odata supports only two data formats: XML and JSON. It will not give you HTML response. Ref. http://www.odata.org/documentation/odata-version-2-0/json-format/

If you using a non Odata service as end point URL, you will not get all the benefits of HCPms.

Regards, Midhun

SAP Technology RIG

Former Member
0 Kudos

Hi Midhun,

I realise the answer is HTML. The answer is only HTML because the logon cannot be done. It is not supposed to be HTML. It is supposed to be JSON. Cf the backend link to which the mobile services redirect https://rootc5227830trial.hanatrial.ondemand.com/Services.svc/CompanyLocations?$format=json . This is the data that is supposed to be returned. It cannot be accessed because the logon failed, and therefore the HTML page on which the logon failed is returned.

midhun_vp
Active Contributor
0 Kudos

Hi Christopher,

Firstly, test this from a rest client to make sure you are able to register and get the data. Then you could test it from the app. You could follow this blog:

You have to double check the URL format.

Regards, Midhun

SAP Technology RIG

Former Member
0 Kudos

Midhun,

I have finally got it working! I am still not 100% sure what the reason was (perhaps a combination of different settings in the app that were wrong) but I think part of the issue was due to the wrong trust settings in HCP - it works with the following settings : default configuration type, and Enabled Principal propagation / Force authentication (not Default).

Thanks for your links, they were a great help.

Best regards,

Christopher

EDIT : I now know what did the trick. In the application configuration on HCP, by setting each of the Authentication configuration to "User name and password", I avoided the Javascript login mechanism and could therefore authenticate using the headers of the HTTP request.

Answers (2)

Answers (2)

Vlado
Advisor
Advisor
0 Kudos

Discussion successfully moved from SAP HANA Cloud Platform Developer Center to SMP Developer Center

KishoreKumarV
Advisor
Advisor
0 Kudos

Hello,

I am having an issue in consuming the backend odata in my hybrid android app. I have created an application in HCPms and the backend url -odata which I have created in the hcp xs applicaiton in my trial instance - https://s8hanaxs.hanatrial.ondemand.com/p1940680127trial/warroom/Esplanade/Esplanade/odata/Esplanade...

I enabled the basic authentication and saved my user credentials in the HCPms backend tab, when the metadata request is called from the component.js of app it is failing with an error - {message: "Failed to execute 'send' on 'XMLHttpRequest': Fail…anatrial.ondemand.com/com.kapsel.push/$metadata'.", request: undefined, response: undefined}

But the same application if i change my hcp odata service to ES1 -  http://sapes1.sapdevcenter.com:8080/sap/opu/odata/sap/ZGWSAMPLE_SRV/

with no other changes, this metadata call from the component.js is getting success 200ok.

I am not sure what is wrong, or is there any other way of handling hcp xs application odata service in hcpms.

Regards,

Kishore Kumar

Former Member
0 Kudos

Hello Kishore,

A quick google search of that error brings up quite a few possibilities. What status is returned?

KishoreKumarV
Advisor
Advisor
0 Kudos

Hello Christoper Neve,

There is no response as such.

The call is just failing.

Kishore Kumar