如何使用Rest模板将TLS1.2强制为Rest客户端

编程入门 行业动态 更新时间:2024-10-27 21:14:42
本文介绍了如何使用Rest模板将TLS1.2强制为Rest客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我通过调用post方法使用Spring3.0 restTemplate使用json Webservice.

I am consuming json webservice using Spring3.0 restTemplate by calling post method.

MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>(); headers.add("Content-Type", MediaType.APPLICATION_JSON_VALUE); HttpEntity<Object> entity = new HttpEntity<Object>(requestAsString, headers); postForObject = restTemplate.postForObject(url, entity, responseClass );

我们的应用程序已部署在WAS服务器中,并尝试通过使用TLS1.0创建套接字连接来连接生产者.但是,现在生产者仅支持TLS1.1和TLS1.2.

Our application is deployed in WAS server and trying to connect producer by creating socket connection with TLS1.0. However, now producer only supports TLS1.1 and TLS1.2.

如何强制执行restTempate以使用TLS1.1或TLS 1.2.

How to enforce restTempate to use TLS1.1 or TLS 1.2.

通常对于apache httpclient代码,创建自定义ProtocolSocketFactory并覆盖createSocket方法.但是,在RestTemplate的情况下,该如何实现.

Normally for apache httpclient code , create custom ProtocolSocketFactory and override createSocket method. However , in case of RestTemplate , how to achieve same.

推荐答案

您可以将RestTemplate配置为使用自定义ClientHttpRequestFactory.特别是(因为您使用的是Spring 3.0),所以有一个 CommonsClientHttpRequestFactory .这样一来,您就可以详细配置通用HTTP,而RestTemplate将使用它来执行其请求.

You can configure your RestTemplate to use a custom ClientHttpRequestFactory. In particular (since you're using Spring 3.0), there is a CommonsClientHttpRequestFactory. That will enable you to configure commons HTTP in detail, and your RestTemplate will use that for executing its requests.

请注意,实际的实现类在Spring的更高版本中已更改(并且如果您仍使用3.0,则应该考虑更新).从3.1开始,实现类称为HttpComponentsClientHttpRequestFactory.

Please note that the actual implementation classes have changed in later versions of Spring (and if you're still on 3.0 you really should consider updating). From 3.1 on the implementation class is called HttpComponentsClientHttpRequestFactory.

更多推荐

如何使用Rest模板将TLS1.2强制为Rest客户端

本文发布于:2023-11-05 07:15:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560232.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   客户端   模板   Rest

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!