异步调用中cxf rest客户端中的异常处理

时间:2014-04-16 05:58:03

标签: web-services jax-rs cxfrs

我有一个方法“void deleteUser(User user)”公开为cxf jaxrs web服务。此void返回类型使其成为异步Web服务。我的deleteUser方法有时会抛出异常对象,我也需要在我的cxf jax-rs客户端中捕获该对象。但我在我的其余cxf客户端没有任何异常。 有没有办法可以捕获异步休息调用的异常。

1 个答案:

答案 0 :(得分:0)

您可以从响应对象访问。

Future<Response> response1 = null;
        try{
            response1 = client.async().get();
            Response response = response1.get();
            if(response.getStatus() == 200){
                // Success code here
                LOG.info("Returned with value: " + value);
            }else{
                LOG.info("Http request returned with status: "+ Status.fromStatusCode(response.getStatus()).getReasonPhrase()+ ", With error message "+ response.readEntity(String.class));
            }
        }catch(Exception ex){
            LOG.error("Errored", ex);
        }finally{
            if(client != null){
                client.close();
            }
        }
相关问题