Benjamin Good wrote:
> If anyone else is having trouble reading and writing to the api from  
> java, please do let me know - think I've made it through most of the  
> cases.  The only one I haven't finished yet is the job of writing to  
> the connotea wiki from code.  Seems that it is possible to do that  
> via browser emulation (cookies etc.) but it would be cool if it was  
> added to the API.
> 

Hi Ben,

(To introduce myself: I'm a developer in the Emerging Technologies
Department at Nature.)

Just so you know, I'm just in the process of wrapping up a Java Connotea
API client. I haven't encountered any major problems implementing this
yet (fingers crossed ;D) ... there are a few small things that I was
going to summarize on this list as soon as I had wrapped the thing up,
but they were mainly questions to do with things like  "Why not HTTP
delete for remove?" etc.

Posting does work - my client is built on Restlet
(http://www.restlet.org/), which I can highly recommend and it will make
your task a million times simpler than using HttpURLConnection and
friends directly.

Here is a sample piece of code I wrote during development which works
for me and posts a link to Connotea via the API:


package org.connotea;

import org.restlet.Client;
import org.restlet.data.ChallengeResponse;
import org.restlet.data.ChallengeScheme;
import org.restlet.data.Form;
import org.restlet.data.Method;
import org.restlet.data.Parameter;
import org.restlet.data.Protocol;
import org.restlet.data.Reference;
import org.restlet.data.Request;
import org.restlet.data.Response;

public class Driver
{
    public static void main(String[] args) throws Throwable
    {
        Client client = new Client(Protocol.HTTP);

        Reference reference = new
Reference("http://www.connotea.org/data/add";);

        Request request = new Request(Method.POST, reference);

        ChallengeScheme challengeScheme = ChallengeScheme.HTTP_BASIC;
        ChallengeResponse challengeResponse = new ChallengeResponse(
                challengeScheme, "your_username", "your_password");
        request.setChallengeResponse(challengeResponse);

        Form form = new Form();
        form.add(new Parameter("uri", "http://www.nature.com/";));
        form.add(new Parameter("tags", "science journal"));
        form.encode();

        request.setEntity(form.getWebRepresentation());

        Response response = client.handle(request);
        System.out.println(response.getStatus());
    }
}

I hope to complete a beta of the Java client I am working on today, as
it happens, so you could just wait for that if you like. The above code
demonstrates how Java client is really working "under the hood", but it
provides a front-end and Connotea "domain objects" which encapsulate all
the currently implemented API methods for convenient use in your
applications.

All the best,

Chris

p.s. has anyone else noticed that if you pass an invalid (i.e.
unencoded) url to /data/remove you get a default server 404, whereas
doing the same with any of the gets returns an RDF response? Seems like
one to fix?


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Connotea-code-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/connotea-code-devel

Reply via email to