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();
	}
}
相关推荐
€8111 分钟前
Java入门级教程17——利用Java SPI机制制作验证码、利用Java RMI机制实现分布式登录验证系统
java·开发语言·java spi机制·远程传输数据
2301_815357707 分钟前
parameterType和@Param注解的区别
java·开发语言·数据库
We....26 分钟前
Java 分布式缓存实现:结合 RMI 与本地文件缓存
java·分布式·缓存
2401_8454174533 分钟前
set和map
java·开发语言
所愿ღ38 分钟前
JavaWeb-Servlet总结及JSP
java·笔记·servlet
杨杨杨大侠39 分钟前
Atlas Mapper 教程系列 (4/10):高级映射技巧与类型转换
java·开源·github
杨杨杨大侠41 分钟前
Atlas Mapper 教程系列 (3/10):核心注解详解与基础映射
java·开源·github
tqs_123451 小时前
redis zset 处理大规模数据分页
java·算法·哈希算法
尚学教辅学习资料1 小时前
基于Spring Boot的家政服务管理系统+论文示例参考
java·spring boot·后端·java毕设
杨杨杨大侠1 小时前
Atlas Log 0.2.0 版本
java·github·apache log4j