CXF-Proxy Client and @Suspended AsyncResponse

核能气质少年 提交于 2019-12-11 09:24:38

问题


I recently learned that with JAX-RS 2.0 long running service endpoints can make use of the @Suspended annotation and AsyncResponse to free resources for incoming requests while the actual work is done in the background. All client examples - at least the ones I found so far - are either calling such endpoints directly (plain http-call) or make use of the JAX-RS client API. However I was not able to figure out how to use this with the proxy-based API.

Given a REST endpoint that uses @Suspended:

public interface HeavyLiftingService {
  @GET
  @Path("/heavylifting")
  public void heavyLifting(@Suspended final AsyncResponse aResponse);
}

its implementation using Spring:

@Component
public class HeavyLiftingServiceImpl implements HeavyLiftingService {
  @Override
  @Async
  public void heavyLifting(@Suspended final AsyncResponse aResponse) {
    final Result result = doHeavyLifting();
    aResponse.resume(result);
  }
}

And a proxy-based client, that wants to obtain the result:

HeavyLiftingService proxy = JAXRSClientFactory.create("https://some-server.xyz", HeavyLiftingService.class);
proxy.heavyLifting(null); // what to put in here?
Result result = null; // how can I get the result?

Obviously there are two problems:

  1. What do I need to provide to the heavyLifting method as value for the AsyncResponse parameter?
  2. How can I get the result as the return type of methods using @Suspended has to be void?

And another question is how exceptions in the service method are handled. Will an exception automatically resume the response and return a corresponding error status?

来源:https://stackoverflow.com/questions/42845219/cxf-proxy-client-and-suspended-asyncresponse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!