Last active
August 29, 2015 14:01
-
-
Save danielbryantuk/9446b5887c170e98b259 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class CorrelatingRestClient implements RestClient { | |
private RestTemplate restTemplate = new RestTemplate(); | |
@Override | |
public String getForString(String uri) { | |
String correlationId = RequestCorrelation.getId(); | |
HttpHeaders httpHeaders = new HttpHeaders(); | |
httpHeaders.set(RequestCorrelation.CORRELATION_ID, correlationId); | |
LOGGER.info("start REST request to {} with correlationId {}", uri, correlationId); | |
//TODO: error-handling and fault-tolerance in production | |
ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.GET, | |
new HttpEntity<String>(httpHeaders), String.class); | |
LOGGER.info("completed REST request to {} with correlationId {}", uri, correlationId); | |
return response.getBody(); | |
} | |
} | |
//... calling Class | |
public String exampleMethod() { | |
RestClient restClient = new CorrelatingRestClient(); | |
return restClient.getForString(URI_LOCATION); //correlation id handling completely abstracted to RestClient impl | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment