From cac7d76cba10c6a8f16008b201a98bcbdbc0dddf Mon Sep 17 00:00:00 2001 From: Jacques Le Roux Date: Fri, 8 Dec 2017 05:04:23 +0000 Subject: [PATCH] Implemented: Handle service response effectively (OFBIZ-9981) Included Debug.logError in ServiceUtil.returnProblem so that in case of any error occurred and handled, it will always be logged on the console. jleroux: I put a toString() there, Debug.logError() does not work with maps Also no functional change (better code) in QRCodeEvents jleroux: I also replaced tabs by spaces there and put debug info in exceptions Thanks: Suraj Khurana git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1817455 13f79535-47bb-0310-9956-ffa450edef68 --- .../ofbiz/common/qrcode/QRCodeEvents.java | 53 ++++++++++--------- .../org/apache/ofbiz/service/ServiceUtil.java | 1 + 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/framework/common/src/main/java/org/apache/ofbiz/common/qrcode/QRCodeEvents.java b/framework/common/src/main/java/org/apache/ofbiz/common/qrcode/QRCodeEvents.java index 7fd8b4597a..065b792f89 100644 --- a/framework/common/src/main/java/org/apache/ofbiz/common/qrcode/QRCodeEvents.java +++ b/framework/common/src/main/java/org/apache/ofbiz/common/qrcode/QRCodeEvents.java @@ -29,6 +29,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.UtilHttp; import org.apache.ofbiz.base.util.UtilMisc; import org.apache.ofbiz.base.util.UtilProperties; @@ -76,55 +77,55 @@ public class QRCodeEvents { OutputStream os = response.getOutputStream(); Map context = UtilMisc.toMap("message", message, "format", format, "userLogin", userLogin, "locale", locale); if (UtilValidate.isNotEmpty(width)) { - try { + try { context.put("width", Integer.parseInt(width)); - } catch (NumberFormatException e) { - // do nothing - } + } catch (NumberFormatException e) { + Debug.logWarning(e, e.getMessage(), module); + } if (UtilValidate.isEmpty(height)) { - try { + try { context.put("height", Integer.parseInt(width)); - } catch (NumberFormatException e) { - // do nothing - } + } catch (NumberFormatException e) { + Debug.logWarning(e, e.getMessage(), module); + } } } if (UtilValidate.isNotEmpty(height)) { - try { + try { context.put("height", Integer.parseInt(height)); - } catch (NumberFormatException e) { - // do nothing - } + } catch (NumberFormatException e) { + Debug.logWarning(e, e.getMessage(), module); + } if (UtilValidate.isEmpty(width)) { - try { + try { context.put("width", Integer.parseInt(height)); - } catch (NumberFormatException e) { - // do nothing - } + } catch (NumberFormatException e) { + Debug.logWarning(e, e.getMessage(), module); + } } } if (UtilValidate.isNotEmpty(encoding)) { context.put("encoding", encoding); } if (UtilValidate.isNotEmpty(verifyOutput) && verifyOutput.booleanValue()) { - context.put("verifyOutput", verifyOutput); + context.put("verifyOutput", verifyOutput); } if (UtilValidate.isNotEmpty(logoImageMaxWidth)) { - try { + try { context.put("logoImageMaxWidth", Integer.parseInt(logoImageMaxWidth)); - } catch (NumberFormatException e) { - // do nothing - } + } catch (NumberFormatException e) { + Debug.logWarning(e, e.getMessage(), module); + } } if (UtilValidate.isNotEmpty(logoImageMaxHeight)) { - try { + try { context.put("logoImageMaxHeight", Integer.parseInt(logoImageMaxHeight)); - } catch (NumberFormatException e) { - // do nothing - } + } catch (NumberFormatException e) { + Debug.logWarning(e, e.getMessage(), module); + } } Map results = dispatcher.runSync("generateQRCodeImage", context); - if (!ServiceUtil.isError(results)) { + if (ServiceUtil.isSuccess(results)) { BufferedImage bufferedImage = (BufferedImage) results.get("bufferedImage"); if (!ImageIO.write(bufferedImage, format, os)) { String errMsg = UtilProperties.getMessage("QRCodeUiLabels", "ErrorWriteFormatToFile", new Object[] { format }, locale); diff --git a/framework/service/src/main/java/org/apache/ofbiz/service/ServiceUtil.java b/framework/service/src/main/java/org/apache/ofbiz/service/ServiceUtil.java index 06b83b679c..c7ac7824dc 100644 --- a/framework/service/src/main/java/org/apache/ofbiz/service/ServiceUtil.java +++ b/framework/service/src/main/java/org/apache/ofbiz/service/ServiceUtil.java @@ -152,6 +152,7 @@ public final class ServiceUtil { if (errorMap.size() > 0) { result.put(ModelService.ERROR_MESSAGE_MAP, errorMap); } + Debug.logError(result.toString(), module); return result; }