You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2017/12/16 15:27:27 UTC

svn commit: r1818423 - /ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/paypal/PayPalEvents.java

Author: jleroux
Date: Sat Dec 16 15:27:27 2017
New Revision: 1818423

URL: http://svn.apache.org/viewvc?rev=1818423&view=rev
Log:
Improved: [FB] Package org.apache.ofbiz.accounting.thirdparty.paypal
(OFBIZ-9539)

Simplifies the code (no functional change) after a discussion with Michael and
Dennis in the Jira

Thanks: Michael and Dennis 

Modified:
    ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/paypal/PayPalEvents.java

Modified: ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/paypal/PayPalEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/paypal/PayPalEvents.java?rev=1818423&r1=1818422&r2=1818423&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/paypal/PayPalEvents.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/paypal/PayPalEvents.java Sat Dec 16 15:27:27 2017
@@ -182,8 +182,9 @@ public class PayPalEvents {
         return "success";
     }
 
-    /** PayPal Call-Back Event */
-    public static String payPalIPN(HttpServletRequest request, HttpServletResponse response) {
+    /** PayPal Call-Back Event 
+     * @throws IOException */
+    public static String payPalIPN(HttpServletRequest request, HttpServletResponse response) throws IOException {
         Locale locale = UtilHttp.getLocale(request);
         Delegator delegator = (Delegator) request.getAttribute("delegator");
         LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
@@ -228,34 +229,20 @@ public class PayPalEvents {
 
         // send off the confirm request
         String confirmResp = null;
-        BufferedReader in = null;
-        PrintWriter pw = null;
+        String str = UtilHttp.urlEncodeArgs(parametersMap);
+        URL u = new URL(redirectUrl);
+        URLConnection uc = u.openConnection();
+        uc.setDoOutput(true);
+        uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
 
-        try {
-            String str = UtilHttp.urlEncodeArgs(parametersMap);
-            URL u = new URL(redirectUrl);
-            URLConnection uc = u.openConnection();
-            uc.setDoOutput(true);
-            uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
-            pw = new PrintWriter(new OutputStreamWriter(uc.getOutputStream(), "UTF-8"));
-            pw.println(str);
+        try (BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
+                PrintWriter pw = new PrintWriter(new OutputStreamWriter(uc.getOutputStream(), "UTF-8"))) {
 
-            in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
+            pw.println(str);
             confirmResp = in.readLine();
             Debug.logError("PayPal Verification Response: " + confirmResp, module);
         } catch (IOException e) {
             Debug.logError(e, "Problems sending verification message.", module);
-        } finally {
-            if (in != null) {
-                try {
-                    in.close();
-                } catch (IOException e) {
-                    Debug.logError(e, "Could not close BufferedReader.", module);
-                }
-            }
-            if (pw != null) {
-                pw.close();
-            }
         }
 
         Debug.logInfo("Got verification from PayPal, processing..", module);