JFINAL-PROXY简介
JFINAL-PROXY 是基于 jfinal 与 httpclient 实现的正向代理插件
https://gitee.com/sohnny/jfinalproxy
快速入门
1. 引入 jfinalproxy.jar 包, 或引入maven配置
<dependency> <groupId>com.gitee.sohnny</groupId> <artifactId>jfinalproxy</artifactId> <version>1.0</version> </dependency>
2. 新建 proxy.properties 配置文件 内容如下:
################## HttpClient start ################## maxTotal = 200 defaultMaxPerRoute = 20 localhostRoutePort = 80 maxPerRoute = 50 ################## HttpClient end ################## ################## Proxy start ################## isEnable = false proxyHost = 192.168.10.2 proxyHostPort = 8089 username = test password = test ################## Proxy end ##################
maxTotal 最大http线程池为 200; defaultMaxPerRoute 默认的路由数为 20; isEnable 为true启用代理 proxyHost 代理主机地址 proxyHostPort 代理主机端口 username 用户名 password 密码
用法
... import com.sohnny.httpclient.sdk.HttpClientFactory; import org.apache.http.util.EntityUtils; ... CloseableHttpResponse response = null; String jsonstr = null; HttpGet httpget = new HttpGet("http://www.baidu.com"); try { response = HttpClientFactory.getHttpClient() .execute(httpget, HttpClientContext.create()); HttpEntity entity = response.getEntity(); jsonstr = entity != null ? EntityUtils.toString(entity) : null; } catch (IOException e) { e.printStackTrace(); }
项目maven依赖
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>com.jfinal</groupId> <artifactId>jfinal</artifactId> <version>3.3</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.2</version> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpmime</artifactId> <version>4.5.2</version> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.1</version> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/log4j/log4j --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.25</version> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.25</version> <scope>provided</scope> </dependency> </dependencies> <build> <finalName>jfinalproxy</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.2.0</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> <compilerArguments> <extdirs>src\main\webapp\WEB-INF\lib</extdirs> </compilerArguments> </configuration> </plugin> </plugins> </build>
项目:Jfinal-proxy