| 7908 |
manish.sha |
1 |
package com;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.config.ConfigException;
|
|
|
4 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
|
|
5 |
|
|
|
6 |
import com.fedex.track.stub.*;
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
/**
|
|
|
10 |
* Demo of using the Track service with Axis
|
|
|
11 |
* to track a shipment.
|
|
|
12 |
* <p>
|
|
|
13 |
* com.fedex.track.stub is generated via WSDL2Java, like this:<br>
|
|
|
14 |
* <pre>
|
|
|
15 |
* java org.apache.axis.wsdl.WSDL2Java -w -p com.fedex.track.stub http://www.fedex.com/...../TrackService?wsdl
|
|
|
16 |
* </pre>
|
|
|
17 |
*
|
|
|
18 |
* This sample code has been tested with JDK 5 and Apache Axis 1.4
|
|
|
19 |
*/
|
|
|
20 |
public class TrackWebServiceClient {
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
public static TrackReply getTrackingUpdates(String trackingNumber){
|
|
|
24 |
TrackRequest request = new TrackRequest();
|
|
|
25 |
|
|
|
26 |
request.setClientDetail(createClientDetail());
|
|
|
27 |
request.setWebAuthenticationDetail(createWebAuthenticationDetail());
|
|
|
28 |
|
|
|
29 |
TransactionDetail transactionDetail = new TransactionDetail();
|
|
|
30 |
transactionDetail.setCustomerTransactionId("Tracking Request");
|
|
|
31 |
request.setTransactionDetail(transactionDetail);
|
|
|
32 |
|
|
|
33 |
VersionId versionId = new VersionId("trck", 6, 0, 0);
|
|
|
34 |
request.setVersion(versionId);
|
|
|
35 |
|
|
|
36 |
TrackPackageIdentifier packageIdentifier = new TrackPackageIdentifier();
|
|
|
37 |
packageIdentifier.setValue(trackingNumber); // tracking number
|
|
|
38 |
packageIdentifier.setType(TrackIdentifierType.TRACKING_NUMBER_OR_DOORTAG); // Track identifier types are TRACKING_NUMBER_OR_DOORTAG, TRACKING_CONTROL_NUMBER, ....
|
|
|
39 |
request.setPackageIdentifier(packageIdentifier);
|
|
|
40 |
request.setIncludeDetailedScans(new Boolean(true));
|
|
|
41 |
TrackReply reply= new TrackReply();
|
|
|
42 |
|
|
|
43 |
try{
|
|
|
44 |
// Initializing the service
|
|
|
45 |
TrackServiceLocator service;
|
|
|
46 |
TrackPortType port;
|
|
|
47 |
|
|
|
48 |
service = new TrackServiceLocator();
|
|
|
49 |
updateEndPoint(service);
|
|
|
50 |
port = service.getTrackServicePort();
|
|
|
51 |
|
|
|
52 |
reply = port.track(request); // This is the call to the web service passing in a request object and returning a reply object
|
|
|
53 |
|
|
|
54 |
printNotifications(reply.getNotifications());
|
|
|
55 |
|
|
|
56 |
if (isResponseOk(reply.getHighestSeverity())) // check if the call was successful
|
|
|
57 |
{
|
|
|
58 |
return reply;
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
catch (Exception e) {
|
|
|
62 |
e.printStackTrace();
|
|
|
63 |
}
|
|
|
64 |
return null;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
private static boolean isResponseOk(NotificationSeverityType notificationSeverityType) {
|
|
|
68 |
if (notificationSeverityType == null) {
|
|
|
69 |
return false;
|
|
|
70 |
}
|
|
|
71 |
if (notificationSeverityType.equals(NotificationSeverityType.WARNING) ||
|
|
|
72 |
notificationSeverityType.equals(NotificationSeverityType.NOTE) ||
|
|
|
73 |
notificationSeverityType.equals(NotificationSeverityType.SUCCESS)) {
|
|
|
74 |
return true;
|
|
|
75 |
}
|
|
|
76 |
return false;
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
private static ClientDetail createClientDetail() {
|
|
|
81 |
ClientDetail clientDetail = new ClientDetail();
|
|
|
82 |
String accountNumber ="";
|
|
|
83 |
try {
|
|
|
84 |
accountNumber = ConfigClient.getClient().get("fedex_account_number");
|
|
|
85 |
} catch (ConfigException e) {
|
|
|
86 |
// TODO Auto-generated catch block
|
|
|
87 |
e.printStackTrace();
|
|
|
88 |
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
String meterNumber ="";
|
|
|
92 |
try {
|
|
|
93 |
meterNumber = ConfigClient.getClient().get("fedex_meter_number");
|
|
|
94 |
} catch (ConfigException e) {
|
|
|
95 |
// TODO Auto-generated catch block
|
|
|
96 |
e.printStackTrace();
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
/*if (accountNumber == null) {
|
|
|
100 |
accountNumber = "510087089"; // Replace "XXX" with clients account number
|
|
|
101 |
}
|
|
|
102 |
if (meterNumber == null) {
|
|
|
103 |
meterNumber = "118585428"; // Replace "XXX" with clients meter number
|
|
|
104 |
}*/
|
|
|
105 |
|
|
|
106 |
clientDetail.setAccountNumber(accountNumber);
|
|
|
107 |
clientDetail.setMeterNumber(meterNumber);
|
|
|
108 |
return clientDetail;
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
private static WebAuthenticationDetail createWebAuthenticationDetail() {
|
|
|
112 |
WebAuthenticationCredential wac = new WebAuthenticationCredential();
|
|
|
113 |
String key="";
|
|
|
114 |
try {
|
|
|
115 |
key = ConfigClient.getClient().get("fedex_authenication_key");
|
|
|
116 |
} catch (ConfigException e) {
|
|
|
117 |
// TODO Auto-generated catch block
|
|
|
118 |
e.printStackTrace();
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
String password="";
|
|
|
122 |
try {
|
|
|
123 |
password = ConfigClient.getClient().get("fedex_authenication_password");
|
|
|
124 |
} catch (ConfigException e) {
|
|
|
125 |
// TODO Auto-generated catch block
|
|
|
126 |
e.printStackTrace();
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
/*if (key == null) {
|
|
|
131 |
key = "4XqfCFRFM4uXe6Wm"; // Replace "XXX" with clients key
|
|
|
132 |
}
|
|
|
133 |
if (password == null) {
|
|
|
134 |
password = "LtIgtKmluqOPikdNmTjXWPkTo"; // Replace "XXX" with clients password
|
|
|
135 |
}*/
|
|
|
136 |
wac.setKey(key);
|
|
|
137 |
wac.setPassword(password);
|
|
|
138 |
return new WebAuthenticationDetail(wac);
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
private static void updateEndPoint(TrackServiceLocator serviceLocator) {
|
|
|
142 |
String endPoint="";
|
|
|
143 |
try {
|
|
|
144 |
endPoint = ConfigClient.getClient().get("fedex_endpoint_address_track");
|
|
|
145 |
} catch (ConfigException e) {
|
|
|
146 |
// TODO Auto-generated catch block
|
|
|
147 |
e.printStackTrace();
|
|
|
148 |
}
|
|
|
149 |
if (endPoint != null) {
|
|
|
150 |
serviceLocator.setTrackServicePortEndpointAddress(endPoint);
|
|
|
151 |
}
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
private static void printNotifications(Notification[] notifications) {
|
|
|
155 |
System.out.println("Notifications:");
|
|
|
156 |
if (notifications == null || notifications.length == 0) {
|
|
|
157 |
System.out.println(" No notifications returned");
|
|
|
158 |
}
|
|
|
159 |
for (int i=0; i < notifications.length; i++){
|
|
|
160 |
Notification n = notifications[i];
|
|
|
161 |
System.out.print(" Notification no. " + i + ": ");
|
|
|
162 |
if (n == null) {
|
|
|
163 |
System.out.println("null");
|
|
|
164 |
continue;
|
|
|
165 |
} else {
|
|
|
166 |
System.out.println("");
|
|
|
167 |
}
|
|
|
168 |
NotificationSeverityType nst = n.getSeverity();
|
|
|
169 |
|
|
|
170 |
System.out.println(" Severity: " + (nst == null ? "null" : nst.getValue()));
|
|
|
171 |
System.out.println(" Code: " + n.getCode());
|
|
|
172 |
System.out.println(" Message: " + n.getMessage());
|
|
|
173 |
System.out.println(" Source: " + n.getSource());
|
|
|
174 |
}
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
}
|