2

我在结合 RESTeasy 的 ClientRequest 类时遇到 Java 的 useSystemProxy-Feature 问题:

ClientRequest request = new ClientRequest(Config.getInstance().getProperty(Config.UPDATE_URL));
ClientResponse<FullscreenUpdateTransfer> response = request.get(FullscreenUpdateTransfer.class);
if (response.getStatus() != Response.Status.OK.getStatusCode())
{
    throw new Exception("HTTP Status Response: " + response.getStatus());
}

大约一分钟后抛出:

java.net.SocketException: Malformed reply from SOCKS server
    at java.net.SocksSocketImpl.readSocksReply(SocksSocketImpl.java:90)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:429)
    at java.net.Socket.connect(Socket.java:529)
    at java.net.Socket.connect(Socket.java:478)
    at java.net.Socket.<init>(Socket.java:375)
    at java.net.Socket.<init>(Socket.java:249)
    at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:79)
    at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:121)
    at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:706)
    at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:386)
    at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
    at org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor.execute(ApacheHttpClientExecutor.java:64)
    at org.jboss.resteasy.core.interception.ClientExecutionContextImpl.proceed(ClientExecutionContextImpl.java:39)
    at org.jboss.resteasy.plugins.interceptors.encoding.AcceptEncodingGZIPInterceptor.execute(AcceptEncodingGZIPInterceptor.java:40)
    at org.jboss.resteasy.core.interception.ClientExecutionContextImpl.proceed(ClientExecutionContextImpl.java:45)
    at org.jboss.resteasy.client.ClientRequest.execute(ClientRequest.java:448)
    at org.jboss.resteasy.client.ClientRequest.httpMethod(ClientRequest.java:655)
    at org.jboss.resteasy.client.ClientRequest.get(ClientRequest.java:483)
    at org.jboss.resteasy.client.ClientRequest.get(ClientRequest.java:503)
    at de.taf.easygo.modules.dfimanager.database.logic.Update.run(Update.java:110)
    at java.util.TimerThread.mainLoop(Timer.java:512)
    at java.util.TimerThread.run(Timer.java:462)

因此,RESTeasy 似乎告诉 Apache HTTP 客户端使用 SOCKS 代理。(现在我重新阅读了堆栈跟踪,似乎 Apache HTTP 客户端命令 Socket 使用 SOCKS 代理。)现在一直在寻找解决方案。我通过使用 HttpUrlConnection 多次解决它,然后手动将结果提供给 JaxbContext。不是很方便,尤其是涉及到 PUT 请求时,所以我想问一下是否有人解决了这个问题。

当然,我为此使用了经过测试/工作的 HTTP 代理。

我没有通过 proxyHost/proxyPort 属性提供代理的选项。我需要使用 java.net.useSystemProxies。

4

0 回答 0