Retrieving the Response from Backend

Retrieve the response from the backend to the device.

Server response will be obtained in the form of callbacks onError and onSuccess:
  • onError: public void onError(ISDMRequest arg0, ISDMResponse arg1, ISDMRequestStateElement arg2)
  • onSuccess: public void onSuccess(ISDMRequest aRequest, ISDMResponse aResponse)
On successful operation, onSuccess method will be invoked. Perform the following in onSuccess method to parse the response.
  1. Create the SDMParser object.
  2. Depending on the type of queried document (service document, metadata document, and so on).
/*Upon performing request using SDMRequestManager.makeRequest(SDMBaseRequest), the response will arrive at either public void onError(ISDMRequest arg0, ISDMResponse arg1, ISDMRequestStateElement arg2) {} or public void onSuccess(ISDMRequest aRequest, ISDMResponse aResponse) {} depending on whether the transaction was a failure or success respectively.
Add the following in the onSuccess() method: */

	HttpEntity responseEntity = aResponse.getEntity();
SDMParser parser = new SDMParser(mPreferences, mLogger);
/*The response parsing depends on the type of document queried*/
if(serviceDoc)
{
ISDMODataServiceDocument serviceDoc =
parser.parseSDMODataServiceDocumentXML(EntityUtils.toString(respons
eEntity));
}
else if(metadata)
{
ISDMODataSchema metaDoc =
parser.parseSDMODataSchemaXML(EntityUtils.toString(responseEntity),
serviceDoc);
}
else if(data)
{
List<ISDMODataEntry> dataSet =
parser.parseSDMODataEntriesXML(EntityUtils.toString(responseEntity)
, "CarrierCollection", metaDoc);
}

Consume the parse data.

/*Iterate through the entries and get the required fields*/
Iterator<ISDMODataEntry> iterator = dataSet.iterator();
while (iterator.hasNext())
{Map<String,String> propertyValues = iterator.next().getPropertyValues();
Log.i(“SMP”,propertyValues.get("CARRNAME")
+"\n"+propertyValues.get("carrid"));
}