users@jersey.java.net

[Jersey] Re: client, couchdb and long polling?

From: Martin Matula <martin.matula_at_oracle.com>
Date: Wed, 13 Jun 2012 10:30:39 +0200

Well, long polling should be easy - it is basically a regular HTTP request that blocks until a change is received. You may want to use AsyncWebResource for that. Any particular problem you are facing?

For receiving "Continuous Changes" (as defined in the article), it is a bit trickier - this is what chunking support in Jersey 2.0 was designed for but Jersey 1.x does not provide it out of the box. So, you'll have to do a bit more coding on your own. You would have to request the entity as InputStream and write a utility class on top of that input stream that reads bytes as they become available (plus it can use Jackson or some other JSON parser to convert them to POJOs and pass to some event handlers).
Martin

On Jun 12, 2012, at 10:37 AM, Kristian Rink wrote:

> Folks;
>
> interacting with an Apache CouchDB instance using the Jersey client, I see that things work pretty well except for one thing I so far did not manage to get working: CouchDB offers a way of "listening" for changes in a database using some sort of HTTP long polling [1]. Is there a sane, "clean" way how to work with this using Jersey 1.x? How do you handle things like these?
>
> TIA and all the best,
> Kristian
>
> [1]http://guide.couchdb.org/draft/notifications.html