Rev 903 | Rev 2942 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.serving.services;import in.shop2020.config.ConfigException;import in.shop2020.serving.model.ShipmentUpdate;import in.shop2020.thrift.clients.config.ConfigClient;import java.util.ArrayList;import java.util.List;import javax.xml.xpath.XPath;import javax.xml.xpath.XPathConstants;import javax.xml.xpath.XPathExpressionException;import javax.xml.xpath.XPathFactory;import org.apache.log4j.Logger;import org.w3c.dom.Element;import org.w3c.dom.NodeList;import org.xml.sax.InputSource;public class BlueDartTrackingService {private static Logger log = Logger.getLogger(Class.class);private static String BLUEDART_URL;static{try {BLUEDART_URL = ConfigClient.getClient().get("bluedart_update_url");} catch (ConfigException e) {BLUEDART_URL = "file:///home/ashish/Downloads/BlueDart_Track.xml";e.printStackTrace();}}public List<ShipmentUpdate> getUpdates(String awbNumber){String uri = BLUEDART_URL + awbNumber + ",";//String uri = BLUEDART_URL;log.info("Blue Dart Update URL: " + uri);InputSource inputSource = new InputSource(uri);XPath xpath = XPathFactory.newInstance().newXPath();String expression = "/ShipmentData/Shipment/Scans/ScanDetail";NodeList nodes = null;try {nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);} catch(XPathExpressionException xpee) {return null;}List<ShipmentUpdate> updates = new ArrayList<ShipmentUpdate>();System.out.println("Action date\t\t\tUpdate City\t\t\tTracki Code Desc" );for(int i=nodes.getLength()-1; i>=0; i--) {Element hawbUpdate = (Element) nodes.item(i);ShipmentUpdate update = new ShipmentUpdate();update.date = getElementTextContent(hawbUpdate, "ScanDate");update.time = getElementTextContent(hawbUpdate, "ScanTime");update.city = getElementTextContent(hawbUpdate, "ScannedLocation");update.description = getElementTextContent(hawbUpdate, "Scan");updates.add(update);}return updates;}private String getElementTextContent(Element element, String tagName){return element.getElementsByTagName(tagName).item(0).getTextContent();}public static void main(String[] args){System.out.println("Aramax number is " + "6199186044");BlueDartTrackingService service = new BlueDartTrackingService();List<ShipmentUpdate> updates = service.getUpdates("6199186044");for(ShipmentUpdate update: updates){System.out.println(update.toString());}}}