details: https://code.openbravo.com/erp/devel/pi/rev/8a73e458127f changeset: 34794:8a73e458127f user: Javier Armendáriz <javier.armendariz <at> openbravo.com> date: Tue Sep 25 09:59:27 2018 +0200 summary: Related to issue 39261: Connection leak when printing image on subreports.
Moved connection close to getImageLogo to avoid errors trying to fetch image binary data from a closed connection. diffstat: src/org/openbravo/erpCommon/utility/Utility.java | 35 ++++++----------------- 1 files changed, 10 insertions(+), 25 deletions(-) diffs (80 lines): diff -r 18826c3cd89b -r 8a73e458127f src/org/openbravo/erpCommon/utility/Utility.java --- a/src/org/openbravo/erpCommon/utility/Utility.java Thu Sep 20 14:31:38 2018 -0400 +++ b/src/org/openbravo/erpCommon/utility/Utility.java Tue Sep 25 09:59:27 2018 +0200 @@ -58,9 +58,6 @@ import javax.imageio.ImageIO; import javax.servlet.ServletException; -import net.sf.jasperreports.engine.JRException; -import net.sf.jasperreports.engine.JasperReport; - import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; @@ -96,6 +93,9 @@ import org.openbravo.utils.FileUtility; import org.openbravo.utils.FormatUtilities; +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JasperReport; + /** * @author Fernando Iriazabal * @@ -2112,24 +2112,6 @@ * @return The image requested */ public static Image getImageLogoObject(String logo, String org) { - return getImageLogoObject(logo, org, false); - } - - /** - * Provides the image logo as a byte array for the indicated parameters. - * - * @param logo - * The name of the logo to display This can be one of the following: yourcompanylogin, - * youritservicelogin, yourcompanymenu, yourcompanybig or yourcompanydoc - * @param org - * The organization id used to get the logo In the case of requesting the yourcompanydoc - * logo you can indicate the organization used to request the logo. - * @param doConnectionClose - * A flag to force the close of the DAL connection after retrieving the image - * - * @return The image requested - */ - private static Image getImageLogoObject(String logo, String org, boolean doConnectionClose) { Image img = null; OBContext.setAdminMode(); try { @@ -2196,9 +2178,6 @@ log4j.error("Could not load logo from database: " + logo + ", " + org, e); } finally { OBContext.restorePreviousMode(); - if (doConnectionClose) { - OBDal.getReadOnlyInstance().commitAndClose(); - } } return img; } @@ -2235,7 +2214,7 @@ byte[] imageByte; try { - Image img = getImageLogoObject(logo, org, doConnectionClose); + Image img = getImageLogoObject(logo, org); if (img == null) { String path = getDefaultImageLogoPath(logo); ByteArrayOutputStream bout = new ByteArrayOutputStream(); @@ -2255,6 +2234,12 @@ } catch (Exception e) { log4j.error("Could not load logo from database: " + logo + ", " + org, e); imageByte = getBlankImage(); + } finally { + if (doConnectionClose) { + // Closing read-only instance connection because this is the connection used by + // getImageLogoObject + OBDal.getReadOnlyInstance().commitAndClose(); + } } return imageByte; } _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits