Issues and solutions to creating a client

Creating XML

The classes from the android SDK (javax.xml.parser, org.w3c.dom, org.xml.sax) are only made for parsing incomming xml files. An important trade indeed but this means we will either have to build our own using a string builder or finding some external lib.

Actually Android comes with the XMLSerializer classes provided by the java library. We use thoose now.

External libraries

XStream

XStream might be a solution:  http://xstream.codehaus.org/faq.html#Compatibility_Android
When adding the XStream jar and xpp jar to the buildpath, the compiler is issuing a bunch of warnings like this:

[2009-11-07 01:15:31 - drunkendroid]warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.)

Which kind off discourages me from experimenting further with the library.

I still did a unit test and the result of our stock entities Trip and Reading (as of 07-11-09) made up some xml which is very close to what the webservice wants to consume. This code is all i added. No kidding.

XStream xstream = new XStream();
xstream.alias("trip", Trip.class);
xstream.alias("event", Reading.class);		
<trip>
  <readings>
    <event>
      <date>
        <time>1255816133</time>
        <timezone>Europe/Paris</timezone>
      </date>
      <latitude>35.908422</latitude>
      <longitude>14.502362</longitude>
      <mood>110</mood>
    </event>
    <event>
      <date reference="../../event/date"/>
      <latitude>35.909141</latitude>
      <longitude>14.50358</longitude>
      <mood>95</mood>
    </event>
    <event>
      <date reference="../../event/date"/>
      <latitude>35.909275</latitude>
      <longitude>14.502825</longitude>
      <mood>62</mood>
    </event>
  </readings>
  <startDate>
    <time>1255816133</time>
    <timezone>Europe/Paris</timezone>
  </startDate>
</trip>

Connecting to the server

We started out using RESTLet 2.0 M5 for Android, but because of a bad experience(RESTLetClient) with the DomRepresentation class, we started looking for alternatives to the client. It seems that the apache HttpClient library might do the job. As it has worked for other people, and is the text book example in all the Android Books we have looked in (Unlocking Android, Beginning Android).

An example of a put operation using apache HttpClient:
 http://www.smnirven.com/?p=15

Handling the connection to the server

I believer we should set up some kinda queueing system which handles the uploading of events to the server. We might end up in a situation where only parts of the data is uploaded before the application is closed or the dataconncetion is lost. Right now we don't handle those situations. We should!