当系统属性配置为使用SOCKS代理时,强制直接连接到toto.localhost.lan(在本地计算机上提供)的简单测试。
package net.wetope.launcher.tests;
import java.net.URL;
import java.net.URLConnection;
import junit.framework.TestCase;
public class AppTest extends TestCase {
public void testFile() {
try {
System.setProperty("socksProxyHost", "127.0.0.1");
System.setProperty("socksProxyPort", "9999");
URL url = new URL("http://toto.localhost.lan/");
URLConnection conn = url.openConnection(java.net.Proxy.NO_PROXY);
conn.getInputStream();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
}
此测试结果为:
java.net.SocketException: Malformed reply from SOCKS server
Testsuite: net.wetope.launcher.tests.AppTest
Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0,094 sec
------------- Standard Error -----------------
java.net.SocketException: Malformed reply from SOCKS server
at java.net.SocksSocketImpl.readSocksReply(SocksSocketImpl.java:90)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:472)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:395)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:530)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:234)
at sun.net.www.http.HttpClient.New(HttpClient.java:307)
at sun.net.www.http.HttpClient.New(HttpClient.java:324)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:970)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:949)
at java.net.SocksSocketImpl.readSocksReply(SocksSocketImpl.java:90)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:836)
at java.net.SocksSocketImpl.readSocksReply(SocksSocketImpl.java:90)
at java.net.SocksSocketImpl.readSocksReply(SocksSocketImpl.java:90)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:472)
at net.wetope.launcher.tests.AppTest.testFile(AppTest.java:16)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:395)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:530)
at junit.framework.TestCase.runTest(TestCase.java:168)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:234)
at junit.framework.TestCase.runBare(TestCase.java:134)
at sun.net.www.http.HttpClient.New(HttpClient.java:307)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at sun.net.www.http.HttpClient.New(HttpClient.java:324)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:970)
at junit.framework.TestResult.run(TestResult.java:113)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:949)
at junit.framework.TestCase.run(TestCase.java:124)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:836)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1172)
at junit.framework.TestSuite.run(TestSuite.java:227)
at net.wetope.launcher.tests.AppTest.testFile(AppTest.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:518)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1052)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:906)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:518)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1052)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:906)
------------- ---------------- ---------------
Testcase: testFile(net.wetope.launcher.tests.AppTest): FAILED
null
junit.framework.AssertionFailedError: null
at net.wetope.launcher.tests.AppTest.testFile(AppTest.java:19)
Test net.wetope.launcher.tests.AppTest FAILED
test:
Deleting: /tmp/TEST-net.wetope.launcher.tests.AppTest.xml
BUILD SUCCESSFUL (total time: 1 second)
即使我指定使用直接连接,也通过SOCKS代理尝试连接。
有什么想法吗?
由于
编辑: 堆栈跟踪从jUnit中清除:
java.net.SocketException: Malformed reply from SOCKS server
at java.net.SocksSocketImpl.readSocksReply(SocksSocketImpl.java:90)
at java.net.SocksSocketImpl.readSocksReply(SocksSocketImpl.java:90)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:472)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:395)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:530)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:234)
at sun.net.www.http.HttpClient.New(HttpClient.java:307)
at sun.net.www.http.HttpClient.New(HttpClient.java:324)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:970)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:949)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:836)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1172)
at net.wetope.launcher.tests.AppTest.testSmg(AppTest.java:16)