HttpComponentsClientHttpRequestFactory

If you are using Spring MVC's RestTemplate to make REST calls, it is important to realize that it doesn't use HTTP connection pooling of any kind, and will establish and close a connection every time you make a REST call.

If you want to use connection pooling, you would need to provide another implementation of ClientHttpRequestFactory. A good option is to use the org.springframework.http.client.HttpComponentsClientHttpRequestFactory() which is provided with Spring.

new org.springframework.web.client.RestTemplate(new HttpComponentsClientHttpRequestFactory())
Of course, if you look up the documentation for HttpComponentsClientHttpRequestFactory, you can configure a lot of the connection pooling parameters.

https://coderwall.com/p/dcohra/connection-pooling-with-spring-resttemplate

http://stackoverflow.com/questions/25698072/simpleclienthttprequestfactory-vs-httpcomponentsclienthttprequestfactory-for-htt

org.springframework.http.client.SimpleClientHttpRequestFactory

java.net.Proxy

java.net.Proxy.Type

java.net.InetSocketAddress

org.springframework.web.client.RestTemplate

@Bean
public RestTemplate restTemplate() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); Proxy proxy= new Proxy(Type.HTTP, new InetSocketAddress("my.host.com", 8080));
requestFactory.setProxy(proxy); return new RestTemplate(requestFactory);
}

put these lines before calling your get or post method. so proxy get set .

    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
DefaultHttpClient httpClient = (DefaultHttpClient) requestFactory.getHttpClient();
HttpHost proxy = new HttpHost("proxtserver", port);
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
restTemplate.setRequestFactory(requestFactory);

http://stackoverflow.com/questions/3687670/using-resttemplate-how-to-send-the-request-to-a-proxy-first-so-i-can-use-my-jun 

Using RestTemplate, how to send the request to a proxy first so I can use my junits with JMeter?的更多相关文章

  1. 印象笔记无法同步问题解决 Unable to send HTTP request: 12029

    问题 今天突然发现本地软件不能访问网络. 包括: 印象笔记无法同步, 搜狗输入法无法登陆. 但其它上网正常. 思路及解决过程 因为chrome上网 ,qq上网均正常. 且同事可以正常使用. 推测是本地 ...

  2. windows elasticsearch搭集群启动失败failed to send join request to master....

    创建几份elasticsearch副本,修改各自config\elasticsearch.yml配置文件: 第一份: #允许elasticsearch跨域访问,使用elasticsearch-head ...

  3. How to resolve the 403 error when send POST request from Postman

    Root cause: the site refused the connection from the http request origin, by default it is setted as ...

  4. libeXosip2(1-1) -- How-To initialize libeXosip2.

    How-To initialize libeXosip2. The eXtented eXosip stack Initialize eXosip and prepare transport laye ...

  5. RFC3261--sip

    本文转载自 http://www.ietf.org/rfc/rfc3261.txt 中文翻译可参考 http://wenku.baidu.com/view/3e59517b1711cc7931b716 ...

  6. Spring RestTemplate介绍

    http://www.cnblogs.com/rollenholt/p/3894117.html RestTemplate 这篇文章打算介绍一下Spring的RestTemplate.我这边以前设计到 ...

  7. Spring RestTemplate 专题

    相同的参数(接口的入参json打印在日志了)在PostMan中返回预期的数据,但使用RestTemplate时去提示信息错误(参数中汉字).这种情况,搞得怀疑对RestTemplate的理解了使用Re ...

  8. bing---iis how to process http request

    http://msdn.microsoft.com/en-us/library/ms524901(v=vs.90).aspx http://msdn.microsoft.com/en-us/magaz ...

  9. Chrome Timeline的指标说明:Blocked、Connect、Send、Wait、Receive

    Blocked time includes any pre-processing time (such as cache lookup) and the time spent waiting for ...

随机推荐

  1. GC-垃圾回收

    代:0代,1代,2代: 所谓第几代,指经历过GC回收的次数. 回收算法: 1.确认需要检查的代. 在分配新对象时, 如果第0代已满,则进行检查:如果第1代已满,则进行检查:第2代同理: 如第0代没有足 ...

  2. svchost.exe是什么?为什么一直在运行

    原文:http://www.howtogeek.com/howto/windows-vista/what-is-svchostexe-and-why-is-it-running/ 自己简单翻译了下,图 ...

  3. Maven问题总结:could not resolve archetype xxxxxxx from any of the configured repositories

    错误提示 Eclipse中通过Archetype创建Maven项目时报错:Could not resolve archetype xxxxxxx from any of the configured ...

  4. mysql 导入导出.sql文件

    备份数据库(包含全部表和全部存储过程):C:\Documents and Settings\Administrator>mysqldump -h localhost -u root -p -R ...

  5. Failed to connect to remote VM. Connection refused. Connection refused: connect.

    eclipse debug启动经常出现这个错误,已经启动了debug进程,X掉重新启动即可.

  6. Xamarin学习资源收集

    推荐入门视频 跨行動平台App開發概觀- 使用Xamarin+Visual Studio https://www.youtube.com/watch?v=ELuFTTn1gS4 中文产品介绍http: ...

  7. LR中获取当前系统时间方法

    方法一:使用loadrunner的参数化获取当前时间使用lr的参数化,非常方便,对lr熟悉的各位朋友也能马上上手,时间格式也有很多,可以自由选择.步骤:1.将复制给aa的值参数化2.选中abc,使用右 ...

  8. MySQL并发调优和IO调优

    一.myisam的IO调优1.myisam通常在每次写入后把索引的改变刷写到磁盘上.所以批处理通常会更快点.做到这点,可以通过LOCK TABLES,他可以把写入控制到对表解锁.还可以用delay_k ...

  9. 【转】设计模式 ( 十七) 状态模式State(对象行为型)

    设计模式 ( 十七) 状态模式State(对象行为型) 1.概述 在软件开发过程中,应用程序可能会根据不同的情况作出不同的处理.最直接的解决方案是将这些所有可能发生的情况全都考虑到.然后使用if... ...

  10. zepto源码--width,height--学习笔记

    width和height函数,实际上通过css方法也完全可以取到这两个函数的结果.获取width,$elem.css('width');设置width的话,$elem.css('width', 100 ...