Java Paypal HttpHostConnectException

Java Paypal HttpHostConnectException,java,paypal,paypal-sandbox,Java,Paypal,Paypal Sandbox,我在设置Paypal时遇到了一点问题,似乎一直都在收到HttpHostConnectException(请参见下面的完整stacktrace)我认为这可能是防火墙的问题,但网络团队已保证允许地址通过防火墙。那么,有没有人对造成这种情况的原因有什么建议 org.apache.http.conn.HttpHostConnectException: Connect to api-3t.sandbox.paypal.com:443 [api-3t.sandbox.paypal.com/173.0.82.

我在设置Paypal时遇到了一点问题,似乎一直都在收到
HttpHostConnectException
(请参见下面的完整stacktrace)我认为这可能是防火墙的问题,但网络团队已保证允许地址通过防火墙。那么,有没有人对造成这种情况的原因有什么建议

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;
}
public HashMap paypalHttpCall(最终字符串methodName,列出NVP){
字符串responseText=“”;
HashMap responsevp=null;
CloseableHttpClient-httpClient=HttpClientHelper.getDefaultHttpClient(30000);
Status=Status.health;
String description=“Paypal连接成功”;
AddPostParameterFnotempty(nvps、Paypal.METHOD、methodName);
addpostparameterfnotempty(nvps,“版本”,this.paypalEndpointVersion);
addpostparameterfnotempty(nvps,“PWD”,this.payplpassword);
addPostParameterFnotempty(nvps,“用户”,this.paypalUsername);
ADDPPOSTPARAMETERIFNOTEMPTY(nvps,“签名”,此为paypalSignature);
CloseableHttpResponse postResponse=null;
试一试{
super.transactionStart();
/*getExternalURL()返回https://api-3t.sandbox.paypal.com/nvp
*
*/
如果(!UrlHelper.isAValidFullURL(getExternalURL())){
//不应该发生,但如果发生了,我们会被烤的,所以不要尝试
抛出新的IllegalArgumentException(“错误url:+getExternalURL());
}
final-HttpPost-HttpPost=新的HttpPost(getExternalURL());
setEntity(新的UrlEncodedFormEntity(nvps,“UTF-8”);
postResponse=httpClient.execute(httpPost);//此处连接超时
}捕获(ioe异常ioe){
status=status.DEAD;
description=“我们通过了IOException,所以发生了一些不好的事情。”;
ioe.printStackTrace();
}最后{
super.transactionFinish(状态、描述);
}
返回响应envp;
}

根据评论部分与OP的讨论,我很确定这是一个防火墙问题。无论目标是google还是paypal,都不可能通过
telnet
与443端口连接

当您陷入这样的困境时,在中找到的此图非常有用:


你能证明网络团队的声明吗?(他们是向您展示了还是告诉您了?)例如,您是否能够从执行程序的环境中访问并ping有问题的地址?我并不是说网络团队在撒谎或工作做得不好,但有时会发生粗心的错误,有时也会出现沟通失误。他们肯定这是被添加的。这看起来很奇怪,因为我现在可以在我的浏览器中点击它,但不能在我的代码中点击,但它正在发送相同的请求。这很奇怪。您是否在本地部署了应用程序?如果它是远程部署的,那么网络团队可能已经为您的本地机器打开了连接,但没有为部署应用程序的机器打开连接。它在我的机器上本地运行。您如何在浏览器中对其进行测试?我非常高兴以250分奖励您,因为您提供了巨大的帮助,但我只想等待测试结果我已将日志发送回我们的网络团队,以查看他们的说法,但目前为+1。请注意:在任何情况下都不要使用Telnet验证与PayPal API端点或其他IP地址的连接。由于Telnet不知道SSL,也不确认SSL握手,这可能会在PayPal端触发临时黑名单,从而使故障排除更加复杂。改用CURL或OpenSSL。来源:@PayPal_Martin不会启动SSL握手。SSL的客户端进行初始化:确认或响应由服务器完成。文件是错误的。从技术上讲,这一解释应该得到修正——信息保持不变。如果我们有一个传入的TCP连接,但随后没有进行SSL握手,则原始IP地址最终将被阻止。原来防火墙仍在阻止我,但后来我们发现我们也被代理阻止,因此,感谢您,享受他们花费的250分。