使用 RestEasy 客户端代理时如何指定 Web 代理? [英] How do I specify a web proxy when using RestEasy client proxy?

查看:49
本文介绍了使用 RestEasy 客户端代理时如何指定 Web 代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 RestEasy ProxyFactory 连接到 REST 服务.但是我需要通过网络代理连接.如何指定代理连接详细信息?

I am using a RestEasy ProxyFactory to connecting to a REST service. However I need to connect via a web proxy. How do I specify the proxy connection details?

目前我正在使用:

MyInterface instance = org.jboss.resteasy.client.ProxyFactory.create(MyInterface.class,url);
instance.doStuff();

但是,它无法连接.

RestEasy 似乎在幕后使用 Apache Commons HTTPClient,它不允许您使用标准 Java 系统属性指定代理.

RestEasy seems to be using Apache Commons HTTPClient under the covers, which does not allow you to specify a proxy using the standard Java System Properties.

推荐答案

好吧,我想我已经通过指定 ClientExecutor 找到了它:

Ok I think I've found it by specifying the 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);

这篇关于使用 RestEasy 客户端代理时如何指定 Web 代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