restTemplate Invalid ‘expires‘ attribute: Sat, 18 Apr 2054 02:50:25 GMT、

服务器后台warning:

分析:

Sat, 18 Apr 2054 02:50:25 GMT、日期解析失败,使用标准的cookie解析方式

解决:

RequestConfig.custom().setConnectionRequestTimeout(connectRequestTimeout) .setConnectTimeout(connectTimeout).setSocketTimeout(socketTimeout) .setCookieSpec(CookieSpecs.STANDARD).build();

java 复制代码
	@Bean
	public RestTemplate restTemplate(@Autowired CloseableHttpClient closeableHttpClient) {
		return new RestTemplate(new HttpComponentsClientHttpRequestFactory(closeableHttpClient));
	}
	
@Bean
	public CloseableHttpClient closeableHttpClient() {
		return builder(connectTimeout, connectRequestTimeout, readTimeout);
	}

	private CloseableHttpClient builder(int connectTimeout, int connectRequestTimeout, int socketTimeout) {
		RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(connectRequestTimeout)
				.setConnectTimeout(connectTimeout).setSocketTimeout(socketTimeout)
				.setCookieSpec(CookieSpecs.STANDARD).build();

		return HttpClients.custom().setConnectionManager(get()).setDefaultRequestConfig(requestConfig)
				.setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy() {
					@Override
					public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
						long time = super.getKeepAliveDuration(response, context);
						if (time >= 0) {
							return time;
						}
						return keepAliveTime;
					}
				}).build();
	}

	private PoolingHttpClientConnectionManager get() {
		if (gcm != null) {
			return gcm;
		}
		synchronized (RestConfig.class) {
			Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
					.register("http", PlainConnectionSocketFactory.getSocketFactory())
					.register("https", SSLConnectionSocketFactory.getSocketFactory()).build();
			PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(registry);
			manager.setMaxTotal(maxTotal);
			manager.setDefaultMaxPerRoute(maxPerRoute);
			idleThread = new IdleConnectionMonitorThread(manager);
			idleThread.start();
			Runtime.getRuntime().addShutdownHook(new Thread() {
				@Override
				public void run() {
					idleThread.shutdown();
				}
			});

			gcm = manager;
		}
		return gcm;
	}

	// 监控有异常的链接
	private class IdleConnectionMonitorThread extends Thread {
		private final HttpClientConnectionManager connMgr;
		private volatile boolean exitFlag = false;

		public IdleConnectionMonitorThread(HttpClientConnectionManager connMgr) {
			this.connMgr = connMgr;
			setDaemon(true);
		}

		@Override
		public void run() {
			while (!exitFlag) {
				synchronized (this) {
					try {
						wait(2000);
					} catch (InterruptedException e) {
						Thread.currentThread().interrupt();
					}
				}
				// 关闭失效的连接
				connMgr.closeExpiredConnections();
				// 可选的, 关闭指定时间内不活动的连接
				connMgr.closeIdleConnections(30, TimeUnit.SECONDS);
			}
		}

		public void shutdown() {
			exitFlag = true;
		}
	}
复制代码

参考:

Spring Boot 无效的cookie标头:无效的"expires"属性 _大数据知识库

Invalid cookie header: "Set-Cookie: xxx", HttpOnly". Invalid 'expires' attribute报错说明-CSDN博客

HttpClient4 警告: Invalid cookie header 的问题解决_org.apache.http.client.protocol.responseprocesscoo-CSDN博客

相关推荐
计算机-秋大田几秒前
基于微信小程序的乡村研学游平台设计与实现,LW+源码+讲解
java·spring boot·微信小程序·小程序·vue
LuckyLay3 分钟前
Spring学习笔记_36——@RequestMapping
java·spring boot·笔记·spring·mapping
醉颜凉39 分钟前
【NOIP提高组】潜伏者
java·c语言·开发语言·c++·算法
阿维的博客日记44 分钟前
java八股-jvm入门-程序计数器,堆,元空间,虚拟机栈,本地方法栈,类加载器,双亲委派,类加载执行过程
java·jvm
qiyi.sky44 分钟前
JavaWeb——Web入门(8/9)- Tomcat:基本使用(下载与安装、目录结构介绍、启动与关闭、可能出现的问题及解决方案、总结)
java·前端·笔记·学习·tomcat
lapiii3581 小时前
图论-代码随想录刷题记录[JAVA]
java·数据结构·算法·图论
RainbowSea1 小时前
4. Spring Cloud Ribbon 实现“负载均衡”的详细配置说明
java·spring·spring cloud
程序员小明z1 小时前
基于Java的药店管理系统
java·开发语言·spring boot·毕业设计·毕设
夜色呦1 小时前
现代电商解决方案:Spring Boot框架实践
数据库·spring boot·后端
爱敲代码的小冰1 小时前
spring boot 请求
java·spring boot·后端