贝宝 HttpHostConnectException
Paypal HttpHostConnectException
我在设置 Paypal 时遇到了一些问题,似乎一直收到 HttpHostConnectException
(请参阅下面的完整堆栈跟踪)我认为这可能是防火墙的问题,但网络团队已保证他们允许该地址通过防火墙。那么有人对可能导致这种情况的原因有什么建议吗?
org.apache.http.conn.HttpHostConnectException: Connect to api-3t.sandbox.paypal.com:443 [api-3t.sandbox.paypal.com/173.0.82.83] failed: Connection timed out: connect
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:140)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
at uk.co.cdl.webclient.servicefacade.payment.PaypalPaymentService.paypalHttpCall(PaypalPaymentService.java:192)
at uk.co.cdl.webclient.servicefacade.payment.PaypalPaymentService.registerPaypalExpressCheckoutTransaction(PaypalPaymentService.java:125)
at uk.co.cdl.webclient.model.paypal.RegisterPaypalPayment.doPost(RegisterPaypalPayment.java:41)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:239)
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:123)
... 31 more
这是我的 Java 请求代码
public HashMap<String, String> paypalHttpCall(final String methodName, List<NameValuePair> nvps) {
String responseText = "";
HashMap<String, String> responseNvp = null;
CloseableHttpClient httpClient = HttpClientHelper.getDefaultHttpClient(30000);
Status status = Status.HEALTHY;
String description = "Paypal Connection Successful";
addPostParameterIfNotEmpty(nvps, Paypal.METHOD, methodName);
addPostParameterIfNotEmpty(nvps, "VERSION", this.paypalEndpointVersion);
addPostParameterIfNotEmpty(nvps, "PWD", this.paypalPassword);
addPostParameterIfNotEmpty(nvps, "USER", this.paypalUsername);
addPostParameterIfNotEmpty(nvps, "SIGNATURE", this.paypalSignature);
CloseableHttpResponse postResponse = null;
try {
super.transactionStart();
/* getExternalURL() returns https://api-3t.sandbox.paypal.com/nvp
*
*/
if (!UrlHelper.isAValidFullURL(getExternalURL())) {
// shouldn't happen, but we're toasted if it does, so don't even try
throw new IllegalArgumentException("bad url: "+getExternalURL());
}
final HttpPost httpPost = new HttpPost(getExternalURL());
httpPost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
postResponse = httpClient.execute(httpPost); // Connection timeout here
} catch (IOException ioe) {
status = Status.DEAD;
description = "We through an IOException so something bad has happened.";
ioe.printStackTrace();
} finally {
super.transactionFinish(status, description);
}
return responseNvp;
}
根据评论区与OP的讨论,我很确定这是一个防火墙问题。不可能通过 telnet
与端口 443 连接,无论目标是 google 还是 paypal。
这张图,在 this answer 中找到,当你陷入这样的困境时非常有用:
我在设置 Paypal 时遇到了一些问题,似乎一直收到 HttpHostConnectException
(请参阅下面的完整堆栈跟踪)我认为这可能是防火墙的问题,但网络团队已保证他们允许该地址通过防火墙。那么有人对可能导致这种情况的原因有什么建议吗?
org.apache.http.conn.HttpHostConnectException: Connect to api-3t.sandbox.paypal.com:443 [api-3t.sandbox.paypal.com/173.0.82.83] failed: Connection timed out: connect
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:140)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
at uk.co.cdl.webclient.servicefacade.payment.PaypalPaymentService.paypalHttpCall(PaypalPaymentService.java:192)
at uk.co.cdl.webclient.servicefacade.payment.PaypalPaymentService.registerPaypalExpressCheckoutTransaction(PaypalPaymentService.java:125)
at uk.co.cdl.webclient.model.paypal.RegisterPaypalPayment.doPost(RegisterPaypalPayment.java:41)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:239)
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:123)
... 31 more
这是我的 Java 请求代码
public HashMap<String, String> paypalHttpCall(final String methodName, List<NameValuePair> nvps) {
String responseText = "";
HashMap<String, String> responseNvp = null;
CloseableHttpClient httpClient = HttpClientHelper.getDefaultHttpClient(30000);
Status status = Status.HEALTHY;
String description = "Paypal Connection Successful";
addPostParameterIfNotEmpty(nvps, Paypal.METHOD, methodName);
addPostParameterIfNotEmpty(nvps, "VERSION", this.paypalEndpointVersion);
addPostParameterIfNotEmpty(nvps, "PWD", this.paypalPassword);
addPostParameterIfNotEmpty(nvps, "USER", this.paypalUsername);
addPostParameterIfNotEmpty(nvps, "SIGNATURE", this.paypalSignature);
CloseableHttpResponse postResponse = null;
try {
super.transactionStart();
/* getExternalURL() returns https://api-3t.sandbox.paypal.com/nvp
*
*/
if (!UrlHelper.isAValidFullURL(getExternalURL())) {
// shouldn't happen, but we're toasted if it does, so don't even try
throw new IllegalArgumentException("bad url: "+getExternalURL());
}
final HttpPost httpPost = new HttpPost(getExternalURL());
httpPost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
postResponse = httpClient.execute(httpPost); // Connection timeout here
} catch (IOException ioe) {
status = Status.DEAD;
description = "We through an IOException so something bad has happened.";
ioe.printStackTrace();
} finally {
super.transactionFinish(status, description);
}
return responseNvp;
}
根据评论区与OP的讨论,我很确定这是一个防火墙问题。不可能通过 telnet
与端口 443 连接,无论目标是 google 还是 paypal。
这张图,在 this answer 中找到,当你陷入这样的困境时非常有用: