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/07 10:40:39 UTC
svn commit: r1817345 - in
/ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/eway:
EwayServices.java GatewayConnector.java GatewayResponse.java
Author: jleroux
Date: Thu Dec 7 10:40:39 2017
New Revision: 1817345
URL: http://svn.apache.org/viewvc?rev=1817345&view=rev
Log:
Improved: [FB] Package org.apache.ofbiz.accounting.thirdparty.eway
(Additional Bugs)
(OFBIZ-9528)
Fixes minor Findbugs warnings
jleroux: I removed few trailing blanks and benefited from Writer being also
autocloseable
Thanks: Kyra Pritzel-Hentley for report, Julian Leichert for patch
Modified:
ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/eway/EwayServices.java
ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/eway/GatewayConnector.java
ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/eway/GatewayResponse.java
Modified: ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/eway/EwayServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/eway/EwayServices.java?rev=1817345&r1=1817344&r2=1817345&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/eway/EwayServices.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/eway/EwayServices.java Thu Dec 7 10:40:39 2017
@@ -96,7 +96,7 @@ public class EwayServices {
Boolean authResult = reply.getTrxnStatus();
// auth fields
- result.put("authResult", Boolean.valueOf(authResult.booleanValue()));
+ result.put("authResult", authResult);
result.put("authMessage", reply.getTrxnError());
result.put("authCode", reply.getAuthCode());
result.put("authRefNum", reply.getTrxnNumber());
@@ -163,7 +163,7 @@ public class EwayServices {
// process the result
Map<String, Object> result = ServiceUtil.returnSuccess();
Boolean refundResult = reply.getTrxnStatus();
- result.put("refundResult", Boolean.valueOf(refundResult.booleanValue()));
+ result.put("refundResult", refundResult);
result.put("refundMessage", reply.getTrxnError());
result.put("refundCode", reply.getAuthCode());
result.put("refundRefNum", reply.getTrxnNumber());
@@ -228,7 +228,7 @@ public class EwayServices {
// process the result
Map<String, Object> result = ServiceUtil.returnSuccess();
Boolean refundResult = reply.getTrxnStatus();
- result.put("releaseResult", Boolean.valueOf(refundResult.booleanValue()));
+ result.put("releaseResult", refundResult);
result.put("releaseMessage", reply.getTrxnError());
result.put("releaseCode", reply.getAuthCode());
result.put("releaseRefNum", reply.getTrxnNumber());
Modified: ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/eway/GatewayConnector.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/eway/GatewayConnector.java?rev=1817345&r1=1817344&r2=1817345&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/eway/GatewayConnector.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/eway/GatewayConnector.java Thu Dec 7 10:40:39 2017
@@ -78,7 +78,7 @@ public class GatewayConnector {
public GatewayResponse sendRequest(GatewayRequest request) throws Exception {
// determine the gateway url to be used, based on the request type
- String serverurl = request.getUrl();
+ String serverurl = request.getUrl();
GatewayResponse response = null;
InputStream in = null;
@@ -89,28 +89,29 @@ public class GatewayConnector {
connection = (HttpURLConnection)(u.openConnection());
connection.setDoOutput(true);
connection.setDoInput(true);
- connection.setRequestMethod("POST");
- connection.setConnectTimeout(timeout*1000);
+ connection.setRequestMethod("POST");
+ connection.setConnectTimeout(timeout*1000);
- OutputStream out = connection.getOutputStream();
- Writer wout = new OutputStreamWriter(out, "UTF-8");
- wout.write(request.toXml());
- wout.flush();
- wout.close();
+ try (OutputStream out = connection.getOutputStream();
+ Writer wout = new OutputStreamWriter(out, "UTF-8")) {
+
+ wout.write(request.toXml());
+ wout.flush();
- in = connection.getInputStream();
- response = new GatewayResponse(in, request);
- return response;
+ in = connection.getInputStream();
+ response = new GatewayResponse(in, request);
+ return response;
+ }
}
catch (Exception e) {
- // rethrow exception so that the caller learns what went wrong
+ // re-throws exception so that the caller knows what went wrong
Debug.logError(e, e.getMessage(), module);
throw e;
}
finally {
- // close resources
+ // close connection
if (in != null) in.close();
- if (connection != null) connection.disconnect();
+ connection.disconnect();
}
}
}
\ No newline at end of file
Modified: ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/eway/GatewayResponse.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/eway/GatewayResponse.java?rev=1817345&r1=1817344&r2=1817345&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/eway/GatewayResponse.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/eway/GatewayResponse.java Thu Dec 7 10:40:39 2017
@@ -21,6 +21,7 @@ package org.apache.ofbiz.accounting.thir
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
+import java.util.Locale;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -140,7 +141,8 @@ public class GatewayResponse {
// get all elements
NodeList list = doc.getElementsByTagName("*");
- for (int i = 0; i < list.getLength(); i++) {
+ int length = list.getLength();
+ for (int i = 0; i < length; i++) {
Node node = list.item(i);
String name = node.getNodeName();
if (name == "ewayResponse")
@@ -150,40 +152,41 @@ public class GatewayResponse {
if (textnode != null)
value = textnode.getNodeValue();
- if (name == "ewayTrxnError")
+ switch(name) {
+ case "ewayTrxnError":
txTrxnError = value;
- else if (name == "ewayTrxnStatus") {
- if ("true".equals(value.toLowerCase().trim())) {
+ case "ewayTrxnStatus":
+ if ("true".equals(value.toLowerCase(Locale.getDefault()).trim())) {
txTrxnStatus = true;
}
- }
- else if (name == "ewayTrxnNumber")
+
+ case "ewayTrxnNumber":
txTrxnNumber = value;
- else if (name == "ewayTrxnOption1")
+ case "ewayTrxnOption1":
txTrxnOption1 = value;
- else if (name == "ewayTrxnOption2")
+ case "ewayTrxnOption2":
txTrxnOption2 = value;
- else if (name == "ewayTrxnOption3")
+ case "ewayTrxnOption3":
txTrxnOption3 = value;
- else if (name == "ewayReturnAmount") {
+ case "ewayReturnAmount":
if (!value.equals("")) {
txReturnAmount = Integer.parseInt(value);
}
- }
- else if (name == "ewayAuthCode")
+ case "ewayAuthCode":
txAuthCode = value;
- else if (name == "ewayTrxnReference")
+ case "ewayTrxnReference":
txTrxnReference = value;
- else if (name == "ewayBeagleScore") {
+ case "ewayBeagleScore":
if (!value.equals("")) {
txBeagleScore = Double.parseDouble(value);
}
- }
- else {
+ default:
throw new Exception("Unknown field in response: " + name);
}
}
+
+
if (req.isTestMode()) {
Debug.logInfo("[eWay Reply]\n" + this.toString(), module);
}