Hi On Thu, May 5, 2011 at 10:07 PM, Daniel Kulp <[email protected]> wrote: > On Thursday, May 05, 2011 3:59:40 PM Simon Chen wrote: >> Hi all, >> >> I am wondering how I can report progress back to the client about a >> long-running function? >> >> Say I have: >> >> @POST >> @Path("/setup") >> Response setup(...) { >> ... >> } >> >> The setup function may take a long time to finish. Returning a >> Response.ok() might be fine, but I'd prefer the client to see >> something in the middle... >> >> Thanks. >> -Simon > > With HTTP, the only real way to do it would be to grab the HttpServletResponse > and then send "100 Continue" responses back periodically. I'm not exactly > sure how that would be accomplished though as I've never really looked at it. > I haven't tried that either...May be worth experimenting with.
You may want to introduce some custom callback mechanism. Add @Oneway annotation or have client sending OnewayRequest HTTP header [1] and you'll get HTTP 202 once setup() has been invoked. Additionally, provide a callback URI (as part of POST request, in the request body or as header) and have setup() periodically reporting back. Another approach is get setup() delegate the execution to another application thread, and return immediately URI representing the resource which can be polled in order to get the setup status. Yet another approach is to use JMS: http://cxf.apache.org/docs/jax-rs-advanced-features.html#JAX-RSAdvancedFeatures-JMSSupport Cheers, Sergey [1] http://cxf.apache.org/docs/jax-rs-advanced-features.html#JAX-RSAdvancedFeatures-Onewayinvocations > > -- > Daniel Kulp > [email protected] > http://dankulp.com/blog > Talend - http://www.talend.com > -- Sergey Beryozkin Application Integration Division of Talend http://sberyozkin.blogspot.com
