public static Map<String,Object> handleFedexShipReply(String fDXShipReplyString,GenericValue shipmentRouteSegment,List<GenericValue> shipmentPackageRouteSegs,Locale locale) throws GenericEntityException {
  List<Object> errorList=FastList.newInstance();
  GenericValue shipmentPackageRouteSeg=shipmentPackageRouteSegs.get(0);
  Document fdxShipReplyDocument=null;
  try {
    fdxShipReplyDocument=UtilXml.readXmlDocument(fDXShipReplyString,false);
  }
 catch (  Exception e) {
    String errorMessage="Error parsing the FDXShipReply: " + e.toString();
    Debug.logError(e,errorMessage,module);
  }
  if (UtilValidate.isEmpty(fdxShipReplyDocument)) {
    return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,"FacilityShipmentFedexShipmentTemplateParsingError",locale));
  }
  Element rootElement=fdxShipReplyDocument.getDocumentElement();
  handleErrors(rootElement,errorList,locale);
  if (UtilValidate.isNotEmpty(errorList)) {
    return ServiceUtil.returnError(errorList);
  }
  Element trackingElement=UtilXml.firstChildElement(rootElement,"Tracking");
  String trackingNumber=UtilXml.childElementValue(trackingElement,"TrackingNumber");
  Element labelElement=UtilXml.firstChildElement(rootElement,"Labels");
  String encodedImageString=UtilXml.childElementValue(labelElement,"OutboundLabel");
  if (UtilValidate.isEmpty(encodedImageString)) {
    Debug.logError("Cannot find FDXShipReply label. FDXShipReply document is: " + fDXShipReplyString,module);
    return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,"FacilityShipmentFedexShipmentTemplateLabelNotFound",UtilMisc.toMap("shipmentPackageRouteSeg",shipmentPackageRouteSeg,"fDXShipReplyString",fDXShipReplyString),locale));
  }
  byte[] labelBytes=Base64.base64Decode(encodedImageString.getBytes());
  if (labelBytes != null) {
    shipmentPackageRouteSeg.setBytes("labelImage",labelBytes);
  }
 else {
    Debug.logInfo("Failed to either decode returned FedEx label or no data found in Labels/OutboundLabel.",module);
  }
  shipmentPackageRouteSeg.set("trackingCode",trackingNumber);
  shipmentPackageRouteSeg.set("labelHtml",encodedImageString);
  shipmentPackageRouteSeg.store();
  shipmentRouteSegment.set("trackingIdNumber",trackingNumber);
  shipmentRouteSegment.put("carrierServiceStatusId","SHRSCS_CONFIRMED");
  shipmentRouteSegment.store();
  return ServiceUtil.returnSuccess(UtilProperties.getMessage(resourceError,"FacilityShipmentFedexShipmentConfirmed",locale));
}

public static Map < String , Object > handleFedexShipReply ( String fDXShipReplyString , GenericValue shipmentRouteSegment , List < GenericValue > shipmentPackageRouteSegs , Locale locale ) throws GenericEntityException { List < Object > errorList = FastList . newInstance ( ) ; GenericValue shipmentPackageRouteSeg = shipmentPackageRouteSegs . get ( 0 ) ; Document fdxShipReplyDocument = null ; try { fdxShipReplyDocument = UtilXml . readXmlDocument ( fDXShipReplyString , false ) ; } catch ( Exception e ) { String errorMessage = "Error parsing the FDXShipReply: " + e . toString ( ) ; Debug . logError ( e , errorMessage , module ) ; } if ( UtilValidate . isEmpty ( fdxShipReplyDocument ) ) { return ServiceUtil . returnError ( UtilProperties . getMessage ( resourceError , "FacilityShipmentFedexShipmentTemplateParsingError" , locale ) ) ; } Element rootElement = fdxShipReplyDocument . getDocumentElement ( ) ; handleErrors ( rootElement , errorList , locale ) ; if ( UtilValidate . isNotEmpty ( errorList ) ) { return ServiceUtil . returnError ( errorList ) ; } Element trackingElement = UtilXml . firstChildElement ( rootElement , "Tracking" ) ; String trackingNumber = UtilXml . childElementValue ( trackingElement , "TrackingNumber" ) ; Element labelElement = UtilXml . firstChildElement ( rootElement , "Labels" ) ; String encodedImageString = UtilXml . childElementValue ( labelElement , "OutboundLabel" ) ; if ( UtilValidate . isEmpty ( encodedImageString ) ) { Debug . logError ( "Cannot find FDXShipReply label. FDXShipReply document is: " + fDXShipReplyString , module ) ; return ServiceUtil . returnError ( UtilProperties . getMessage ( resourceError , "FacilityShipmentFedexShipmentTemplateLabelNotFound" , UtilMisc . toMap ( "shipmentPackageRouteSeg" , shipmentPackageRouteSeg , "fDXShipReplyString" , fDXShipReplyString ) , locale ) ) ; } byte [ ] labelBytes = Base64 . base64Decode ( encodedImageString . getBytes ( ) ) ; if ( labelBytes != null ) { shipmentPackageRouteSeg . setBytes ( "labelImage" , labelBytes ) ; } else { Debug . logInfo ( "Failed to either decode returned FedEx label or no data found in Labels/OutboundLabel." , module ) ; } shipmentPackageRouteSeg . set ( "trackingCode" , trackingNumber ) ; shipmentPackageRouteSeg . set ( "labelHtml" , encodedImageString ) ; shipmentPackageRouteSeg . store ( ) ; shipmentRouteSegment . set ( "trackingIdNumber" , trackingNumber ) ; shipmentRouteSegment . put ( "carrierServiceStatusId" , "SHRSCS_CONFIRMED" ) ; shipmentRouteSegment . store ( ) ; return ServiceUtil . returnSuccess ( UtilProperties . getMessage ( resourceError , "FacilityShipmentFedexShipmentConfirmed" , locale ) ) ; }
extract the tracking number and shipping label from the fdxshipreply xml string
