I have a REST client interface like this:
public interface NameSearchClient {
@RequestLine("POST")
@Headers("Content-Type: application/json")
SearchResponse searchByName(NameSearchRequest request);
}
It gets implemented and set-up in a factory class like this:
@Component
public class NameClientFactory {
public <T> T createFeignClient(Class<T> clientClass, String apiUrl) {
return Feign.builder()
.encoder(new GsonEncoder())
.decoder(new GsonDecoder())
.target(clientClass, apiUrl);
}
}
I was wondering if it's possible to write an Aspect annotation that upon every call made by that client, executes some action (another HTTP call in my case) and adds a new header to the request? Is AspectJ the right tool for that?