|
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 |
|
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 |
|
Hi Martin;
and thanks a bunch for your thoughts on that. Am 13.06.2012 10:30, schrieb Martin Matula: > 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? No, none yet. Thanks for pointing me there. So far I have never been in need to use Jersey/JAX-RS for anything asynchronous so I so far simply haven't tried. ;) > 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). Imagined something like this already, but wanted to check first whether there already is a solution at hand for that problem provided by the framework out of the box. I'll look into both doing it on my own and seeing whether/how Jersey 2.0 prereleases do about this. :) Thanks again and all the best, Kristian |
| Powered by Nabble | Edit this page |
