Skip to content

Commit

Permalink
#2: Injecting correlation headers to RestTemplate #2
Browse files Browse the repository at this point in the history
  • Loading branch information
minkowp committed Aug 12, 2019
1 parent 951d08b commit 6b30cd6
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.logstash.logback.appender.LogstashTcpSocketAppender;
import net.logstash.logback.encoder.LogstashEncoder;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand All @@ -19,6 +20,7 @@
import pl.piomin.logging.filter.SpringLoggingFilter;
import pl.piomin.logging.util.UniqueIDGenerator;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand All @@ -36,6 +38,8 @@ public class SpringLoggingAutoConfiguration {
Optional<String> trustStoreLocation;
@Value("${spring.logstash.ssl.trustStorePassword:#{null}}")
Optional<String> trustStorePassword;
@Autowired(required = false)
Optional<RestTemplate> template;

@Bean
public UniqueIDGenerator generator() {
Expand Down Expand Up @@ -84,4 +88,13 @@ public LogstashTcpSocketAppender logstashAppender() {
return logstashTcpSocketAppender;
}

@PostConstruct
public void init() {
template.ifPresent(restTemplate -> {
List<ClientHttpRequestInterceptor> interceptorList = new ArrayList<ClientHttpRequestInterceptor>();
interceptorList.add(new RestTemplateSetHeaderInterceptor());
restTemplate.setInterceptors(interceptorList);
});
}

}

0 comments on commit 6b30cd6

Please sign in to comment.