package com.ycl.feign;
|
|
import com.ycl.interceptor.HKFeignInterceptor;
|
import feign.Client;
|
import feign.Logger;
|
import feign.RequestInterceptor;
|
import feign.codec.ErrorDecoder;
|
import org.springframework.cloud.configuration.SSLContextFactory;
|
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Configuration;
|
|
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
import java.security.cert.CertificateException;
|
import java.security.cert.X509Certificate;
|
|
/**
|
*海康接口配置
|
*/
|
@Configuration
|
public class HKFeignConfig {
|
//跳过ssl验证
|
@Bean
|
public Client generateClient() {
|
try {
|
SSLContext ctx = SSLContext.getInstance("SSL");
|
X509TrustManager tm = new X509TrustManager() {
|
@Override
|
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
}
|
@Override
|
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
}
|
@Override
|
public X509Certificate[] getAcceptedIssuers() {
|
return null;
|
}
|
};
|
ctx.init(null, new TrustManager[]{tm}, null);
|
return new Client.Default(ctx.getSocketFactory(), (hostname, session) -> true);
|
} catch (Exception e) {
|
return null;
|
}
|
}
|
/**
|
* 调用异常处理
|
* @return
|
*/
|
@Bean
|
public ErrorDecoder errorDecoder() {
|
return new FeignErrorDecoder();
|
}
|
|
@Bean
|
Logger.Level feignLoggerLevel(){
|
return Logger.Level.FULL;
|
}
|
}
|