jersey icon indicating copy to clipboard operation
jersey copied to clipboard

[Jersey-Client] Support for custom implementations of concurrency - Feature Request

Open dmartinsid opened this issue 8 years ago • 0 comments

In the current implementation of Jersey if we have a ThreadLocal and use async the only way to pass the ThreadLocal variables from the concurrent thread to async thread is with Invocation.Builder.property(String name, Object value), if we have a ClientRequestFilter, We can get this information in async Thread with ClientRequestContext.getProperty(String name), per example:

Call in original Thread

Future<Account> future = webTarget.path("/api/account/123") .request(MediaType.APPLICATION_JSON_VALUE) .property("requestContextHolder", RequestContextHolder.getRequestAttributes()) .async() .get(Account.class);

Filter that runs in async Thread

public void filter(final ClientRequestContext requestContext) throws IOException { RequestAttributes requestAttributes = (RequestAttributes) requestContext.getProperty("requestAttributes"); }

This way solves the problem, but is not elegant for a case that we need to set this information for different APIs calls. For this case would be nice if Jersey have a way to be more extensible, like HystrixConcurrencyStrategy, where we can define in one place what to copy from current thread to async thread or a place where we can fill ClientRequestContext with all the properties that we need in Async Thread for this request.

dmartinsid avatar Dec 27 '17 20:12 dmartinsid