使用 paypal api 时无法建立 SOAP 连接

Posted

技术标签:

【中文标题】使用 paypal api 时无法建立 SOAP 连接【英文标题】:Unable to establish SOAP connection while using paypal api 【发布时间】:2014-02-12 15:34:09 【问题描述】:

我正在尝试使用 paypal soap 客户端,并使用 Paypal Express Checkout with Java 参考执行 setExpressCheckout 方法。

所以这里我只使用了 paypal-base.jar 和 paypal-stubs.jar 肥皂客户端(从 wsdl 生成)。

    public class SetExpressCheckoutService

        private static Logger log = Logger.getLogger(SetExpressCheckoutService.class);

        public static void main(String[] args)
            SetExpressCheckoutService setExpressCheckoutService = new SetExpressCheckoutService();

            //the parameters for the service
            Long userId = 5l;
            String amount = "25";
            String returnURL = "http://localhost:8080/integratingstuff-paypal/return_after_payment.xhtml";
            String cancelURL = "http://localhost:8080/integratingstuff-paypal/cancel_payment.xhtml";
            PaymentActionCodeType paymentAction = PaymentActionCodeType.Sale;
            CurrencyCodeType currencyCode = CurrencyCodeType.EUR;

            try 
                //calling the service, setting up the checkoutpage
                String token = setExpressCheckoutService.setExpressCheckout(userId, amount, currencyCode, returnURL,cancelURL,paymentAction);
                log.info("Url to redirect to: https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&useraction=commit&token=" + token);
             catch (PayPalException e) 
                log.error(e);
            
        

        public String setExpressCheckout(Long userId, String paymentAmount,
                CurrencyCodeType currencyCodeType, String returnURL, String cancelURL,
                    PaymentActionCodeType paymentAction) throws PayPalException



CallerServices caller = new CallerServices();

            //construct and set the profile, these are the credentials we establish as "the shop" with Paypal
            APIProfile profile = ProfileFactory.createSignatureAPIProfile();
            profile.setAPIUsername("sdk-three_api1.sdk.com");
            profile.setAPIPassword("QFZCWN5HZM8VBG7Q");
            profile.setSignature("AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ");
            profile.setEnvironment("sandbox");
            caller.setAPIProfile(profile);

            //construct the request
            SetExpressCheckoutRequestType pprequest = new SetExpressCheckoutRequestType();
            pprequest.setVersion("63.0");

            //construct the details for the request
            SetExpressCheckoutRequestDetailsType details = new SetExpressCheckoutRequestDetailsType();

            PaymentDetailsType paymentDetails = new PaymentDetailsType();
            paymentDetails.setOrderDescription("Integrating Stuff Test Order");
            paymentDetails.setInvoiceID("INVOICE-" + Math.random());
            BasicAmountType orderTotal = new BasicAmountType(paymentAmount);
            orderTotal.setCurrencyID(currencyCodeType);
            paymentDetails.setOrderTotal(orderTotal);
            paymentDetails.setPaymentAction(paymentAction);
            details.setPaymentDetails(new PaymentDetailsType[]paymentDetails);

            details.setReturnURL(returnURL);
            details.setCancelURL(cancelURL);
            details.setCustom(userId.toString());

            //set the details on the request
            pprequest.setSetExpressCheckoutRequestDetails(details);

            //call the actual webservice, passing the constructed request
            SetExpressCheckoutResponseType ppresponse = (SetExpressCheckoutResponseType) caller.call("SetExpressCheckout", pprequest);

            //get the token from the response
            return ppresponse.getToken();
        
    

我已尝试执行此方法,但出现异常com.paypal.sdk.exceptions.FatalException: Unable to establish SOAP connection

原因:java.lang.NullPointerException 在 com.paypal.sdk.core.APICallerBase.getEndpointUrl(APICallerBase.java:296)

完整的堆栈跟踪是:

