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();
	}
}
相关推荐
北方有星辰zz9 分钟前
数据结构:栈
java·开发语言·数据结构
Seven9710 分钟前
一个static关键字引发的线上故障:深度剖析静态变量与配置热更新的陷阱
java
山野万里__12 分钟前
C++与Java内存共享技术:跨平台与跨语言实现指南
android·java·c++·笔记
风象南14 分钟前
Spring Shell命令行工具开发实战
java·spring boot·后端
Java技术小馆18 分钟前
POST为什么发送两次请求
java·面试·架构
天天摸鱼的java工程师19 分钟前
MySQL表设计实战指南:从业务场景到表结构优化
java·后端·mysql
SimonKing22 分钟前
Java处理PDF就靠它!Apache PDFBox:开源免费的PDF全能王
java·后端·程序员
天天摸鱼的java工程师26 分钟前
Java与AI:从业务场景到代码实现,构建人工客服系统实战
java·后端·面试
都叫我大帅哥28 分钟前
Redis中zset内存变形记
java·redis
slowlybutsurely34 分钟前
Cursor快速入门
java·ai编程·cursor