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. (6) 如何用Apache POI操作Excel文件-----POI-3.10的一个和注解(comment)相关的另外一个bug

    如果POI-3.10往一个工作表(sheet)里面插入数据的话,需要注意了,其有一个不太被容易发现的bug. 被插入的工作表(sheet)里面的单元格没有包含任何的注解(comment)的时候,插入一 ...

  2. Mybatis resultMap空值映射问题解决

    Mybatis在使用resultMap来映射查询结果中的列,如果查询结果中包含空值的列(不是null),则Mybatis在映射的时候,不会映射这个字段,例如 查询 name,sex,age,数据库中的 ...

  3. ThinkPHP 模板截取字符串 【转载】

    对于英文字符可使用如下形式(模板中): {$vo.title|substr=,} 如果是中文字符thinkphp提供了msubstr,用法如下: function msubstr($str, $sta ...

  4. BAT批处理(一)

    本文摘自博文<BAT批处理文件教程> 这是一篇技术教程,我会用很简单的文字表达清楚自己的意思,只要你识字就能看懂,就能学到知识.写这篇教程的目的,是让每一个看过这些文字的朋友记住一句话:如 ...

  5. Nginx 日志文件切割

    Nginx 是一个非常轻量的 Web 服务器,体积小.性能高.速度快等诸多优点.但不足的是也存在缺点,比如其产生的访问日志文件一直就是一个,不会自动地进行切割,如果访问量很大的话,将 导致日志文件容量 ...

  6. IoC容器装配Bean(xml配置方式)(Bean的生命周期)

    1.Spring管理Bean,实例化Bean对象 三种方式 第一种:使用类构造器实例化(默认无参数) package cn.itcast.spring.initbean; /** * 使用构造方法 实 ...

  7. 一个比较轻巧好用的js分页插件,可ajax可url

    var pageNav = pageNav || {}; pageNav.fn = null; pageNav.pre = "pre"; pageNav.next = " ...

  8. crucible3.x +fisheye3.x 安装和破解

    2015-11-24 22:29 423人阅读 评论(1) 收藏 举报  分类: linux(1)  版权声明:本文为博主原创文章,未经博主允许不得转载. 破解文件下载路径:http://downlo ...

  9. Redis学习笔记--五种数据类型的使用场景

    String 1.String 常用命令: 除了get.set.incr.decr mget等操作外,Redis还提供了下面一些操作: 获取字符串长度 往字符串append内容 设置和获取字符串的某一 ...

  10. HD 1003 Max Sum 的递归解法

    #include <STDIO.H> typedef struct SU_tag{ SU_tag(){} SU_tag(int a,int b,int c):max_sum(a),left ...