我似乎无法让JAX-RS客户端在Java 8上使用Web代理。我正在使用RESTEasy 3.0.10.Final,并在Windows 7 Professional 64位上运行Eclipse 4.4.2。
我在运行localhost
的192.168.1.123:3128
上设置了一个FreeProxy服务器。我打开登录并telnet到192.168.1.123 3128并发出手册GET
。请求显示在日志中。
然后我启动我的Java应用程序,在系统属性中设置http.proxyHost=192.168.1.123
和http.proxyPort=3128
。 (我甚至在启动JVM时尝试使用-D
。)(请注意,我不希望localhost
problem发挥作用,因为我连接的是实际的IP地址,而不是localhost
。)
我使用ClientBuilder.newBuilder().build()
创建一个JAX-RS客户端,并对资源执行GET
。 FreeProxy日志中没有显示任何内容。
为了让JAX-RS客户端使用代理,我该怎么办?
ResteasyClientBuilder提供了一种定义defaultProxy的方法:
ResteasyClient client = new ResteasyClientBuilder().defaultProxy("localhost", 8080, "http").build();
似乎可以通过使用-Dhttp.proxyHost
而不是different engine使RESTeasy使用Java的代理属性(例如HttpClient
)。 java.net.HttpURLConnection
支持开箱即用的代理属性:
ResteasyClient client = new ResteasyClientBuilder().httpEngine(URLConnectionEngine()).build();