diff --git a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/PcChargeApi.java b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/PcChargeApi.java index cd924839e3..009573c494 100644 --- a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/PcChargeApi.java +++ b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/gosoftware/PcChargeApi.java @@ -18,18 +18,17 @@ *******************************************************************************/ package org.apache.ofbiz.accounting.thirdparty.gosoftware; +import java.io.DataInputStream; import java.io.IOException; import java.io.PrintStream; -import java.io.DataInputStream; import java.net.Socket; import javax.xml.parsers.ParserConfigurationException; -import org.apache.ofbiz.base.util.UtilXml; -import org.apache.ofbiz.base.util.ObjectType; -import org.apache.ofbiz.base.util.GeneralException; import org.apache.ofbiz.base.util.Debug; - +import org.apache.ofbiz.base.util.GeneralException; +import org.apache.ofbiz.base.util.ObjectType; +import org.apache.ofbiz.base.util.UtilXml; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; @@ -189,6 +188,7 @@ public class PcChargeApi { Socket sock = new Socket(host, port); PrintStream ps = new PrintStream(sock.getOutputStream()); DataInputStream dis = new DataInputStream(sock.getInputStream()); + sock.close(); ps.print(this.toString()); ps.flush(); diff --git a/applications/content/src/main/java/org/apache/ofbiz/content/survey/PdfSurveyServices.java b/applications/content/src/main/java/org/apache/ofbiz/content/survey/PdfSurveyServices.java index 1ca5942cc2..8c2bb767b5 100644 --- a/applications/content/src/main/java/org/apache/ofbiz/content/survey/PdfSurveyServices.java +++ b/applications/content/src/main/java/org/apache/ofbiz/content/survey/PdfSurveyServices.java @@ -585,6 +585,7 @@ public class PdfSurveyServices { ByteArrayOutputStream baos = new ByteArrayOutputStream(); while ((c = fis.read()) != -1) baos.write(c); inputByteBuffer = ByteBuffer.wrap(baos.toByteArray()); + fis.close(); } catch (FileNotFoundException e) { throw(new GeneralException(e.getMessage())); } catch (IOException e) { diff --git a/applications/marketing/src/main/java/org/apache/ofbiz/sfa/vcard/VCard.java b/applications/marketing/src/main/java/org/apache/ofbiz/sfa/vcard/VCard.java index 7c1f88cf11..f666f8b690 100644 --- a/applications/marketing/src/main/java/org/apache/ofbiz/sfa/vcard/VCard.java +++ b/applications/marketing/src/main/java/org/apache/ofbiz/sfa/vcard/VCard.java @@ -31,16 +31,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import ezvcard.Ezvcard; -import ezvcard.io.text.VCardReader; -import ezvcard.parameter.AddressType; -import ezvcard.parameter.TelephoneType; -import ezvcard.parameter.EmailType; -import ezvcard.property.Address; -import ezvcard.property.Email; -import ezvcard.property.FormattedName; -import ezvcard.property.StructuredName; -import ezvcard.property.Telephone; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.FileUtil; import org.apache.ofbiz.base.util.StringUtil; @@ -62,6 +52,17 @@ import org.apache.ofbiz.service.GenericServiceException; import org.apache.ofbiz.service.LocalDispatcher; import org.apache.ofbiz.service.ServiceUtil; +import ezvcard.Ezvcard; +import ezvcard.io.text.VCardReader; +import ezvcard.parameter.AddressType; +import ezvcard.parameter.EmailType; +import ezvcard.parameter.TelephoneType; +import ezvcard.property.Address; +import ezvcard.property.Email; +import ezvcard.property.FormattedName; +import ezvcard.property.StructuredName; +import ezvcard.property.Telephone; + public class VCard { public static final String module = VCard.class.getName(); public static final String resourceError = "MarketingUiLabels"; @@ -71,8 +72,9 @@ public class VCard { * @param dctx * @param context * @return + * @throws IOException */ - public static Map importVCard(DispatchContext dctx, Map context) { + public static Map importVCard(DispatchContext dctx, Map context) throws IOException { LocalDispatcher dispatcher = dctx.getDispatcher(); Delegator delegator = dctx.getDelegator(); Locale locale = (Locale) context.get("locale"); @@ -84,10 +86,10 @@ public class VCard { boolean isGroup = false; List> partiesCreated = new ArrayList>(); List> partiesExist = new ArrayList>(); - String partyName = ""; + String partyName = ""; // TODO this is not used yet + VCardReader vCardReader = new VCardReader(in); try { - VCardReader vCardReader = new VCardReader(in); ezvcard.VCard vcard = null; while ((vcard = vCardReader.readNext()) != null) { @@ -162,6 +164,7 @@ public class VCard { } else { //TODO change uncorrect labellisation String emailFormatErrMsg = UtilProperties.getMessage(resourceError, "SfaImportVCardEmailFormatError", locale); + vCardReader.close(); return ServiceUtil.returnError(structuredName.getGiven() + " " + structuredName.getFamily() + " has " + emailFormatErrMsg); } } @@ -215,12 +218,13 @@ public class VCard { resp = dispatcher.runSync("createPartyIdentification", createPartyIdentificationMap); } } - vCardReader.close(); } catch (IOException | GenericEntityException | GenericServiceException e) { Debug.logError(e, module); + vCardReader.close(); return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "SfaImportVCardError", UtilMisc.toMap("errorString", e.getMessage()), locale)); } + vCardReader.close(); result.put("partiesCreated", partiesCreated); result.put("partiesExist", partiesExist); return result; diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/Debug.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/Debug.java index 6e9be0c43b..3b6115dfaf 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/Debug.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/Debug.java @@ -108,6 +108,7 @@ public final class Debug { Formatter formatter = new Formatter(sb); formatter.format(msg, params); msg = sb.toString(); + formatter.close(); } // log diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/DatabaseUtil.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/DatabaseUtil.java index 9f76b9c2df..55a56646c6 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/DatabaseUtil.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/DatabaseUtil.java @@ -1883,6 +1883,7 @@ public class DatabaseUtil { try { stmt = connection.createStatement(); stmt.executeUpdate(sql2); + stmt.close(); } catch (SQLException e2) { // if this also fails report original error, not this error... return "SQL Exception while executing the following:\n" + sql + "\nError was: " + e.toString();