![](/img/trans.png)
[英]How to add dynamic header values to feign-client through Feign interceptor from current request?
[英]How to set HostnameVerifier in Feign-Client from spring-cloud-netflix-feign
我正在嘗試將Spring Cloud Feign Client設置為使用自定義HostnameVerifier。 我需要自定義HostnameVerifier來忽略證書問題。 我怎樣才能做到這一點?
這是我當前的配置:
@FeignClient(name = "AccountSettingsClient", url = "${account.settings.service.url}", decode404 = true,
configuration = AccountSettingsClientConfig.class, fallbackFactory = AccountSettingsClientFallbackFactory.class)
public interface AccountSettingsClient {
@RequestMapping(method = RequestMethod.GET, value = "/settings/{uuid}")
AccountSettings accountSettings(@PathVariable("uuid") String uuid);
}
@Component
@Slf4j
class AccountSettingsClientFallbackFactory implements FallbackFactory<AccountSettingsClient> {
@Override
public AccountSettingsClient create(Throwable cause) {
return uuid -> {
log.warn("Falling back to null.", cause);
return null;
};
}
}
@Configuration
@RequiredArgsConstructor
@EnableConfigurationProperties(SomeProperties.class)
@EnableFeignClients
public class AccountSettingsClientConfig {
private final SomeProperties someProperties;
@Bean
RequestInterceptor oauth2FeignRequestInterceptor() {
return new OAuth2FeignRequestInterceptor(new
DefaultOAuth2ClientContext(), resource());
}
}
默認情況下,會創建一個帶有HttpURLConnection的LoadBalancerFeignClient,並且不能覆蓋其HostnameVerifier的設置。 為了覆蓋它,選擇另一個客戶端,例如OkHttp或Apache Http Client,添加相應的maven依賴項,然后可以使用所有設置覆蓋該客戶端。
我選擇了OkHttpClient並添加到我的AccountSettingsConfig
跟隨bean:
@Bean
public okhttp3.OkHttpClient okHttpClient() {
return new OkHttpClient.Builder().hostnameVerifier((s, sslSession) -> true)
.build();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.