CorrelationID setting by 4financeIT

Below you can find people who helped to create this solution

Tomasz Nurkiewicz <tomasz.nurkiewicz@4finance.com>
Marcin Zajaczkowski <marcin.zajaczkowski@4finance.com>
Kamil Szymanski <kamil.szymanski@4finance.com>
Michal Chmielarz <michal.chmielarz@4finance.com>
Marcin Grzejszczak <marcin.grzejszczak@4finance.com>
Jakub Nabdralik <jakub.nabrdalik@4finance.com>
Urszula Choromanska <urszula.choromanska@4finance.com>
Tomasz Dziurko <tomasz.dziurko@4finance.com>
Tomasz Szymanski <tomasz.szymanski@4finance.com>
Adam Chudzik <adam.chudzik@4finance.com>
This commit is contained in:
Marcin Grzejszczak
2015-05-29 08:02:23 +02:00
committed by Marcin Grzejszczak
parent b5b3a21a88
commit dad0505d5a
36 changed files with 1825 additions and 51 deletions

View File

@@ -0,0 +1,46 @@
/*
* Copyright 2012-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.resttemplate;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.web.client.RestTemplate;
import java.util.List;
/**
* Default configure of {@code RestTemplate} that adds a list {@code ClientHttpRequestInterceptor}
* to {@code RestTemplate}
*
* @see ClientHttpRequestInterceptor
* @see RestTemplate
*
* @author Marcin Grzejszczak, 4financeIT
*/
public class DefaultRestTemplateConfigurer implements RestTemplateConfigurer {
private final List<ClientHttpRequestInterceptor> clientHttpRequestInterceptors;
public DefaultRestTemplateConfigurer(List<ClientHttpRequestInterceptor> clientHttpRequestInterceptors) {
this.clientHttpRequestInterceptors = clientHttpRequestInterceptors;
}
@Override
public void modifyRestTemplate(RestTemplate restTemplate) {
for (ClientHttpRequestInterceptor clientHttpRequestInterceptor : clientHttpRequestInterceptors) {
restTemplate.getInterceptors().add(clientHttpRequestInterceptor);
}
}
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2012-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.resttemplate;
import org.springframework.web.client.RestTemplate;
/**
* Interface that allows to modify the {@code RestTemplate} parameters
*
* @see RestTemplate
*
* @author Marcin Grzejszczak, 4financeIT
*/
public interface RestTemplateConfigurer {
void modifyRestTemplate(RestTemplate restTemplate);
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright 2012-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.resttemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.List;
/**
*
* Autoconfiguration that sets up a {@code RestTemplate} as a bean if one is not present
* and performs its additional modification via a {@code RestTemplateConfigurer}.
*
* @author Marcin Grzejszczak, 4financeIT
*/
@Configuration
@ConditionalOnWebApplication
@ConditionalOnProperty(value = "spring.cloud.sleuth.resttemplate.enabled", matchIfMissing = true)
public class SleuthRestTemplateAutoConfiguration {
@Configuration
protected static class RestTemplateConfig {
@Autowired
private List<ClientHttpRequestInterceptor> clientHttpRequestInterceptors = new ArrayList<>();
@Bean
@ConditionalOnMissingBean
public RestTemplate restTemplate() {
return new RestTemplate();
}
@Bean
@ConditionalOnMissingBean
public RestTemplateConfigurer restTemplateConfigurer(RestTemplate restTemplate) {
DefaultRestTemplateConfigurer configurer = new DefaultRestTemplateConfigurer(clientHttpRequestInterceptors);
configurer.modifyRestTemplate(restTemplate);
return configurer;
}
}
}

View File

@@ -0,0 +1,3 @@
# Auto Configuration
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.sleuth.resttemplate.SleuthRestTemplateAutoConfiguration