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();
	}
}
相关推荐
helloworld工程师10 分钟前
【微服务】SpringBoot整合LangChain4j 操作AI大模型实战详解
java·eclipse·tomcat·maven
Java&Develop11 分钟前
idea里面不能运行 node 命令 cmd 里面可以运行咋回事啊
java·ide·intellij-idea
q5673152329 分钟前
使用Java的HttpClient实现文件下载器
java·开发语言·爬虫·scrapy
你们补药再卷啦1 小时前
不用额外下载jar包,idea快速查看使用的组件源码
java·ide·intellij-idea
爱的叹息1 小时前
Spring Boot 自定义配置类(包含字符串、数字、布尔、小数、集合、映射、嵌套对象)实现步骤及示例
java·linux·spring boot
@西瓜@2 小时前
JAVAEE(多线程-线程池)
java·开发语言
returnShitBoy3 小时前
Go语言中的垃圾回收是如何工作的?
java·jvm·golang
有什么东东3 小时前
山东大学软件学院创新项目实训开发日志(9)之测试前后端连接
java
zhangpeng4555479403 小时前
用Java写一个MVCC例子
java·开发语言
谦行3 小时前
前端视角 Java Web 入门手册 5.1:真实世界 Web 开发——初识 Spring Boot
java·后端