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();
	}
}
相关推荐
风生u18 分钟前
activiti7 详解
java
岁岁种桃花儿27 分钟前
SpringCloud从入门到上天:Nacos做微服务注册中心(二)
java·spring cloud·微服务
Word码30 分钟前
[C++语法] 继承 (用法详解)
java·jvm·c++
TT哇36 分钟前
【实习 】银行经理端两个核心功能的开发与修复(银行经理绑定逻辑修复和线下领取扫码功能开发)
java·vue.js
逝水如流年轻往返染尘39 分钟前
Java中的数组
java
java1234_小锋1 小时前
Java高频面试题:BIO、NIO、AIO有什么区别?
java·面试·nio
用户8307196840821 小时前
Java IO三大模型(BIO/NIO/AIO)超详细总结
java
sheji34161 小时前
【开题答辩全过程】以 基于SSM的花店销售管理系统为例,包含答辩的问题和答案
java
Mr_sun.1 小时前
Day09——入退管理-入住-2
android·java·开发语言
MAGICIAN...2 小时前
【java-软件设计原则】
java·开发语言