Jef*_*mes 5 java webproxy resteasy
我正在使用 RestEasy ProxyFactory 连接到 REST 服务。但是我需要通过网络代理进行连接。如何指定代理连接详细信息?
目前我正在使用以下命令创建实例:
MyInterface instance = org.jboss.resteasy.client.ProxyFactory.create(MyInterface.class,url);
instance.doStuff();
Run Code Online (Sandbox Code Playgroud)
但是,它没有连接。
RestEasy 似乎在幕后使用 Apache Commons HTTPClient,它不允许您使用标准 Java 系统属性指定代理。
好吧,我想我已经通过指定 ClientExecutor 找到了它:
org.apache.commons.httpclient.HttpClient httpClient = new HttpClient();
httpClient.getHostConfiguration().setProxy(proxyHost,proxyPort);
ClientExecutor executor = new ApacheHttpClientExecutor(httpClient);
MyInterface instance = org.jboss.resteasy.client.ProxyFactory.create(MyInterface.class,url,executor);
Run Code Online (Sandbox Code Playgroud)