com.paypal.sdk.exceptions.FatalException: Unable to establish SOAP connection
        at com.paypal.sdk.core.soap.SOAPAPICaller.setupConnection(SOAPAPICaller.java:292)
        at com.paypal.sdk.services.CallerServices.setAPIProfile(CallerServices.java:112)
        at com.imedicor.liferay.organizations.util.PaypalService.setExpressCheckout(PaypalService.java:92)
        at com.imedicor.liferay.organizations.util.PaypalService.testing(PaypalService.java:43)
        at org.apache.jsp.organization_005fdetails_jsp._jspService(organization_005fdetails_jsp.java:500)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
        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 com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
        at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593)
        at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:530)
        at com.liferay.portlet.PortletRequestDispatcherImpl.dispatch(PortletRequestDispatcherImpl.java:323)
        at com.liferay.portlet.PortletRequestDispatcherImpl.include(PortletRequestDispatcherImpl.java:134)
        at com.imedicor.liferay.organizations.portlet.OrganizationPortlet.doView(OrganizationPortlet.java:83)
        at com.liferay.portal.kernel.portlet.LiferayPortlet.doDispatch(LiferayPortlet.java:218)
        at com.liferay.util.bridges.mvc.MVCPortlet.doDispatch(MVCPortlet.java:319)
        at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
        at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
        at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
        at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:111)
        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 com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
        at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593)
        at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:530)
        at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:534)
        at com.liferay.portlet.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:607)
        at com.liferay.portlet.InvokerPortletImpl.render(InvokerPortletImpl.java:359)
        at org.apache.jsp.html.portal.render_005fportlet_jsp._jspService(render_005fportlet_jsp.java:1207)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at com.liferay.portal.servlet.DirectRequestDispatcher.include(DirectRequestDispatcher.java:97)
        at com.liferay.portal.servlet.PACLRequestDispatcherWrapper.doDispatch(PACLRequestDispatcherWrapper.java:90)
        at com.liferay.portal.servlet.PACLRequestDispatcherWrapper.include(PACLRequestDispatcherWrapper.java:54)
        at com.liferay.portal.util.PortalImpl.renderPortlet(PortalImpl.java:5158)
        at com.liferay.portal.util.PortalUtil.renderPortlet(PortalUtil.java:1569)
        at com.liferay.portlet.layoutconfiguration.util.RuntimePortletImpl.processPortlet(RuntimePortletImpl.java:165)
        at com.liferay.portlet.layoutconfiguration.util.RuntimePortletImpl.processPortlet(RuntimePortletImpl.java:203)
        at com.liferay.portlet.layoutconfiguration.util.RuntimePortletImpl.processPortlet(RuntimePortletImpl.java:190)
        at com.liferay.portlet.layoutconfiguration.util.RuntimePortletUtil.processPortlet(RuntimePortletUtil.java:87)
        at com.liferay.portlet.layoutconfiguration.util.velocity.TemplateProcessor.processMax(TemplateProcessor.java:165)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:389)
        at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:378)
        at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:270)
        at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:262)
        at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:342)
        at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336)
        at org.apache.velocity.Template.merge(Template.java:328)
        at org.apache.velocity.Template.merge(Template.java:235)
        at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:381)
        at com.liferay.portal.velocity.VelocityEngineImpl.mergeTemplate(VelocityEngineImpl.java:264)
        at com.liferay.portal.kernel.velocity.VelocityEngineUtil.mergeTemplate(VelocityEngineUtil.java:73)
        at com.liferay.portlet.layoutconfiguration.util.RuntimePortletImpl.doProcessTemplate(RuntimePortletImpl.java:499)
        at com.liferay.portlet.layoutconfiguration.util.RuntimePortletImpl.doDispatch(RuntimePortletImpl.java:394)
        at com.liferay.portlet.layoutconfiguration.util.RuntimePortletImpl.processTemplate(RuntimePortletImpl.java:228)
        at com.liferay.portlet.layoutconfiguration.util.RuntimePortletUtil.processTemplate(RuntimePortletUtil.java:125)
        at org.apache.jsp.html.portal.layout.view.control_005fpanel_jsp._jspService(control_005fpanel_jsp.java:676)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
        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 com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
        at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593)
        at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:530)
        at com.liferay.portal.action.LayoutAction.includeLayoutContent(LayoutAction.java:468)
        at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:735)
        at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:249)
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
        at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:187)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
        at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
        at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:560)
        at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:537)
        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 com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
        at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:294)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
        at com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:138)
        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 com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
        at com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:335)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
        at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:123)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
        at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:294)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
        at com.liferay.portal.servlet.filters.i18n.I18nFilter.processFilter(I18nFilter.java:241)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
        at com.liferay.portal.servlet.filters.etag.ETagFilter.processFilter(ETagFilter.java:56)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
        at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:246)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
        at com.liferay.portal.servlet.filters.sso.ntlm.NtlmPostFilter.processFilter(NtlmPostFilter.java:83)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
        at com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:80)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
        at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.processFilter(VirtualHostFilter.java:216)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:187)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:167)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:167)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:187)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
        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$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
        at com.paypal.sdk.core.APICallerBase.getEndpointUrl(APICallerBase.java:296)
        at com.paypal.sdk.core.soap.SOAPAPICaller.setupConnection(SOAPAPICaller.java:193)

