From a028e9a20726a6ad7b9725f97dfdfe855de8b1d2 Mon Sep 17 00:00:00 2001 From: Anil Patel Date: Thu, 12 Jul 2007 19:12:01 +0000 Subject: [PATCH] Improved error response handling. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@555723 13f79535-47bb-0310-9956-ffa450edef68 --- specialpurpose/oagis/servicedef/secas.xml | 10 ++-- specialpurpose/oagis/servicedef/services.xml | 6 +- .../src/org/ofbiz/oagis/OagisServices.java | 51 ++++++++--------- .../ofbiz/oagis/OagisShipmentServices.java | 55 +++++++++++-------- .../oagis/webapp/oagis/message/ConfirmBod.ftl | 10 ++-- 5 files changed, 70 insertions(+), 62 deletions(-) diff --git a/specialpurpose/oagis/servicedef/secas.xml b/specialpurpose/oagis/servicedef/secas.xml index 56c71ee712..641aa4e985 100644 --- a/specialpurpose/oagis/servicedef/secas.xml +++ b/specialpurpose/oagis/servicedef/secas.xml @@ -37,7 +37,7 @@ under the License. --> - + @@ -51,25 +51,25 @@ under the License. --> - + - + - + - + diff --git a/specialpurpose/oagis/servicedef/services.xml b/specialpurpose/oagis/servicedef/services.xml index b10ce50621..6a2364d8f6 100644 --- a/specialpurpose/oagis/servicedef/services.xml +++ b/specialpurpose/oagis/servicedef/services.xml @@ -42,8 +42,7 @@ under the License. - - + - - + diff --git a/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java b/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java index c9481601b4..f3062a6522 100644 --- a/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java +++ b/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java @@ -33,6 +33,7 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.text.ParseException; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Date; @@ -105,8 +106,9 @@ public class OagisServices { bodyParameters.put("errorComponent", context.get("component")); bodyParameters.put("errorTask", context.get("task")); bodyParameters.put("errorReferenceId", context.get("referenceId")); - bodyParameters.put("errorDescription", context.get("description")); - bodyParameters.put("errorReasonCode", context.get("reasonCode")); + //bodyParameters.put("errorDescription", context.get("description")); + //bodyParameters.put("errorReasonCode", context.get("reasonCode")); + bodyParameters.put("errorMapList",(List) context.get("errorMapList")); bodyParameters.put("origRef", context.get("origRefId")); String bodyScreenUri = UtilProperties.getPropertyValue("oagis.properties", "Oagis.Template.ConfirmBod"); @@ -199,13 +201,13 @@ public class OagisServices { GenericDelegator delegator = ctx.getDelegator(); LocalDispatcher dispatcher = ctx.getDispatcher(); InputStream in = (InputStream) context.get("inputStream"); - FastList errorList = FastList.newInstance(); + List errorMapList = FastList.newInstance(); GenericValue userLogin = null; try { userLogin = delegator.findByPrimaryKey("UserLogin",UtilMisc.toMap("userLoginId","admin")); } catch (GenericEntityException e){ - String errMsg = "Error Getting UserLogin with userLoginId 'admin'"; + String errMsg = "Error Getting UserLogin with userLoginId 'admin':"+e.toString(); Debug.logError(e, errMsg, module); } @@ -213,16 +215,16 @@ public class OagisServices { try { doc = UtilXml.readXmlDocument(in, true, "RecieveConfirmBod"); } catch (SAXException e) { - String errMsg = "Error parsing the ConfirmBodResponse"; - errorList.add(errMsg); + String errMsg = "Error parsing the ConfirmBodResponse: "+e.toString(); + errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "SAXException")); Debug.logError(e, errMsg, module); } catch (ParserConfigurationException e) { - String errMsg = "Error parsing the ConfirmBodResponse"; - errorList.add(errMsg); + String errMsg = "Error parsing the ConfirmBodResponse: "+e.toString(); + errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "ParserConfigurationException")); Debug.logError(e, errMsg, module); } catch (IOException e) { - String errMsg = "Error parsing the ConfirmBodResponse"; - errorList.add(errMsg); + String errMsg = "Error parsing the ConfirmBodResponse: "+e.toString(); + errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "IOException")); Debug.logError(e, errMsg, module); } @@ -278,13 +280,13 @@ public class OagisServices { try { Map oagisMsgInfoResult = dispatcher.runSync("createOagisMessageInfo", oagisMsgInfoCtx); if (ServiceUtil.isError(oagisMsgInfoResult)){ - String errMsg = "Error creating OagisMessageInfo for the Incoming Message"; - errorList.add(errMsg); + String errMsg = "Error creating OagisMessageInfo for the Incoming Message: "+ServiceUtil.getErrorMessage(oagisMsgInfoResult); + errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "CreateOagisMessageInfoServiceError")); Debug.logError(errMsg, module); } } catch (GenericServiceException e){ - String errMsg = "Error creating OagisMessageInfo for the Incoming Message"; - errorList.add(errMsg); + String errMsg = "Error creating OagisMessageInfo for the Incoming Message: "+e.toString(); + errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "GenericServiceException")); Debug.logError(e, errMsg, module); } @@ -298,8 +300,8 @@ public class OagisServices { try { oagisMsgInfo = delegator.findByPrimaryKey("OagisMessageInfo", oagisMsgErrorCtx); } catch (GenericEntityException e){ - String errMsg = "Error Getting Entity OagisMessageInfo"; - errorList.add(errMsg); + String errMsg = "Error Getting Entity OagisMessageInfo: "+e.toString(); + errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "GenericEntityException")); Debug.logError(e, errMsg, module); } @@ -310,29 +312,28 @@ public class OagisServices { try { Map oagisMsgErrorInfoResult = dispatcher.runSync("createOagisMessageErrorInfo", oagisMsgErrorCtx); if (ServiceUtil.isError(oagisMsgErrorInfoResult)){ - String errMsg = "Error creating OagisMessageErrorInfo"; - errorList.add(errMsg); + String errMsg = "Error creating OagisMessageErrorInfo: "+ServiceUtil.getErrorMessage(oagisMsgErrorInfoResult); + errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "CreateOagisMessageErrorInfoServiceError")); Debug.logError(errMsg, module); } } catch (GenericServiceException e){ - String errMsg = "Error creating OagisMessageErrorInfo"; - errorList.add(errMsg); + String errMsg = "Error creating OagisMessageErrorInfo: "+e.toString(); + errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "GenericServiceException")); Debug.logError(e, errMsg, module); } } else{ - String errMsg = "No such message with an error was found in OagisMessageInfoEntity ; Not creating OagisMessageErrorInfo"; + String errMsg = "No such message with an error was found in OagisMessageInfo Entity ; Not creating OagisMessageErrorInfo"; Debug.logWarning(errMsg, module); - errorList.add(errMsg); + errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "OagisMessageInfoNotFoundError")); } Map result = new HashMap(); result.put("contentType", "text/plain"); - if (errorList.size()>0){ + if (errorMapList.size()>0){ result.putAll(oagisMsgInfoCtx); String errMsg = "Error Processing Received Message"; - result.put("description", errMsg); - result.put("reasonCode", "00000"); + result.put("errorMapList", errorMapList); //result.putAll(ServiceUtil.returnError(errMsg)); return result; } diff --git a/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java b/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java index 1c7395fc40..b2819f92aa 100644 --- a/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java +++ b/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java @@ -97,13 +97,21 @@ public class OagisShipmentServices { LocalDispatcher dispatcher = ctx.getDispatcher(); GenericDelegator delegator = ctx.getDelegator(); - List errorList = new LinkedList(); + List errorMapList = FastList.newInstance(); Document doc = null; try { doc = UtilXml.readXmlDocument(in, true, "ShowShipment"); - } catch (Exception e) { - String errMsg = "Error parsing the ShowShipmentResponse"; - errorList.add(errMsg); + } catch (SAXException e) { + String errMsg = "Error parsing the ShowShipmentResponse: "+e.toString(); + errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "SAXException")); + Debug.logError(e, errMsg, module); + } catch (ParserConfigurationException e) { + String errMsg = "Error parsing the ShowShipmentResponse: "+e.toString(); + errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "ParserConfigurationException")); + Debug.logError(e, errMsg, module); + } catch (IOException e) { + String errMsg = "Error parsing the ShowShipmentResponse: "+e.toString(); + errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "IOException")); Debug.logError(e, errMsg, module); } @@ -111,8 +119,7 @@ public class OagisShipmentServices { try { userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system")); } catch (GenericEntityException e){ - String errMsg = "Error Getting UserLogin with userLoginId system "; - errorList.add(errMsg); + String errMsg = "Error Getting UserLogin with userLoginId system: "+e.toString(); Debug.logError(e, errMsg, module); } @@ -147,13 +154,13 @@ public class OagisShipmentServices { try { Map oagisMsgInfoResult = dispatcher.runSync("createOagisMessageInfo", oagisMsgInfoCtx); if (ServiceUtil.isError(oagisMsgInfoResult)){ - String errMsg = "Error creating OagisMessageInfo for the Incoming Message"; - errorList.add(errMsg); + String errMsg = ServiceUtil.getErrorMessage(oagisMsgInfoResult); + errorMapList.add(UtilMisc.toMap("description", errMsg, "resonCode", "CreateOagisMessageInfoServiceError")); Debug.logError(errMsg, module); } } catch (GenericServiceException e){ - String errMsg = "Error creating OagisMessageInfo for the Incoming Message"; - errorList.add(errMsg); + String errMsg = "Error creating OagisMessageInfo for the Incoming Message: "+e.toString(); + errorMapList.add(UtilMisc.toMap("description", errMsg, "resonCode", "GenericServiceException")); Debug.logError(e, errMsg, module); } @@ -200,31 +207,31 @@ public class OagisShipmentServices { try { Map resultMap = dispatcher.runSync("issueSerializedInvToShipmentPackageAndSetTracking", isitspastCtx); if (ServiceUtil.isError(resultMap)){ - String errMsg = "Error executing issueSerializedInvToShipmentPackageAndSetTracking Service"; - errorList.add(errMsg); + String errMsg = ServiceUtil.getErrorMessage(resultMap); + errorMapList.add(UtilMisc.toMap("description", errMsg, "resonCode", "IssueSerializedInvServiceError")); Debug.logError(errMsg, module); } } catch(GenericServiceException e) { Debug.logInfo(e, module); - errorList.add(e.getMessage()); + String errMsg = "Error executing issueSerializedInvToShipmentPackageAndSetTracking Service: "+e.toString(); + errorMapList.add(UtilMisc.toMap("description", errMsg, "resonCode", "GenericServiceException")); } } catch (GenericEntityException e) { + String errMsg = "Error executing issueSerializedInvToShipmentPackageAndSetTracking Service: "+e.toString(); + errorMapList.add(UtilMisc.toMap("description", errMsg, "resonCode", "GenericEntityException")); Debug.logInfo(e, module); - errorList.add(e.getMessage()); } Map result = new HashMap(); result.put("contentType","text/plain"); - if (errorList.size() > 0) { - // error message generation - result.putAll(oagisMsgInfoCtx); - result.put(ModelService.RESPONSE_MESSAGE,ModelService.RESPOND_ERROR); - result.put(ModelService.ERROR_MESSAGE_LIST, errorList); - result.put("reasonCode", "1000"); - result.put("description", "processing message failed"); - } else { - result.put(ModelService.RESPONSE_MESSAGE,ModelService.RESPOND_SUCCESS); + if (errorMapList.size() > 0) { + //result.putAll(ServiceUtil.returnError("Errors found processing message")); + result.putAll(oagisMsgInfoCtx); + result.put("errorMapList", errorMapList); + return result; } + + result.putAll(ServiceUtil.returnSuccess("Service Completed Successfully")); return result; } @@ -614,4 +621,4 @@ public class OagisShipmentServices { } return result; } -} \ No newline at end of file +} diff --git a/specialpurpose/oagis/webapp/oagis/message/ConfirmBod.ftl b/specialpurpose/oagis/webapp/oagis/message/ConfirmBod.ftl index beda53cca8..7a85debd23 100644 --- a/specialpurpose/oagis/webapp/oagis/message/ConfirmBod.ftl +++ b/specialpurpose/oagis/webapp/oagis/message/ConfirmBod.ftl @@ -50,10 +50,12 @@ ${origRef?if_exists} - - ${errorDescription?if_exists} - ${errorReasonCode?if_exists} - + <#list errorMapList as errorMap> + + ${errorMap.description?if_exists} + ${errorMap.reasonCode?if_exists} + +