PayPalRESTException:连接超时:连接

时间:2013-08-31 08:30:37

标签: java paypal paypal-sandbox

我尝试了很多方法,但我总是得到相同的异常,PayPalRESTException:连接超时:连接。我甚至下载了paypal提供的示例代码,并尝试使用这些代码,但仍然是同样的错误。 请帮我解决这个问题。或者至少提供你的意见。

错误日志:

SEVERE: Servlet.service() for servlet [signup] in context with path [/PayPalDemo] threw exception [com.paypal.core.rest.PayPalRESTException: Connection timed out: connect] with root cause
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 sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at java.net.HttpURLConnection.getResponseCode(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)
    at com.paypal.core.HttpConnection.execute(HttpConnection.java:93)
    at com.paypal.core.rest.OAuthTokenCredential.generateOAuthToken(OAuthTokenCredential.java:132)
    at com.paypal.core.rest.OAuthTokenCredential.generateAccessToken(OAuthTokenCredential.java:95)
    at com.paypal.core.rest.OAuthTokenCredential.getAccessToken(OAuthTokenCredential.java:86)
    at com.paypal.util.AccessTokenGenerator.getAccessToken(AccessTokenGenerator.java:20)
    at com.paypal.util.AppHelper.createCreditCard(AppHelper.java:54)
    at com.paypal.controller.UserServlet.handleSignup(UserServlet.java:268)
    at com.paypal.controller.UserServlet.doPost(UserServlet.java:117)
    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:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

我也访问了几个博客,但是他们建议检查请求网址。

我正在使用sendbox环境,所以我提供了以下网址:

https://api.sandbox.paypal.com

这是我的SDK配置文件:

# Connection Information
http.ConnectionTimeOut=5000
http.Retry=1
http.ReadTimeOut=30000
http.MaxConnection=100

# HTTP Proxy configuration
# If you are using proxy set http.UseProxy to true and replace the following values with your proxy parameters
http.UseProxy=false
#http.ProxyPort=8080
#http.ProxyHost=127.0.0.1
#http.ProxyUserName=null
#http.ProxyPassword=null

#Set this property to true if you are using the PayPal SDK within a Google App Engine java app
http.GoogleAppEngine = false

# Service Configuration
service.EndPoint=https://api.sandbox.paypal.com
clientID=EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp (changed my own)
clientSecret=EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp (changed my own)

Servlet文件:

package com.paypal.api.payments.servlet;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.paypal.api.payments.Address;
import com.paypal.api.payments.Amount;
import com.paypal.api.payments.Authorization;
import com.paypal.api.payments.CreditCard;
import com.paypal.api.payments.Details;
import com.paypal.api.payments.FundingInstrument;
import com.paypal.api.payments.Payer;
import com.paypal.api.payments.Payment;
import com.paypal.api.payments.Transaction;
import com.paypal.api.payments.util.GenerateAccessToken;
import com.paypal.core.rest.APIContext;
import com.paypal.core.rest.PayPalRESTException;
import com.paypal.core.rest.PayPalResource;

public class GetAuthorizationServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    private static final Logger LOGGER = Logger
            .getLogger(GetAuthorizationServlet.class);

    public void init(ServletConfig servletConfig) throws ServletException {

        InputStream is = GetAuthorizationServlet.class
                .getResourceAsStream("/sdk_config.properties");
        try {
            System.out.println("in read::");
            PayPalResource.initConfig(is);
        } catch (PayPalRESTException e) {
            e.printStackTrace();
            LOGGER.fatal(e.getMessage());
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        doPost(req, resp);
    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        APIContext apiContext = null;
        String accessToken = null;
        try {
            accessToken = GenerateAccessToken.getAccessToken();
            System.out.println("Access Token ::"+accessToken);

        } catch (PayPalRESTException e) {
            e.printStackTrace();
            req.setAttribute("error", e.getMessage());
        }
        req.getRequestDispatcher("response.jsp").forward(req, resp);
    }

}

将从paypal获取令牌的实用程序文件

package com.paypal.util;

import com.paypal.core.ConfigManager;
import com.paypal.core.rest.OAuthTokenCredential;
import com.paypal.core.rest.PayPalRESTException;

public class AccessTokenGenerator {
    private static String accessToken;

    public static String getAccessToken() throws PayPalRESTException {
        if (accessToken == null) {

            // ClientID and ClientSecret retrieved from configuration
            String clientID = ConfigManager.getInstance().getValue("clientID");
            String clientSecret = ConfigManager.getInstance().getValue("clientSecret");
            accessToken = new OAuthTokenCredential(clientID, clientSecret).getAccessToken();
        }
        return accessToken;
    }
}

先谢谢。

1 个答案:

答案 0 :(得分:0)

自从过去9小时以来我一直面临这个问题,但现在我找到了解决方案。 代码实现没有错误,但我的防火墙不让他们去连接。

当我从控制面板关闭防火墙时,所有代码都能正常运行。

谢谢你