views:

1057

answers:

2

Hello,

I need some help getting started with this.

I need to know how to call the REST service and parse the xml.

My php script only sends back some xmlcode, nothing else.(no wsdl or uddi)

The platform for the Nokia 5800 is S60 third edition.(that one will apply) The Nokia sdk go's by the same name. I installed Netbeans for this project.

The only stuff, that I find are soap based.

What methods/library's are at my disposal for this?

I have to mention that I am also new to java/netbeans.

thanks, Richard

+2  A: 

To call the REST webservice you can use the HttpConnection class:

HttpConnection connection = null;
InputStream is = null;

final ByteArrayOutputStream bos = new ByteArrayOutputStream();

byte[] response = null;

try {
    connection = (HttpConnection)Connector.open("http://api.yourserver.com/rest/things/12", Connector.READ);
    connection.setRequestMethod(HttpConnection.GET);

    connection.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.1");

    if (connection.getResponseCode() == HttpConnection.HTTP_OK) {
        is = connection.openInputStream();

        if (is != null) {
            int ch = -1;

            while ((ch = is.read()) != -1) {
                bos.write(ch);
            }

            response = bos.toByteArray();
        }
    }
} catch (Exception e) {
    e.printStackTrace();
} finally {
    try {
        if (bos != null) {
            bos.close();
            bos = null;
        }

        if (is != null) {
            is.close();
            is = null;
        }

        if (connection != null) {
            connection.close();
            connection = null;
        }
    } catch (Exception e2) {
        e2.printStackTrace();
    }
}

Now response will contain the XML your server spat out.

You can then use the kXML2 library to parse it. Note that this library references the XMLPull library, so you have to include that in your project.

Jacob H. Hansen
any chance JSR172 does the trick without requiring an additional library?
QuickRecipesOnSymbianOS
@JAcob, thanks for your input. I had more or less given up already on this post. This is very usefull. Now, at least I have a startingpoint. Just have to figure out wich library's I have to reference on top off the file. Also how to use the sdk with netbeans. Anyway, lots to figure out.
Richard
A: 

Hello,

I'm working with REST and with JSONObject's and JSONArrays with this library for Mobile Ajax in Java ME. Is an easy approach working on REST, the library need to be downloaded in source code format and compiled with Netbeans or ANT, it's easy, just check out the project via SVN and do a build in netbeans (WithXML or WithoutXML), in the page are samples using REST and public web services like Yahoo Maps! I hope you enjoy it.