当我尝试通过Java访问外部Web服务时,我收到了连接超时错误。
我做的步骤:
从https.somesite.com/ws/ws我单击安装证书安装证书。然后我将证书导出到cert.cer文件。并做了以下,
keytool -import -keystore cacerts -file openrating.cer -alias somesite.com
keytool -list -keystore cacerts -alias somesite.com
keytool -delete -keystore cacerts -alias somesite.com
以下是我的java代码。
HttpClient httpclient = new HttpClient();
System.setProperty("security.provider.n","com.sun.net.ssl.internal.ssl.Provider");
System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
System.setProperty("javax.net.ssl.keyStore", "C:\\j2sdk1.4.2_06\\jre\\lib\\security\\cacerts");
System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
System.setProperty("javax.net.ssl.trustStore", "C:\\j2sdk1.4.2_06\\jre\\lib\\security\\cacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
GetMethod httpget = new GetMethod(xlatePage);
httpget = new GetMethod("https://somesite.com/ws/ws/?siccode=10000000&xwalk=8");
httpget.setQueryString(sicList);
try {
try {
httpclient.executeMethod(httpget);
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
以下是我的例外情况。
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:367)
at java.net.Socket.connect(Socket.java:524)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:545)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:348)
at com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:69)
at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:112)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:663)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:661)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:529)
即使使用System.setproperty方法添加代理主机和端口也无济于事。
PS:当我点击浏览器中的Web服务URL时,我得到了正确的响应。
如果我错过了什么,请指导我。
答案 0 :(得分:0)
防火墙是个问题。谢谢