RestTemplate Request Logger
This package can be used to log request and response details of API calls made using Spring RestTemplates. The logs are stored in AWS DynamoDB using API Access Tracker (Backend). Please visit API Access Tracker (Backend) to setup AWS stack before using this package for logging your requests.
This package, provides a simple RestTemplate interceptor, to send request and response data to AWS stack using AWS SQS.
Usage
-
Setup your AWS stack as shown in API Access Tracker (Backend).
-
Include this package into your build:
- For Maven builds add below dependency to your pom.xml.
<dependency>
<groupId>com.actigence</groupId>
<artifactId>resttemplate-request-logger</artifactId>
<version>0.0.1</version>
</dependency>
- For Gradle add below dependency to your
build.gradle
file
compile group: 'com.actigence', name: 'resttemplate-request-logger', version: '0.0.1'
- To add RestTemplate interceptor to your project, create the RestTemplate bean as shown below.
@Configuration
public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate() {
ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory());
RestTemplate restTemplate = new RestTemplate(factory);
restTemplate.setInterceptors(singletonList(new OutboundRequestTrackingInterceptor()));
return restTemplate;
}
}
- Now whenever you access any URL using this RestTemplate bean. The request will be seamlessly intercepted by the
OutboundRequestTrackingInterceptor
class and an event will be published to the AWS SQS for storing that request and response.
Quote quote = restTemplate.getForObject(
"https://gturnquist-quoters.cfapps.io/api/random", Quote.class);
- See resttemplate-request-logger-demo for full example code.