所以我得到这个异常是因为没有设置端点 url?

这种情况下如何设置endpoint url?

我还尝试在上述方法开始时以以下方式为端点添加配置。

Map<String, String> sdkConfig = new HashMap<String, String>();
        sdkConfig.put("mode", "sandbox");
        sdkConfig.put("acct1.UserName", "sdk-three_api1.sdk.com");
        sdkConfig.put("acct1.Password", "QFZCWN5HZM8VBG7Q");
        sdkConfig.put("acct1.Signature","AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ");
        PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(sdkConfig);

但我仍然遇到同样的异常。

请在这方面指导我。

谢谢,

【问题讨论】:

有人知道如何使用经典的 api/soap 客户端与 paypal 建立连接吗? 您能否指定我可以在哪里下载包含以下类的JAR 文件:CallerServicesAPIProfile 等?我在任何地方都找不到这个 JAR 从这里您可以下载 paypal_base.jar http://www.java2s.com/Code/Jar/p/Downloadpaypalbasejar.htm 。它包含所有这些类。 另外你知道paypal rest sdk提供并发计费和expressCheckout的实现方法吗?我没有在 paypal sdks 中找到它。 我正在尝试使用soap,因为我想执行expressCheckout和并发计费。但仍然没有运气,paypal论坛也没有提供任何回复。它很奇怪。 【参考方案1】:

好的,所以我没能弄清楚为什么CallerService 会抛出提到的异常,因为即使在反编译提到的paypal_base.jar 之后,代码也相当繁琐,而且很难找出幕后发生的事情。看起来它已经过时了,因为除了几个地方之外,我在网上的任何地方都找不到对这个 JAR 的引用。

但我真的建议您坚持使用 PayPal 提供的原始文档。我自己试过了,这就是我发现的:

    点击上述文章中的Paypal API SDK and Downloads 链接,然后单击Classic APIs 类别下的Merchant 链接(如果您在网上挖掘,您会发现PayPal Merchant API 应该用于ExpressCheckout 请求)。点击上方的Java 按钮并使用Maven(首选)或直接使用页面底部的下载链接下载SDK。

    将下载的 JAR 添加到您的项目并删除其他 PayPal JAR,因为下载的 Merchant API jar 应该包含所有必要的类。

    现在一切都靠猜测了 :) 所以在上面的代码 sn-p 中,你已经形成了 SetExpressCheckoutRequestType 的实例,你需要 some invocation code 来获取 SetExpressCheckoutRequestType 的实例并返回 SetExpressCheckoutResponseType 的实例。

    我在 Eclipse 中使用功能 Search -&gt; References -&gt; Workspace 来查找 SetExpressCheckoutRequestTypeMerchant API jar 中的使用位置。此搜索显示(除了其他地方)有一个名为 SetExpressCheckoutReq 的类,其方法为 setSetExpressCheckoutRequest(SetExpressCheckoutRequestType)

    然后我再次使用搜索功能搜索SetExpressCheckoutReq类的用法,发现有PayPalAPIInterfaceServiceService类的方法setExpressCheckout(SetExpressCheckoutReq setExpressCheckoutReq)返回需要的SetExpressCheckoutResponseType

    setExpressCheckout(SetExpressCheckoutReq setExpressCheckoutReq) 方法旁边,有一个方法也接受ICredential 参数并具有以下签名: setExpressCheckout(SetExpressCheckoutReq setExpressCheckoutReq, ICredential credential)

    再次使用 Eclipse,我寻找实现 ICredential 接口的类,发现有一个名为 SignatureCredential 的类,其构造函数采用 3 个参数:用户名、密码、签名。在我看来,这是要走的路。

    所以,非常近似 - 代码 sn-p 现在应该如下所示:

    final SetExpressCheckoutRequestType ppRequest = ...; // here you create your request as in code snippet above
    
    final Properties serviceConfigurationProperties = ...; // bookmark #1
    final PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(serviceConfigurationProperties);
    
    final SetExpressCheckoutReq request = new SetExpressCheckoutReq();
    request.setSetExpressCheckoutRequest(ppRequest);
    
    final ICredentials credentials = new SignatureCredentials(username, password, signature);
    final SetExpressCheckoutResponseType response = service.setExpressCheckout(request, credentials);
    

