Author: ashish
Date: Mon Sep 7 16:04:16 2009 New Revision: 812213 URL: http://svn.apache.org/viewvc?rev=812213&view=rev Log: User friendly message will be displayed to User Interface. More improvements can be done in this commit. Now the message looks like: In case of success: The following occurred: The data exported successfully to eBay. In case of error: The Following Errors Occurred: Input data for tag <Item.Quantity> is invalid or missing. Please check API documentation. Previously the message was shown as it is in XML form returned from ebay server. Modified: ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/ProductsExportToEbay.java Modified: ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/ProductsExportToEbay.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/ProductsExportToEbay.java?rev=812213&r1=812212&r2=812213&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/ProductsExportToEbay.java (original) +++ ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/ProductsExportToEbay.java Mon Sep 7 16:04:16 2009 @@ -81,14 +81,18 @@ Debug.logError("Exception in exportToEbay " + e, module); return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionInExportToEbay", locale)); } - String successMessage = UtilProperties.getMessage(resource, "productsExportToEbay.productItemsSentToEbay", locale); + String responseMessage = UtilProperties.getMessage(resource, "productsExportToEbay.productItemsSentToEbay", locale); if (result != null) { - String responseString = (String)result.get("successMessage"); - if (UtilValidate.isNotEmpty(responseString)) { - successMessage = responseString; + Map response = exportToEbayResponse((String) result.get("successMessage")); + if (UtilValidate.isNotEmpty(response) && "fail".equals(response.get("responseMessage"))) { + responseMessage = (String) response.get("errorMessage"); + return ServiceUtil.returnError(responseMessage); + } else if (UtilValidate.isNotEmpty(response) && "success".equals(response.get("responseMessage"))) { + responseMessage = (String) response.get("successMessage"); + return ServiceUtil.returnSuccess(responseMessage); } } - return ServiceUtil.returnSuccess(successMessage); + return ServiceUtil.returnSuccess(responseMessage); } private static void appendRequesterCredentials(Element elem, Document doc, String token) { @@ -562,5 +566,29 @@ } return buildEbayConfigContext; } - + + private static Map exportToEbayResponse(String msg) { + Map result = FastMap.newInstance(); + try { + Document docResponse = UtilXml.readXmlDocument(msg, true); + Element elemResponse = docResponse.getDocumentElement(); + String ack = UtilXml.childElementValue(elemResponse, "Ack", "Failure"); + if (ack != null && "Failure".equals(ack)) { + String errorMessage = ""; + List errorList = UtilXml.childElementList(elemResponse, "Errors"); + Iterator errorElemIter = errorList.iterator(); + while (errorElemIter.hasNext()) { + Element errorElement = (Element) errorElemIter.next(); + errorMessage = UtilXml.childElementValue(errorElement, "LongMessage"); + } + result = ServiceUtil.returnFailure(errorMessage); + } else { + result = ServiceUtil.returnSuccess("The data exported successfully to eBay."); + } + } catch (Exception e) { + Debug.logError("Error in processing xml string" + e.getMessage(), module); + return ServiceUtil.returnFailure(); + } + return result; + } } |
Free forum by Nabble | Edit this page |