Using RestTemplate, how to send the request to a proxy first so I can use my junits with JMeter?
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?的更多相关文章
- 印象笔记无法同步问题解决 Unable to send HTTP request: 12029
问题 今天突然发现本地软件不能访问网络. 包括: 印象笔记无法同步, 搜狗输入法无法登陆. 但其它上网正常. 思路及解决过程 因为chrome上网 ,qq上网均正常. 且同事可以正常使用. 推测是本地 ...
- windows elasticsearch搭集群启动失败failed to send join request to master....
创建几份elasticsearch副本,修改各自config\elasticsearch.yml配置文件: 第一份: #允许elasticsearch跨域访问,使用elasticsearch-head ...
- 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 ...
- libeXosip2(1-1) -- How-To initialize libeXosip2.
How-To initialize libeXosip2. The eXtented eXosip stack Initialize eXosip and prepare transport laye ...
- RFC3261--sip
本文转载自 http://www.ietf.org/rfc/rfc3261.txt 中文翻译可参考 http://wenku.baidu.com/view/3e59517b1711cc7931b716 ...
- Spring RestTemplate介绍
http://www.cnblogs.com/rollenholt/p/3894117.html RestTemplate 这篇文章打算介绍一下Spring的RestTemplate.我这边以前设计到 ...
- Spring RestTemplate 专题
相同的参数(接口的入参json打印在日志了)在PostMan中返回预期的数据,但使用RestTemplate时去提示信息错误(参数中汉字).这种情况,搞得怀疑对RestTemplate的理解了使用Re ...
- 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 ...
- Chrome Timeline的指标说明:Blocked、Connect、Send、Wait、Receive
Blocked time includes any pre-processing time (such as cache lookup) and the time spent waiting for ...
随机推荐
- 让apache不区分图片和文件后缀大小写
加载mod_speling模块: LoadModule speling_module /usr/lib/apache2/modules/mod_speling.so 开启模块: CheckSpelli ...
- Data Plane Development Kit (DPDK): Getting Started
参考:dpdk getting started 系统: Ubuntu 14.04 内核信息: 执行 uname -a Linux chen-VirtualBox 3.13.0-32-generic # ...
- PHP 错误与异常 笔记与总结(11 )register_shutdown_function() 函数的使用
通过 register_shutdown_function 方法,可以让我们设置一个当执行关闭时可以被调用的另一个函数. 也就是说,当我们的脚本执行完成或者意外死掉导致 php 执行即将关闭时,我们的 ...
- Yii源码阅读笔记(三)
接着上次的继续阅读BaseYii.php vendor/yiisoft/yii2/BaseYii.php—— public static function getRootAlias($alias)// ...
- The world beyond batch: Streaming 101
https://www.oreilly.com/ideas/the-world-beyond-batch-streaming-101 https://www.oreilly.com/ideas/the ...
- python的变量
Python变量 在Python中,变量的概念基本上和初中代数的方程变量是一致的.例如,对于方程式 y=x*x ,x就是变量.当x=2时,计算结果是4,当x=5时,计算结果是25. 只是在计算机程序中 ...
- 一个高度压缩的bit位图字典的实现
微软实现的字典功能简单方便,出于全局性考虑,其内部实现比较复杂,在对海量数据处理时,仅仅存放一个对象地址就将占据32个bit(64位机器中占据64个bit),而且其内部通过int[]来处理hash桶, ...
- JavaSE的知识
一 SE的知识体系: java基础: 一基础语法 8个基本数据类型-->8个包装类 数据类型转换: 自动转换(从小到大) 强制转换(从大到小) 注意:int 和char 分支与判断: if(){ ...
- zepto源码--isEmptyObject,isNumeric,inArray,trim--学习笔记
1.isEmptyObject,判断对象是否为空对象的函数 定义变量name,遍历传入对象的属性name,如果存在任何属性,则返回false,判定传入的参数为非空对象,否则即为空对象. 2.isNum ...
- php--列表展示(小实训一月考)
效果图: