Author: jleroux
Date: Sat Sep 3 12:15:35 2016
New Revision: 1759082
URL: http://svn.apache.org/viewvc?rev=1759082&view=rev
Log:
By using the try-with-resources statement I'm sure all is safe in
PcChargeApi.send()
Modified:
ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/PcChargeApi.java
ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/PcChargeServices.java
Modified:
ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/PcChargeApi.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/PcChargeApi.java?rev=1759082&r1=1759081&r2=1759082&view=diff
==============================================================================
---
ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/PcChargeApi.java
(original)
+++
ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/PcChargeApi.java
Sat Sep 3 12:15:35 2016
@@ -185,31 +185,29 @@ public class PcChargeApi {
byte readBuffer[] = new byte[2250];
if (mode == MODE_IN) {
- Socket sock = new Socket(host, port);
- PrintStream ps = new PrintStream(sock.getOutputStream());
- DataInputStream dis = new DataInputStream(sock.getInputStream());
- ps.print(this.toString());
- ps.flush();
+ try (Socket sock = new Socket(host, port);
+ PrintStream ps = new PrintStream(sock.getOutputStream());
+ DataInputStream dis = new
DataInputStream(sock.getInputStream())) {
+
+ ps.print(this.toString());
+ ps.flush();
- StringBuilder buf = new StringBuilder();
- int size;
- while ((size = dis.read(readBuffer)) > -1) {
- buf.append(new String(readBuffer, 0, size));
+ StringBuilder buf = new StringBuilder();
+ int size;
+ while ((size = dis.read(readBuffer)) > -1) {
+ buf.append(new String(readBuffer, 0, size));
+ }
+ Document outDoc = null;
+ try {
+ outDoc = UtilXml.readXmlDocument(buf.toString(), false);
+ } catch (ParserConfigurationException e) {
+ throw new GeneralException(e);
+ } catch (SAXException e) {
+ throw new GeneralException(e);
+ }
+ PcChargeApi out = new PcChargeApi(outDoc);
+ return out;
}
- Document outDoc = null;
- try {
- outDoc = UtilXml.readXmlDocument(buf.toString(), false);
- } catch (ParserConfigurationException e) {
- sock.close();
- throw new GeneralException(e);
- } catch (SAXException e) {
- sock.close();
- throw new GeneralException(e);
- }
-
- PcChargeApi out = new PcChargeApi(outDoc);
- sock.close();
- return out;
} else {
throw new IllegalStateException("Cannot send output object");
}
Modified:
ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/PcChargeServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/PcChargeServices.java?rev=1759082&r1=1759081&r2=1759082&view=diff
==============================================================================
---
ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/PcChargeServices.java
(original)
+++
ofbiz/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/PcChargeServices.java
Sat Sep 3 12:15:35 2016
@@ -50,6 +50,7 @@ public class PcChargeServices {
public static Map<String, Object> ccAuth(DispatchContext dctx, Map<String,
? extends Object> context) {
Locale locale = (Locale) context.get("locale");
Delegator delegator = dctx.getDelegator();
+ // setup the PCCharge Interface
Properties props = buildPccProperties(context, delegator);
PcChargeApi api = getApi(props);
if (api == null) {