Odata SDK SMP Configuration Develop App and Test


This blog is outdated, please follow the how to guides here:Mobile Application Development Platform for Developers – Native Apps

Creating Project and Importing Libraries

Create a new Android project in eclipse > Right click on libs folder and choose Import > General > File System. Browse to Odata SDK folder . The Odata SDK can be found inside the SMP SDK as given below.

ScreenHunter_162 Jun. 27 03.03.jpg

Choose the below libraries from column on the right and click on Finish.

Common, Connectivity, Coreservices, gson, Parser, perflib, Request and sap-e2etrace.

ScreenHunter_162 Jun. 27 03.04.jpg

Right click on the project and choose Build path > Configure Build Path, click on Libraries tab, then click on Add Jars. Select the project created from the list and go inside libs folder and choose all the jar files and click on OK.

Project after adding jar files:

ScreenHunter_162 Jun. 27 03.11.jpg


Initialize application

Login.java class will be called first in the project. The application has to be initialized when it starts first time.

Clientconnection parameters has to be set before registration. You can find the App ID and security name in the code below, that was created during SMP configuration.

String returnMsg = “success”;

  try

        {

  mApplication.setUsername(“P0000000000”);

  mApplication.setPassword(“Initial123”);

  ClientConnection clientConnection =

  new ClientConnection(getApplicationContext(),

  “com.test.android“,

  null,

  “SAPSecurity“,

  mApplication.getRequestManager());

  clientConnection.setConnectionProfile(true, “66.175.100.29”, “8080”, null, null);

         UserManager userManager = new UserManager(clientConnection);

         userManager.registerUser(true); //Registering user

Creating Request

After successful registration the control goes to the Registration_Success class. The service document and schema are accessed in this class. The Request manager makes HTTP requests to server. The requests are asynchronous, hence listeners to get the response. If the response of the request is success Onsuccess method is called else onError method.

public void onSuccess(IRequest aRequest, IResponse aResponse) {

  try {

  HttpEntity responseEntity = aResponse.getEntity();

  String responseString = EntityUtils.toString(responseEntity);

  Parser parser = mApplication.getParser();

  if (aRequest.getRequestTAG().contentEquals(REQUEST_SERVICE_DOCUMENT)) {

  mServiceDocument = parser.parseODataServiceDocument(responseString);

  } else if (aRequest.getRequestTAG().contentEquals(REQUEST_METADATA)) {

  IODataSchema schema = parser.parseODataSchema(responseString, mServiceDocument);

  mApplication.setODataSchema(schema);

  RequestBuilder.getInstance().setSchema(schema);

  }

  mSuccess = true;

  mHandler.post(mUpdateResults);

  } catch (ParseException e) {

  } catch (IOException e) {

  } catch (IllegalArgumentException e) {

  } catch (ParserException e) {

  }

public void onError(IRequest aRequest, IResponse aResponse,

  IRequestStateElement aRequestState) {

  //Post to UI Thread

  mSuccess = false;

  mHandler.post(mUpdateResults);

  }

  }

Parsing Data

In the DataAccess class a request is made with the collection ID “BusinessPartnerCollection” to retrieve the data based on a particular collection ID (In a browser it can be teste using the URL http://sapes1.sapdevcenter.com:8080/sap/opu/odata/iwbep/gwdemo/BusinessPartnerCollection).

Retrieve the data from the response using the parser.

public void onSuccess(IRequest aRequest, IResponse aResponse) {

  try {

  HttpEntity responseEntity = aResponse.getEntity();

  String responseString = EntityUtils.toString(responseEntity);

  Parser parser = mApplication.getParser();

  IODataSchema schema =mApplication.getODataSchema();

Entries = parser.parseODataEntries(responseString, “BusinessPartnerCollection”, schema);// Parsing Data

  mSuccess = true;

  mHandler.post(mUpdateResults);

  } catch (Exception e) {

  e.printStackTrace();

  }

  }

The value of the property can be accessed using the below code:

List poset = new ArrayList();

for(IODataEntry entry:Entries)

    {

           String Street = entry.getPropertyValue(“Company”).toString();// Company is a property in Odata

           poset.add(Street);

    }

The property “Company” is populated in a list view in Android.

android screen list.png

Download Source Code


Midhun VP

@midhunvptwit

To report this post you need to login first.

46 Comments

You must be Logged on to comment or reply to a post.

  1. Varahalu Babu Jampana

    Hi Midhun,

    Very Happy with your code and we are able to consume and display our OData from our service.

    But We are having issue with POST operation and we are using your buildPOSTRequest method in the RequestBuilder as follows

    private void postData() {

    IODataEntry entry = new ODataEntry();

    entry.putPropertyValue(“BankCountry”, “IN”);

    entry.putPropertyValue(“BankKey”, “00996”);

    entry.putPropertyValue(“BankName”, “UCUCUC”);

    entry.putPropertyValue(“City”, “Gajuwaka”);

    IRequest request = RequestBuilder.getInstance().buildPOSTRequest(this, “BankSet”, entry, “$format=json”);

    mApplication.getRequestManager().makeRequest(request);

    It throws Null at mApplication.getRequestManager().makeRequest(request);”

    Here mSchema is not null in buildPOSTRequest method. Am I wrong while requesting the Server?? Please suggest me with a code snippet to solve it.

    Regards,

    Varahalu Babu Jampana

    (0) 
  2. jyoti sahu

    hi midhun,

    I have downloded the source code but while extracting the file is giving error. please help me out.

    SMP3 android.PNG

    thanks & regards

    jyoti sahu

    (0) 
  3. Jared Commerford

    Hi Midhun,

    Is the IP you entered here the IP for the GW server or the SMP3.0 server?

    clientConnection.setConnectionProfile(true, “66.175.100.29“, “8080”, null, null);


    Regards

    Jared

    (0) 
      1. Jared Commerford

        Thank you Midhun.

        Continuing with the question though, am I correct in saying that if i’ve setup RSOE services on the SMP3.0 server to connect to the relay server I should be able to connect and register if I replaced the SMP server IP and Port with my relay servers IP and port 80?

        To setup the relay server for SMP 3.0 I followed the guide here : Configuring Relay Servers to Work with SAP Mobile Platform – Administrator – SAP Library

        The RSOE services are running and they are connected successfully to the relay server.

        Regards

        Jared

        (0) 
      2. Ranjith Lingala

        Hi Midhun,

        Excellent information for SMP 3.x Android native application development using SMP Native SDK 3.X. libraries.

        But in SMP 3.X SAP given user-on board using “MAF Logon” also, can you update/integrate the same application using “MAF Logon” that will be useful for everyone. Because it’s new feature and every one new to “MAF Logon” for user- on boarding.

        Thanks,

        Ranjith

        (0) 
        1. Midhun VP Post author

          Thanks Ranjith.

          I have plans to update the blog with MAFLogon and Relay server. Will update soon.

          Regards,

          Midhun VP

          (0) 
  4. vijay malik

    Thanks midhun , for a very great starting point .

    Can you suggest for the following fix when running your code ?

    “Could not find class ‘com.sap.mobile.lib.request.RequestManager’, referenced from method com.example.smp3android.AppInfo.getRequestManager “

    (0) 
    1. Midhun VP Post author

      Hi Vijay,

      It should work, you just need to extract it using winrar and import to android workspace>Run. I just tested it. I am on Android API 19. The SMP libraries inside libs folder.

      Regards,

      Midhun VP

      (0) 
        1. Varahalu Babu Jampana

          Hi vijay,            I guess you need to use “android-support-v7-appcompact” as a library project to your android project. It will available in your android installation folder..!!                                

          (0) 
            1. DURAI VENKATESH

              Hi Vijay,

                            I’M using your code Develop App and Test, SMP registration is done. But I dont know how to call get request? I want read the data. pls assist me.

              Regards,

              Durai,

              (0) 
      1. Juan David Lopez Gutierrez

        Hi Midhun,

        I append in the IRequest the filter query and this worked.

        IRequest request = RequestBuilder.getInstance().buildGETRequest(this, “Products?$filter=Rating gt 3“);

        I thought I should send it as an object or other parameter.

        Thanks for your help.

        Regards,

        Juan Lopez

        (0) 
      2. DURAI VENKATESH

        Hi Midun,

                      I’M using your code Develop App and Test, SMP registration is done. But I dont know how to call get request? I want read the data. pls assist me.

        Regards,

        Durai,

        (0) 
  5. DineshKumar R

    Hi Midhun,

    while initializing the application,

    in the following part

    try

            {

      mApplication.setUsername(“P0000000000”);

      mApplication.setPassword(“Initial123”);

      ClientConnection clientConnection =

      new ClientConnection(getApplicationContext(),

      “com.test.android”,

      null,

      “SAPSecurity”,

      mApplication.getRequestManager());

      clientConnection.setConnectionProfile(true, “66.175.100.29”, “8080”, null, null);

             UserManager userManager = new UserManager(clientConnection);

             userManager.registerUser(true); //Registering user

    i gave the ip and port of smp server ,id and security as declared in management cockpit  and the username ,password of the odata service URL, but i am getting an error security config does not exist.

    Please Advice.

    (0) 
      1. DineshKumar R

        Hi Midhun,

        Thanks for your reply.

        I have tried with the RestClient and i am able to register the user. While I tried with Android Native apps , it is showing [404]security config not found error.

        Pls help on this.

        (0) 
  6. Juan David Lopez Gutierrez

    Hi Midhun,

    I need make a Request of type PATCH Method. I changed:

    request.setRequestMethod(IRequest.REQUEST_METHOD_PATCH);

    but, How I can send data? The Gateway Service receives a table with multiple rows.

    Do you have a tutorial where explain this process?

    Regards,

    Juan Lopez

    (0) 
    1. Midhun VP Post author

      Hi Juan,


      Batch requests allow you to group multiple Odata requests into single HTTP request.

      GET, POST, PUT, DELETE requests can be added to a batch request. You have to manage it from the device code.

      Ex.

      private static final String ODATA_BATCH_VERB = “$batch”;

      //Create the Batch Request

      BatchRequest mBatchRequest = new BatchRequest(appEndPoint + ODATA_BATCH_VERB);

      mBatchRequest.setListener(this);

      mBatchRequest.setPriority(IRequest.PRIORITY_HIGH);

      //Create the Batch Request

      mBatchRequest.addRetrieveRequestToBatch(getRequest);

      mBatchRequest.addRequestToChangeset(deleteRequest);

      mBatchRequest.addRequestToChangeset(createRequest);

      mBatchRequest.addRequestToChangeset(updateRequest);

      //Close change Requests

      mBatchRequest.closeExistingChangeSet();

      //Execute the batch request

      requestManager().makeRequest(mBatchRequest);

      Regards, Midhun

      SAP Customer Experience Group – CEG

      (0) 
  7. DURAI VENKATESH

    Hi Midun,

                  I’M using your code Develop App and Test, SMP registration is done. But I dont know how to call get request? I want read the data. pls assist me.

    Regards,

    Durai,

    (0) 
      1. DURAI VENKATESH

        Hi Midhun,

                        Where did  u declared get request function in datascreen Class or Registration_Success Class. please tell me.

        Regards,

        Durai,

        (0) 
      2. DURAI VENKATESH

        Hi Midhun,

                       This is the get method. But it not working, I’m getting socket handling error.

        private void getData()

        {

         

          mProgressDialog =

          ProgressDialog.show(DataScreen.this,(CharSequence) “”,”Loading Data”,true);

          IRequest request = RequestBuilder.getInstance().buildGETRequest(this,”/CustProfile?$filter=Custid eq ‘0000220214’”);

          mApplication.getRequestManager().makeRequest(request);

        }

        (0) 
  8. DineshKumar R

    Hi Midhun,

    1. In Android with SMP3.x , How to validate the SAP users.

    2. Since for one application there will be many odata urls, Should we configure each OData url seperately in SMP cockpit?

    please advise

    (0) 
  9. DURAI VENKATESH

    Hi Midhun,

                        Here this is my get request code. when I click the getdata button, I’m getting FATAL EXCEPTION: SocketConnectionHandler #1 error and I don’t know this correct or not. please assist me.


    public IRequest buildGETRequest(INetListener listener, String collection, int topFilter, String filter ) {

    String query = “”;

    if (topFilter>0) query = ODATA_TOP_FILTER + topFilter;

    if (!TextUtils.isEmpty(filter)){

    if (!TextUtils.isEmpty(query)) query += “&”;

    query += ODATA_FILTER + filter;

    }

    IRequest request = new BaseRequest();

    request.setListener(listener);

    request.setPriority(IRequest.PRIORITY_HIGH);

    request.setRequestMethod(IRequest.REQUEST_METHOD_GET);

    String endPointURL = mEndPoint + collection;

    //Adding the JSON format

    if (mIsJSONFormat) {

    endPointURL = endPointURL + “?” + ODATA_JSON_FORMAT;

    }

    if (!TextUtils.isEmpty(query)) {

    if(endPointURL.contains(“?”))

    endPointURL = endPointURL + “&” + query;

    else

    endPointURL = endPointURL + “?” + query;

    }

    request.setRequestUrl(endPointURL);

    if (mIsMAFLogon) {

    Map<String,String> headers = new HashMap<String,String>();

    headers.put(APP_CONNECTION_ID_HEADER, mSMPAppConnectionID);

    request.setHeaders(headers);

    }

    return request;

    }


    @Override

      public void onSuccess(IRequest aRequest, IResponse aResponse) {

      try{

      HttpEntity responseEntity = aResponse.getEntity();

      String responseString = EntityUtils.toString(responseEntity);

      Parser parser = mApplication.getParser();

      IODataSchema schema = mApplication.getODataSchema();

      Entries = parser.parseODataEntries(responseString,”read_cust/odt/?$filter=IKunnr eq ‘55556667’”,schema);

      mSuccess = true;

      mHandler.post(mUpdateResults);

      }

      catch (Exception e)

      {

      e.printStackTrace();

      }

      }

    private void getData()

    {

    mProgressDialog = ProgressDialog.show(DataScreen.this,(CharSequence) “”, “Loading Data”, true);

    IRequest request = RequestBuilder.getInstance().buildGETRequest(this,”read_cust/?$filter=IKunnr eq ‘1000235’”);

    mApplication.getRequestManager().makeRequest(request);

    }

    (0) 
  10. DURAI VENKATESH

    Hi Midhun,

                     May I know which version of SMP did you used for that project because I’m using SMP 3 SP05. I’m downloaded that project and run in emulator when click the register button, registration is done. but next screen when click the GetData button, I’m getting Socket Handle Exception error. I dont know I’m give the input in correct place or not. please help me. below I mentioned that code please check it.

    With regards,

    Duraivenkatesh.R,

    (0) 
    1. DURAI VENKATESH

      Hi Midhun,

                      Do you know about MAF Logon and how to create MAF logon class and what are the jar files needed. please help me.

      with regards,

      Duraivenkatesh.R

      (0) 
        1. DURAI VENKATESH

          Hi Midhun,

                          I followed that guide only, But now I’m facing this error

          java.lang.UnsatisfiedLinkError: Couldn’t load stlport_shared from loader dalvik.system.PathClassLoader please help me.

          UnsatisfiedLinkError.png

          (0) 
  11. DURAI VENKATESH

    Hi Midhun,

                    I tried SMP3Android application registration is done. when I click the getdata button. I’m getting the SocketConnectionHandler error. I’m using SMP3 SP05 PL04.

    SocketConnectionHandler.png

    (0) 
  12. DineshKumar R

    Hi Midhun,

    By using the above code Registration with SMP and fetch the data from SAP are happened successfully with in corporate network.

    While trying same apps with outside network, Registration happened successfully, but not able to fetch the data from SAP.

    kindly advice.

    (0) 
    1. Midhun VP Post author

      Hi Saurabh,

      Your question is specific to Android. You can find many examples in the web on how to have multiple values in a list item.

      Regards, Midhun

      SAP Technology RIG

      (0) 
  13. Ana Velasquez

    Hi Midhun VP,

    At the moment I’m having a few issues with the Store concept and making a batch request, I’ve been recommended to update both, server and sdk to their latest version, I’m working with SDK SP05 and Server SP04, in the meantime, while these can be upgraded, I still have to make a batch request, do you think that it’s possible with Request Builder, or all its methods are deprecated?

    Thanks in advance.

    Best regards,

    Ana Velasquez

    (0) 

Leave a Reply