Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Component
- public class RequestAttributeAwareCallableWrapper implements HystrixCallableWrapper {
- @Override
- public <T> Callable<T> wrapCallable(Callable<T> callable) {
- return new RequestAttributeAwareCallable<>(callable, RequestContextHolder.currentRequestAttributes());
- }
- private static class RequestAttributeAwareCallable<T> implements Callable<T> {
- private final Callable<T> callable;
- private final RequestAttributes requestAttributes;
- public RequestAttributeAwareCallable(Callable<T> callable, RequestAttributes requestAttributes) {
- this.callable = callable;
- this.requestAttributes = requestAttributes;
- }
- @Override
- public T call() throws Exception {
- try {
- RequestContextHolder.setRequestAttributes(requestAttributes);
- return callable.call();
- } finally {
- RequestContextHolder.resetRequestAttributes();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement