Opensearch Support.

2 views
Skip to first unread message

Jose Donizetti

unread,
Feb 19, 2011, 8:21:35 PM2/19/11
to restfu...@googlegroups.com
Hi, I've been implementing the opensearch support on the java version, though it's finished I'm not happy with the code.
Here is an example of how it is working:


Response response = restfulie.at("http://localhost:3000/products/opensearch.xml").accept("application/opensearchdescription+xml").get();
SearchDescription desc = response.getResource();
response = restfulie.at(desc.use("application/xml").atPage(page).search("20").getUri()).get();
// above in bold is the part I'm not happy is to need to recover the uri, so that I can make the search request!
// it would be better to be as below
response  = desc.use("application/xml").atPage(page).search("20").get();

But to do that I would have to couple an instance of Restfulie.custom() inside SearchDescription, what would be ugly to test and been a new instance
of the client it wouldn't have the information prior registered on the MediaTypes. It could be easily done by declaring RestClient to be an dependency at
the SearchDescription constructor, but this object is created by xstream and I'm not sure it is able to make some DI.
What do you think?

doni.

Guilherme Silveira

unread,
Feb 22, 2011, 10:13:20 AM2/22/11
to restfu...@googlegroups.com
Hi Doni,

You are right. What about renaming "getUri" to "toUri"?
What is the "atPage"? Is it the query term? If so, it should be
something as "queryFor(...)"

The get() method should use the same Restfulie instance that retrieved
the response on the last request, so you can test it invoked the
correct methods. You are right, you will need to add a custom
converter for search description, thats all... tjust take a look at
the xstream converter tutorial, it should solve it.

We can also enhance it later to do:
desc.use('application/xml').with(queryFor("guilherme")).and(page(2))

Well done!

Regards

Guilherme Silveira
Caelum | Ensino e Inovação
http://www.caelum.com.br/

Reply all
Reply to author
Forward
0 new messages