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
最新文章
- JVM内存模型和启动参数的关系
- [No000038]操作系统Operating Systems -CPU
- Android开发遇到的坑(1):Java中List的安全删除问题
- Backbone之旅——Collection and View篇
- Ext入门学习系列(五)表格控件(3)
- LIBRARY_PATH和LD_LIBRARY_PATH环境变量的区别
- de4dot命令 v2.0.3.3405
- qt学习:信号,槽
- 【笔记】《通俗详细地讲解什么是P和NP问题》的概念记录
- Unity3D在一建筑GL材料可以改变颜色和显示样本
- dva-quickstart 与 create-react-app 比较(一)
- get请求URL的转码
- Maven常识
- Spring MVC(三)控制器获取页面请求参数以及将控制器数据传递给页面和实现重定向的方式
- day_12函数默认值,数据类型的补充,函数对象名称空间与作用域,函数的嵌套定义
- centos7如何查找文件?
- FortiGate下视频会议等语音相关配置
- 【文文殿下】[CEOI2004]锯木厂选址 题解
- 异常空格,ASCII (194,160)问题
- 多页面应用_vue