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 ...
随机推荐
- Windows编译安装OpenSSL
windows下使用vs2008中的nmake编译安装openssl的脚本build.bat: echo off & color 0A :: 项目名称 set PROJECT=openssl ...
- 《你不知道的JavaScript》读书笔记(二)词法作用域
JavaScript 采用的是 词法作用域 的工作模型. 定义 词法化:大部分标准语言编译器的第一个工作阶段叫词法化(单词化),这个过程会对源代码中的字符进行检查,如果是有状态的解析过程,还会赋予单词 ...
- PHP 错误与异常 笔记与总结(1)错误(Deprecated,Notice,Warning)
[常见的错误类型] ① 语法错误 [例1]程序语句结尾少了';' <?php $username = "dee" //少了分号; echo $username; 输出: ( ...
- ThinkPHP 3.2 版本升级了哪些内容
ThinkPHP 3.2 版本升级了哪些内容 ThinkPHP 3.2发布了挺长时间了,这里也总结下这次ThinkPHP 3.2到底发生了哪些变化,方便程序员们进行开发. 前言 T ...
- notepad++ gvim editplus 三款选择试用
notepad++开源 试用还不错 但默认不会识别语法高亮 要自己设置 比较烦 gvim 在XP下竟然无法返回命令行 百般折腾无奈放弃 editplus 自带资源栏 选择器 文件查找功能 ...
- getComputedStyle()与currentStyle
getComputedStyle()与currentStyle计算元素样式 发表于 2011-10-27 由 admin “DOM2级样式”增强了document.defaultView,提供了get ...
- LogNet4学习笔记
LogNet是一套开源的程序日志记录系统,经过配置后可以自动抓取程序中的错误.异常信息,并写入磁盘,也可以在异常发生时执行其他指定的操作,比如:通知某人右键.写入数据库等. 这里写个AspNet应用L ...
- SHELL 八大扩展
最近在梳理bash知识的的过程中,有幸阅读了man bash文档,一时间犹如醍醐灌顶一般,很多当初不明白的地方都豁然开朗,现在就其中的一点做一分享,同时也为man bash做一下广告,当你面对bash ...
- 读书笔记——《图解TCP/IP》(2/4)
经典摘抄 第三章 数据链路 1.实际的通信媒介之间处理的却是电压的高低.光的闪灭以及电波的强弱等信号. 2.数据链路层的相关技术:MAC寻址.介质共享.非公有网络.分组交换.环路检测.VLAN等 3. ...
- Android源码剖析之Framework层实战版(Ams管理Activity启动)
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 讲到实战,就不得不拿两个例子来说明,本篇想拿的是应用最广泛的两个:Ams和Wms,一个管理activ ...