java.io.eofexception:ssl peer shut down incorrectly

可能是因为 1)https设置 2)超时设置

FeignConfig.java

复制代码
package zwf.service;

import java.io.IOException;
import java.io.InputStream;
import java.security.KeyStore;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;

import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLContexts;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import feign.Client;
import feign.Feign;
import feign.Request;
import feign.Retryer;

@Configuration
public class FeignConfig
{

	@Bean
	public Request.Options feignOptions()
	{
		int connectTimeoutMillis = 5 * 1000;
		int readTimeoutMillis = 5 * 1000;

		//请求连接超时,请求读取超时
		return new Request.Options(connectTimeoutMillis, readTimeoutMillis);
	}

	@Bean
	public Retryer feignRetryer()
	{

		long period = 100;
		long maxPeriod = 1000;
		int maxAttempts = 5;//最多尝试次数

		//
		return new Retryer.Default(period, maxPeriod, maxAttempts);
	}

	@Bean
	public Feign.Builder feignBuilder()
	{
		final Client trustSSLSockets = client();
		return Feign.builder().client(trustSSLSockets);
	}

	public static SSLSocketFactory feignTrustingSSLSocketFactory = null;

	@Bean
	public Client client()
	{
		if (feignTrustingSSLSocketFactory == null)
		{
			try
			{
				feignTrustingSSLSocketFactory = getFeignTrustingSSLSocketFactory();
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
		}
		Client client = new Client.Default(feignTrustingSSLSocketFactory, new NoopHostnameVerifier());
		return client;
	}

	public static SSLSocketFactory getFeignTrustingSSLSocketFactory() throws Exception
	{
		String passwd = "zengwenfeng";
		String keyStoreType = "zengwenfeng";
		
		InputStream inputStream = null;
		SSLContext sslContext = SSLContext.getInstance("SSL");
		try
		{
			inputStream = FeignConfig.class.getResourceAsStream("d://zengwenfeng.p12");
			KeyStore keyStore = KeyStore.getInstance(keyStoreType);
			keyStore.load(inputStream, passwd.toCharArray());
			sslContext = SSLContexts.custom().loadKeyMaterial(keyStore, passwd.toCharArray()).build();
		}
		catch (Exception e)
		{
			throw new RuntimeException(e);
		}
		finally
		{
			if (inputStream != null)
			{
				try
				{
					inputStream.close();
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
		}

		return sslContext.getSocketFactory();
	}
}
相关推荐
.格子衫.3 分钟前
Maven前奏
java·pycharm·maven
Mos_x18 分钟前
springboot系列--自动配置原理
java·后端
神奇侠202424 分钟前
基于spring-boot-admin实现对应用、数据库、nginx等监控
java·数据库·nginx
一叶飘零_sweeeet35 分钟前
手写 RPC 框架
java·网络·网络协议·rpc
脸大是真的好~2 小时前
黑马JAVAWeb-01 Maven依赖管理-生命周期-单元测试
java·maven
zhangkaixuan4563 小时前
Apache Paimon 查询全流程深度分析
java·apache·paimon
cici158744 小时前
MyBatis注解的运用于条件搜索实践
java·tomcat·mybatis
wangqiaowq4 小时前
StarRocks安装部署测试
java·开发语言
计算机学姐4 小时前
基于SpringBoot的高校社团管理系统【协同过滤推荐算法+数据可视化】
java·vue.js·spring boot·后端·mysql·信息可视化·推荐算法
工业甲酰苯胺8 小时前
实现 json path 来评估函数式解析器的损耗
java·前端·json