You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by David L <lg...@hotmail.com> on 2011/06/03 16:06:39 UTC

Handling response - Invoking web services asynchronously

Hi all,

What is the best practice for handling async call response?
Below is what I do normally,

new AsyncHandler<MyResponse>() {
    @Override
    public void handleResponse(Response<MyResponse> res) {
        try {
            MyResponse v = res.get();
            // process v ...
        }catch (Exception e) {
            // log the exception
        }
    }
}

Do I need to check isCancelled() or isDone() before I call get()?

If the web service method is of type void, do I still need to call get()?
If I don't call get(), will I miss out any errors?
For example, exceptions are only thrown when get() is called.

Best regards,

David
 		 	   		  

Re: Handling response - Invoking web services asynchronously

Posted by Daniel Kulp <dk...@apache.org>.
On Friday, June 03, 2011 10:06:39 AM David L wrote:
> Hi all,
> 
> What is the best practice for handling async call response?
> Below is what I do normally,
> 
> new AsyncHandler<MyResponse>() {
>     @Override
>     public void handleResponse(Response<MyResponse> res) {
>         try {
>             MyResponse v = res.get();
>             // process v ...
>         }catch (Exception e) {
>             // log the exception
>         }
>     }
> }
> 
> Do I need to check isCancelled() or isDone() before I call get()?

No.  Those are both checked internally.  (well, get will wait until isDone 
would be true and then return the result).


> If the web service method is of type void, do I still need to call get()?
> If I don't call get(), will I miss out any errors?

You would, yes.   The exceptions are only thrown from the get call.

Dan


> For example, exceptions are only thrown when get() is called.
> 
> Best regards,
> 
> David

-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
Talend - http://www.talend.com