问题描述
我似乎无法让JAX-RS客户端在Java 8上使用Web代理。我正在使用RESTEasy 3.0.10.Final,并从Windows 7 Professional 64位的Eclipse 4.4.2内部运行。我在 localhost
上设置了一个FreeProxy服务器,运行在 192.168.1.123:3128
。我打开登录并telnet到192.168.1.123 3128并发出一个手册 GET
。该请求显示在日志中。
然后我启动我的Java应用程序,设置 http.proxyHost = 192.168.1.123
和 http.proxyPort = 3128
在系统属性中。 (我启动JVM时甚至尝试使用 -D
)(请注意,我不会指望发挥作用,因为我连接到一个实际的IP地址, code> localhost 。)
我使用 ClientBuilder.newBuilder()创建一个JAX-RS客户端。 build()
并执行一个 GET
到一个资源。 FreeProxy日志中没有任何内容。
为了让JAX-RS客户端使用代理,我该怎么办?
提供了一种定义defaultProxy的方法:
ResteasyClient client = new ResteasyClientBuilder()。defaultProxy(localhost,8080http)。build();
I can't seem to get JAX-RS clients to use a web proxy on Java 8. I'm using RESTEasy 3.0.10.Final, and running from inside Eclipse 4.4.2 on Windows 7 Professional 64-bit.
I set up a FreeProxy server on localhost
running at 192.168.1.123:3128
. I turn logs on and telnet to 192.168.1.123 3128 and issue a manual GET
. The request shows up in the logs.
I then fire up my Java application, setting http.proxyHost=192.168.1.123
and http.proxyPort=3128
in the system properties. (I've even tried it using -D
when starting the JVM.) (Note that I wouldn't expect the localhost
problem to come into play, as I'm connecting to an actual IP address, not to localhost
.)
I create a JAX-RS client using ClientBuilder.newBuilder().build()
and perform a GET
to a resource. Nothing shows up in the FreeProxy logs.
What do I have to do in order to get JAX-RS clients to use a proxy?
The ResteasyClientBuilder provides a method to define the defaultProxy:
ResteasyClient client = new ResteasyClientBuilder().defaultProxy("localhost", 8080, "http").build();
这篇关于使用Web代理与Java 8 JAX-RS RESTEasy客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!