Reputation: 11
I started using https instead of http in my microservice architecture application. When a request is made with Feign Client, it uses http instead of https.
I created the following class which configures ssl for Feign but it is not working.
@Bean
public Feign.Builder feignBuilder() throws Exception {
return Feign.builder()
.retryer(Retryer.NEVER_RETRY)
.client(feignClient());
}
private SSLSocketFactory createSSLContext() throws Exception {
String trustStorePath = "/home/kaan/NetBeansProjects/SociMedia/BlockService/src/main/resources/truststore.jks";
String keyStorePath = "/home/kaan/NetBeansProjects/SociMedia/BlockService/src/main/resources/keystore.jks";
String pass = "pass";
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(new FileInputStream(ResourceUtils.getFile(keyStorePath)), pass.toCharArray());
SSLContext context = SSLContextBuilder.create()
.loadTrustMaterial(ResourceUtils.getFile(trustStorePath), pass.toCharArray())
.loadKeyMaterial(keyStore, pass.toCharArray())
.build();
return context.getSocketFactory();
}
@Bean
public Client feignClient() throws Exception {
return new Client.Default(createSSLContext(), org.apache.http.conn.ssl.SSLConnectionSocketFactory.getDefaultHostnameVerifier());
}
@Bean
public Decoder feignDecoder(ObjectFactory<HttpMessageConverters> converters) {
return new ResponseEntityDecoder(new SpringDecoder(converters));
}
@Bean
public Encoder feignEncoder() {
return new SpringFormEncoder();
}
I use this class every feign client interface as configuration parameter.
When I access the https://192.168.1.59:9090/v1/user/get?id=2 endpoint, I get the following error:
BlockService executing GET http://BlockService/v1/block/blocked?userId1=25&userId2=2 feign.RetryableException: BlockService executing GET http://BlockService/v1/block/blocked?userId1=25&userId2=2
Upvotes: 1
Views: 104