Author: sichen
Date: Wed Aug 1 09:41:55 2007 New Revision: 561866 URL: http://svn.apache.org/viewvc?view=rev&rev=561866 Log: USPS address validation service requires either zip5 or city and state, per http://www.usps.com/webtools/htm/Address-Information.htm. Returning failure instead of error in the case of connection trouble or errors returned from USPS, so that transactions aren't rolled back. Modified: ofbiz/trunk/applications/product/config/ProductErrorUiLabels.properties ofbiz/trunk/applications/product/servicedef/services_shipment_usps.xml ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsServices.java Modified: ofbiz/trunk/applications/product/config/ProductErrorUiLabels.properties URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/config/ProductErrorUiLabels.properties?view=diff&rev=561866&r1=561865&r2=561866 ============================================================================== --- ofbiz/trunk/applications/product/config/ProductErrorUiLabels.properties (original) +++ ofbiz/trunk/applications/product/config/ProductErrorUiLabels.properties Wed Aug 1 09:41:55 2007 @@ -18,3 +18,4 @@ ############################################################################### ProductReturnNotYetAcceptedOrAlreadyReceived=This return is not yet accepted or already received. ProductReturnRequestedOK=The return is requested. +ProductUspsAddressValidationStateAndCityOrZipRqd = USPS address validation requires either zip5 or city and state Modified: ofbiz/trunk/applications/product/servicedef/services_shipment_usps.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/servicedef/services_shipment_usps.xml?view=diff&rev=561866&r1=561865&r2=561866 ============================================================================== --- ofbiz/trunk/applications/product/servicedef/services_shipment_usps.xml (original) +++ ofbiz/trunk/applications/product/servicedef/services_shipment_usps.xml Wed Aug 1 09:41:55 2007 @@ -41,8 +41,8 @@ <attribute name="firmName" type="String" mode="INOUT" optional="true"/> <attribute name="address1" type="String" mode="INOUT" optional="false"/> <attribute name="address2" type="String" mode="INOUT" optional="true"/> - <attribute name="city" type="String" mode="INOUT" optional="false"/> - <attribute name="state" type="String" mode="INOUT" optional="false"/> + <attribute name="city" type="String" mode="INOUT" optional="true"/> + <attribute name="state" type="String" mode="INOUT" optional="true"/> <attribute name="zip5" type="String" mode="INOUT" optional="true"/> <attribute name="zip4" type="String" mode="INOUT" optional="true"/> </service> Modified: ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsServices.java?view=diff&rev=561866&r1=561865&r2=561866 ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsServices.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsServices.java Wed Aug 1 09:41:55 2007 @@ -24,13 +24,7 @@ import java.io.IOException; import java.io.OutputStream; import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; +import java.util.*; import javax.xml.parsers.ParserConfigurationException; @@ -58,6 +52,7 @@ public class UspsServices { public final static String module = UspsServices.class.getName(); + public final static String errorResource = "ProductErrorUiLabels"; public static Map uspsRateInquire(DispatchContext dctx, Map context) { @@ -427,6 +422,16 @@ public static Map uspsAddressValidation(DispatchContext dctx, Map context) { + String state = (String) context.get("state"); + String city = (String) context.get("city"); + String zip5 = (String) context.get("zip5"); + if ( (UtilValidate.isEmpty(state) && UtilValidate.isEmpty(city) && UtilValidate.isEmpty(zip5)) || // No state, city or zip5 + (UtilValidate.isEmpty(zip5) && (UtilValidate.isEmpty(state) || UtilValidate.isEmpty(city)))) { // Both state and city are required if no zip5 + String errorMessage = UtilProperties.getMessage(errorResource, "ProductUspsAddressValidationStateAndCityOrZipRqd", (Locale) context.get("locale")); + Debug.logError(errorMessage, module); + return ServiceUtil.returnError(errorMessage); + } + Document requestDocument = createUspsRequestDocument("AddressValidateRequest"); Element addressElement = UtilXml.addChildElement(requestDocument.getDocumentElement(), "Address", requestDocument); @@ -450,17 +455,17 @@ responseDocument = sendUspsRequest("Verify", requestDocument); } catch (UspsRequestException e) { Debug.log(e, module); - return ServiceUtil.returnError("Error sending request for USPS Address Validation service: " + e.getMessage()); + return ServiceUtil.returnFailure("Error sending request for USPS Address Validation service: " + e.getMessage()); } Element respAddressElement = UtilXml.firstChildElement(responseDocument.getDocumentElement(), "Address"); if (respAddressElement == null) { - return ServiceUtil.returnError("Incomplete response from USPS Address Validation service: no Address element found"); + return ServiceUtil.returnFailure("Incomplete response from USPS Address Validation service: no Address element found"); } Element respErrorElement = UtilXml.firstChildElement(respAddressElement, "Error"); if (respErrorElement != null) { - return ServiceUtil.returnError("The following error was returned by the USPS Address Validation service: " + + return ServiceUtil.returnFailure("The following error was returned by the USPS Address Validation service: " + UtilXml.childElementValue(respErrorElement, "Description")); } |
Free forum by Nabble | Edit this page |