[OTDev] Java Clients - Any suggestions?

Nina Jeliazkova nina at acad.bg
Fri Oct 2 15:42:48 CEST 2009


Hi Pantelis,

chung wrote:
> Hi Nina,
>
> On Thu, 2009-10-01 at 20:44 +0300, Nina Jeliazkova wrote:
>   
>> Hi Pantelis,
>>
>> You could simply use java.net.HttpURLConnection :
>>
>>             HttpURLConnection conn = (HttpURLConnection)
>>     url.openConnection();
>>             conn.setRequestMethod("GET");
>>             conn.setUseCaches(false);
>>             conn.setRequestProperty("Accept","chemical/x-daylight-smiles");
>>     
>
> Thanks for the code! Seems more convenient than org.apache.HttpClient! 
> Is there an easy way of retrieving ids out of a given URI? e.g. given
> "http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/8/compound/432" I want
> to get the dataset id "8". I tried out the following using restlet:
>
> Reference ref = new
> Reference("http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/8");
> String datasetId =  ref.getSegments().get(2) ; 
> String compoundId =  ref.getSegments().get(4) 
>
> Is there a better way of doing this with restlet?
Reference has methods to parse the URI, but I haven't used them yet.

Well, will it be better if we extend the API to return datasets compound
belongs to.   Could you tell what API functionality you would like to
have in this case?
>  How could I specify
> header information in restlet? 
>
>   
Headers in Restlet are accessible via
getRequest().getAttributes().get("org.restlet.http.headers"), although
for several standard headers there are specific method calls. For example :

            Request request = new Request();
            Client client = new Client(Protocol.HTTP);
            request.setResourceRef(uri);
            request.setMethod(Method.GET);
            request.getClientInfo().getAcceptedMediaTypes().add(new
    Preference<MediaType>(media));

Best regards,
Nina


      

> Best Regards,
> Pantelis
>
>   
>> Here is the code from our demo client earlier this year:  
>> https://ambit.svn.sourceforge.net/svnroot/ambit/branches/ambit-rest-client/src/main/java/ambit2/client/rest/Query.java
>>
>>
>> For more complex applications, Restlet is much more convenient.   Sun's
>> Jersey is another Java REST library https://*jersey*.dev.java.net . 
>> Have no experience wit Apache HttpClient.
>>
>> Best regards,
>> Nina
>>
>> chung wrote:
>>     
>>> Dear All,
>>>  Does anyone have some experience with clients written in Java. I want
>>> to perform a GET request specifying the header "Accept:text/xml". Can I
>>> do that using the HttpClient class
>>> ( http://hc.apache.org/httpclient-3.x/ ) or maybe restlet? Which Java
>>> library do you think would be a good choice? 
>>>
>>> Thank you in advance,
>>> Pantelis
>>>
>>> _______________________________________________
>>> Development mailing list
>>> Development at opentox.org
>>> http://www.opentox.org/mailman/listinfo/development
>>>   
>>>       
>> _______________________________________________
>> Development mailing list
>> Development at opentox.org
>> http://www.opentox.org/mailman/listinfo/development
>>     
>
> _______________________________________________
> Development mailing list
> Development at opentox.org
> http://www.opentox.org/mailman/listinfo/development
>   




More information about the Development mailing list