@Bean public InitializingBean clientsCorrelationInitializer(final RequestCorrelationProperties properties) { return new InitializingBean() { @Override public void afterPropertiesSet() throws Exception { if(clients != null) { for(InterceptingHttpAccessor client : clients) { final List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>(client.getInterceptors()); interceptors.add(new ClientHttpRequestCorrelationInterceptor(properties)); client.setInterceptors(interceptors); } } } }; }
private static void addAuthHeaderToTemplate(RestOperations restTemplate, String token) { ClientHttpRequestInterceptor interceptor = new HeaderAddingHttpInterceptor("Authorization", "bearer " + token); ((InterceptingHttpAccessor) restTemplate).setInterceptors(singletonList(interceptor)); }
@Advice.OnMethodExit(inline = false) public static void onInterceptingHttpAccessorCreated(@Advice.This InterceptingHttpAccessor httpAccessor) { final TracingPlugin tracingPlugin = Stagemonitor.getPlugin(TracingPlugin.class); httpAccessor.getInterceptors().add(new SpringRestTemplateContextPropagatingInterceptor(tracingPlugin)); }