How do I specify a web proxy when using RestEasy client proxy?

帅比萌擦擦* 提交于 2019-12-13 13:16:26

问题


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?

At the moment I am creating the instance using:

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

However, it does not connect.

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.


回答1:


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);


来源:https://stackoverflow.com/questions/5249734/how-do-i-specify-a-web-proxy-when-using-resteasy-client-proxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!