I had a Feign Client created with SpringFramework openFeign, but wanted to hit the same rest end points with a different environment url. As I set the url at the annotation, wanted to check if there is some other way to do this.
Feign Client through Spring Framework Open Feign
@FeignClient(
value = "adminClient",
url = "${api.url}",
configuration = {AuthConfig.class}
)
public interface AdminClient {
@PostMapping("/api/testDomains/{domainName}/resources")
@Headers("Content-Type: application/json")
Resource addResource(
@RequestParam("domainName") String domainName,
Resource resource);
}
Application properties yaml file
domain:
url: https://test.com
url2: https://test2.com
AuthConfig class
@Bean("authenticatedHttpClient")
public HttpClient httpClientBuilder(@Value("${authenticator.type}") String authTYpe, @Value("${authenticator.key-tab.feign-path:#{null}}") String keytabPath, @Value("${authenticator.key-tab.principal:#{null}}") String keytabPrincipal) {
if (authTYpe.equalsIgnoreCase("current-user")) {
return SafeguardClients.forCurrentUser(true)
.create(HttpClientBuilder.class)
.withGsssoToken()
.build();
} else {
return SafeguardClients.forKeyTab(keytabPath, new KerberosPrincipal(keytabPrincipal))
.create(HttpClientBuilder.class)
.withGsssoToken()
.build();
}
}
@Bean
public Client client(@Qualifier("authenticatedHttpClient") final HttpClient clientBuilder) {
return new ApacheHttpClient(clientBuilder);
}