出站请求的BindException

时间:2014-09-09 18:52:29

标签: java jboss7.x openshift

通过java(使用apache.commons.httpclient)发出出站请求时,我收到Permission denied。 以下是jboss日志的根本原因:

Caused by: java.net.BindException: Permission denied
       at java.net.PlainSocketImpl.socketBind(Native Method)
       at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:353)
       at java.net.Socket.bind(Socket.java:598)
       at sun.security.ssl.BaseSSLSocketImpl.bind(BaseSSLSocketImpl.java:114)
       at sun.security.ssl.SSLSocketImpl.bind(SSLSocketImpl.java:64)
       at sun.security.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:430)
       at sun.security.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:142)
       at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:82)
       at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:127)
       at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
       at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
       at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
       at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
       at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
       at com.killer923.dataFetcher.net.http.HttpRequestDispatcher.sendGETRequest(HttpRequestDispatcher.java:44)

我尝试使用curl在通过ssh连接到gear时获取页面,它运行正常并且能够正确获取数据。

我做错了什么?在发出请求时是否需要指定传出端口?

1 个答案:

答案 0 :(得分:1)

解决问题的最简单方法是将apache commons httpclient升级到版本4 +。

对我来说,版本4.3.5有效。这是maven条目:

<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>

获取数据时还需要进行一些更改。

其他方式,一个更复杂的方式,试图覆盖客户端中使用的套接字连接工厂。我没有尝试这种方式,但希望这个链接有所帮助: https://www.openshift.com/forums/openshift/commons-httpclient-permission-denied