cancel
Showing results for 
Search instead for 
Did you mean: 

consuming oData web service and to post data using android native app

Former Member
0 Kudos

Hi,

In my application(Android native application using oData sdk libs) I`m able to invoke the Web Service (WS) URL (ie) all three urls  (service ,metadata and search) and also getting the result in auto invoked method onSuccess()

@Override

          public void onSuccess(ISDMRequest aRequest, HttpResponse aHttpResponse) {

                    Log.w(TAG,"-----onSuccess-------- getRequestUrl*********************> "+ aRequest.getRequestUrl());

                                String respBody = "";

                              try {

                                         final String entityString = EntityUtils.toString(aHttpResponse.getEntity());

                                        final int cLength = 400;

                                        final int len = entityString.length() < cLength ? entityString.length() : cLength;

                                        respBody = entityString.substring(0, len);

                                        Log.w(TAG, "-----onSuccess-------- ******EntityUtils***************> "+ respBody);

 

                                        if (aRequest.getRequestUrl().equals(serviceURL)) {

                                                  Log.e("onSuccess", "serviceURL");

                                                  dataServiceDocument = (SDMODataServiceDocument) this.getParser().parseSDMODataServiceDocumentXML(entityString);

                                        } else if (aRequest.getRequestUrl().equals(metadataURL)) {

                                                  Log.e("onSuccess", "metadataURL");

                                                  dataSchema = (SDMODataSchema) this.getParser().parseSDMODataSchemaXML(entityString, dataServiceDocument);

                                        } else if (aRequest.getRequestUrl().equals(searchURL)) {

                                                  Log.e("onSuccess", "searchURL");

                                                  List<ISDMODataEntry> entries = this.getParser().parseSDMODataEntriesXML(entityString, "DefectCollection",dataSchema);

                                                  System.out.println("SEUCESS ---------------------------- > "+ entries.size());

 

                                                  List<ISDMODataProperty> properties = entries.get(0).getPropertiesData();

                                                  System.out.println("properties -------size--------------------- > "+ properties.size());

   

                                        }

 

                              } catch (Exception e) {

                                        Log.e(TAG, "##Exception "+ e.getMessage());

                              }

                    

 

          }

Queries:

1) I would like to know difference way to parse the obtained xml using oData sdk.

2) And while posting how can we construct the post data as xml using oData sdk  , currently I`m posting by constructing/hard cording the  xml structure as String is will not be possible for huge data.

Kindly share some links/documents related to queries

Thanks 

Accepted Solutions (0)

Answers (1)

Answers (1)

rohith_deraje
Advisor
Advisor
0 Kudos

Hi Yougesh,

You can try constructing the request xls using one of the recieved entries.

// Declare the list as global Or store to catch.

static List<ISDMODataEntry> entries = null;

// Parse the data and store to list.

@Override
public void onSuccess(ISDMRequest aRequest, HttpResponse aResponse) {

  SDMLogger lg =  getLogger();
  String entriesXML = null;
  
  try {
   entriesXML = EntityUtils.toString(aResponse.getEntity(), "UTF-8");
  } catch (IOException e) {
   getLogger().e(TAG, "Entity conversion", e);
  }
 
  if(aRequest.getRequestUrl().equalsIgnoreCase(searchURL))
  {
  try {
   entries = getParser()
      .parseSDMODataEntriesXML(entriesXML, collectionId,
       getSchema());
 
  } catch (IllegalArgumentException e) {  

  } catch (SDMParserException e) {    
  }

  }

//   While building request get any of the entry and modify the properties.
ISDMRequest request = new SDMBaseRequest();
  request.setRequestMethod(ISDMRequest.REQUEST_METHOD_PUT);
  request.setRequestUrl(url);
  request.setListener(listener); 
  ISDMODataEntry entry = entries.get(0);
  entry.putPropertyValue("propertyName", "value");
     String xmlData= entry.toXMLString();
  byte[] data = null;
  try {
   data = xmlData.getBytes("UTF-8");
  } catch (UnsupportedEncodingException e) {
  
  } 
  request.setData(data);

 

Hope it work out.

Regards

Rohith

Former Member
0 Kudos

Hi Rohith,

Thanks for the reply,

1 ) I have tried to post the data by using your method but i`m getting an Error status code : 405,

but at the same time when I attempted with the same data using hard codded xml String I`m able to post the data to the server.

Have another doubt how can we get the  data from  received data xml,, using oData sdk

I`m able to read number of list data it contain by using below code.

entries = this.getParser().parseSDMODataEntriesXML(entityString, "DefectCollection",dataSchema);

System.out.println("LIST SIZE---------------------------- > "+ entries.size());

but how to access the list and get the individual data`s.have tried  some thing like this

entries.get(0).getPropertyValue(property.getName())

have used the above line but it ended up only getting null value , though that property has some value,so how can i parse and get the individual property value from obtained result xml?

Thanks

0 Kudos

Hi,

I am also facing the same. pls help me on this.

Regards,

Dinesh