| 1418 |
ankur.sing |
1 |
package in.shop2020.serving.services;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.config.ConfigException;
|
|
|
4 |
import in.shop2020.serving.model.ShipmentUpdate;
|
|
|
5 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
|
|
6 |
|
|
|
7 |
import java.util.ArrayList;
|
|
|
8 |
import java.util.List;
|
|
|
9 |
|
|
|
10 |
import javax.xml.xpath.XPath;
|
|
|
11 |
import javax.xml.xpath.XPathConstants;
|
|
|
12 |
import javax.xml.xpath.XPathExpressionException;
|
|
|
13 |
import javax.xml.xpath.XPathFactory;
|
|
|
14 |
|
|
|
15 |
import org.apache.log4j.Logger;
|
|
|
16 |
import org.w3c.dom.Element;
|
|
|
17 |
import org.w3c.dom.NodeList;
|
|
|
18 |
import org.xml.sax.InputSource;
|
|
|
19 |
|
|
|
20 |
public class AFLTrackingService {
|
|
|
21 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
22 |
|
|
|
23 |
private static String AFL_URL;
|
|
|
24 |
|
|
|
25 |
static{
|
|
|
26 |
try {
|
|
|
27 |
AFL_URL = ConfigClient.getClient().get("afl_update_url");
|
|
|
28 |
} catch (ConfigException e) {
|
|
|
29 |
e.printStackTrace();
|
|
|
30 |
}
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
public List<ShipmentUpdate> getUpdates(String awbNumber){
|
|
|
34 |
//String uri = "http://trackntrace.aflwiz.com/aflwiztrack?shpntnum=" + awbNumber;
|
|
|
35 |
String uri = AFL_URL + awbNumber + ",";
|
|
|
36 |
log.info("Blue Dart Update URL: " + uri);
|
|
|
37 |
InputSource inputSource = new InputSource(uri);
|
|
|
38 |
XPath xpath = XPathFactory.newInstance().newXPath();
|
|
|
39 |
|
|
|
40 |
String expression = "/SHIPMENTTRACK/SHIPMENTREPORT/CHECKPOINTDETAILS/CHECKPOINTS";
|
|
|
41 |
NodeList nodes = null;
|
|
|
42 |
try {
|
|
|
43 |
nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);
|
|
|
44 |
} catch(XPathExpressionException xpee) {
|
|
|
45 |
return null;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
List<ShipmentUpdate> updates = new ArrayList<ShipmentUpdate>();
|
|
|
49 |
|
|
|
50 |
System.out.println("Action date\t\t\tUpdate City\t\t\tTracki Code Desc" );
|
|
|
51 |
for(int i=0; i<nodes.getLength(); i++) {
|
|
|
52 |
Element hawbUpdate = (Element) nodes.item(i);
|
|
|
53 |
ShipmentUpdate update = new ShipmentUpdate();
|
|
|
54 |
update.date = getElementTextContent(hawbUpdate, "CHECKDATE");
|
|
|
55 |
update.time = getElementTextContent(hawbUpdate, "CHECKTIME");
|
|
|
56 |
update.city = getElementTextContent(hawbUpdate, "LOCATIONNAME");
|
|
|
57 |
update.description = getElementTextContent(hawbUpdate, "CHECKPOINTDESCRIPTION");
|
|
|
58 |
updates.add(update);
|
|
|
59 |
}
|
|
|
60 |
return updates;
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
private String getElementTextContent(Element element, String tagName){
|
|
|
64 |
return element.getElementsByTagName(tagName).item(0).getTextContent();
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
public static void main(String[] args){
|
|
|
68 |
System.out.println("AFL number is " + "4252621801242006");
|
|
|
69 |
AFLTrackingService service = new AFLTrackingService();
|
|
|
70 |
List<ShipmentUpdate> updates = service.getUpdates("4252621801242006");
|
|
|
71 |
for(ShipmentUpdate update: updates){
|
|
|
72 |
System.out.println(update.toString());
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
}
|