CXF-Proxy Client and @Suspended AsyncResponse

2019-08-02 15:28发布

问题:

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?