Bookmark #1: 应该通过Properties 实例和服务配置。要找出应该指定哪些属性,应该搜索它并尝试坚持原始 PayPal 文档而不是 3rd 方博客 :) 如果查看 PayPalAPIInterfaceServiceService 类的 Javadocs,他/她会发现有提到的文件“ sdk_config.properties”。谷歌搜索后,我找到了该文件的几个示例:Example #1、Example #2

请注意,这不是完整的解决方案——它更像是我之前使用 PayPal SOAP API 的提示集合。这个 API 经常变化,文档不简洁,所以我真的建议下载带有源代码的 Merchant API jar,每当出现问题时 - 还要查看代码 - 这通常会澄清很多。请同时遵守 PayPal 的原始文档:

    PayPal SOAP API Basics PayPal Merchant SDK on GitHub

另外,如果您没有使用 Java 的 Web 服务客户端的经验,我建议您尝试使用网上的教程来实现一些简单的 - 这可能会澄清很多。

再次抱歉没有发布完整而简洁的代码 sn-p - 从现在开始我已经有 2 年没有使用 PayPal 了,那时我花了一周的工作时间来找出所有细节并设置它并运行它。请发布问题 - 我会在有时间的时候尝试回答它们

希望这会有所帮助...

编辑

关于response.getAck() 返回FAILURE - 我过去也遇到过这样的问题。我通过试验请求中发送的参数解决了这个问题 - PayPal 对这些参数非常敏感,如果任何参数被省略或没有正确的值,只需返回 FAILURE

您可以在此处找到完整的参数列表: PayPal SetExpressCheckout SOAP API documentation

另请注意,Merchant SDK 的版本 2.5.106 使用版本 106.0 的 API。

希望这会有所帮助...

【讨论】:

谢谢你的朋友。它有很大帮助。现在我可以使用 DirectPayment 执行交易,还可以创建 recurringPaymentProfile。 但很惊讶,无法执行 expressCheckout ,得到 response.getAck() 为 FAILURE。 @Java 我很高兴它有帮助!关于response.getAck()返回FAILURE,请参考我回答的编辑部分。【参考方案2】:

需要设置端点url

    service.EndPoint=https://api-3t.paypal.com/2.0

此外,您可能还需要更多设置:

    service.Binding=SOAP
    service.EndPoint=https://api-3t.paypal.com/2.0
    service.RedirectURL=https://www.paypal.com/webscr&cmd=
    service.DevCentralURL=https://developer.paypal.com
    service.IPNEndpoint=https://www.paypal.com/cgi-bin/webscr

如果您使用的是沙盒,请使用以下设置:

   service.Binding=SOAP
   service.EndPoint=https://api-3t.sandbox.paypal.com/2.0
   service.RedirectURL=https://www.sandbox.paypal.com/webscr&cmd=
   service.DevCentralURL=https://developer.paypal.com
   service.IPNEndpoint=https://www.sandbox.paypal.com/cgi-bin/webscr

【讨论】:

以上是关于使用 paypal api 时无法建立 SOAP 连接的主要内容,如果未能解决你的问题,请参考以下文章

使用 PayPal Payments Pro 记录 SOAP API 操作

PayPal SOAP API - 快速结帐 - 错误 10002

PayPal SOAP API - 不支持版本

如何使用 c# 为 paypal CreateInvoice api 创建 SOAP XML 请求消息

如何在 Paypal SOAP API 快速结账中设置运费

Express PayPal 结帐,无法创建 SSL/TLS 安全通道