Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1.  
  2. @Component
  3. public class RequestAttributeAwareCallableWrapper implements HystrixCallableWrapper {
  4.  
  5.     @Override
  6.     public <T> Callable<T> wrapCallable(Callable<T> callable) {
  7.         return new RequestAttributeAwareCallable<>(callable, RequestContextHolder.currentRequestAttributes());
  8.     }
  9.  
  10.     private static class RequestAttributeAwareCallable<T> implements Callable<T> {
  11.  
  12.         private final Callable<T> callable;
  13.         private final RequestAttributes requestAttributes;
  14.  
  15.         public RequestAttributeAwareCallable(Callable<T> callable, RequestAttributes requestAttributes) {
  16.             this.callable = callable;
  17.             this.requestAttributes = requestAttributes;
  18.         }
  19.  
  20.         @Override
  21.         public T call() throws Exception {
  22.  
  23.             try {
  24.                 RequestContextHolder.setRequestAttributes(requestAttributes);
  25.                 return callable.call();
  26.             } finally {
  27.                 RequestContextHolder.resetRequestAttributes();
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement