如何使用Rest模板将TLS1.2强制为Rest客户端 [英] How to enforce TLS1.2 to Rest client using Rest Template

查看:695
本文介绍了如何使用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),所以有一个

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客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