androidodataodata4jsap-gateway

Consuming SAP NetWeaver Gateway Services from Android app


I am developing an application in Android which consumes OData services provided by SAP NetWeaver gateway, I am using Odata4J library for consuming services.

ODataConsumer consumer = ODataConsumers
 .create("https://sapes1.sapdevcenter.com/sap/opu/odata/IWFND/RMTSAMPLEFLIGHT/");

when I am hitting this URL from web browser, it prompts "Authentication Required" dialog box where I have to enter my username and password and after that I can see service document, schema document etc.

My question is: how can I pass credentials with my request using Odata4J? Do I receive any kind of token after successful authentication for authenticating further requests?


Solution

  • You can pass credentials with the call. OAUTH,SAML2,X509, Basic Auth etc.

    eg

       ODataConsumer.newBuilder(serviceUri).setClientBehaviors(OClientBehaviors.basicAuth(user,
       password)).build();
    
    
      //sorry this was the c# 
      var creds = username + ":" + password;
      var encodedCreds = Convert.ToBase64String(Encoding.ASCII.GetBytes(creds));
      requestHeaders.Add("Authentication", "Basic" + encodedCreds);
    

    Normally the system (if configured properly) will issue a MYSAPSSO2 cookie. This cookie can be re-sent with subsequent requests.

    search for Basic Auth and OdataConsumer, a few examples will show up.