| 7908 |
manish.sha |
1 |
package com;
|
|
|
2 |
|
|
|
3 |
import com.fedex.track.stub.*;
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
/**
|
|
|
7 |
* Demo of using the Track service with Axis
|
|
|
8 |
* to track a shipment.
|
|
|
9 |
* <p>
|
|
|
10 |
* com.fedex.track.stub is generated via WSDL2Java, like this:<br>
|
|
|
11 |
* <pre>
|
|
|
12 |
* java org.apache.axis.wsdl.WSDL2Java -w -p com.fedex.track.stub http://www.fedex.com/...../TrackService?wsdl
|
|
|
13 |
* </pre>
|
|
|
14 |
*
|
|
|
15 |
* This sample code has been tested with JDK 5 and Apache Axis 1.4
|
|
|
16 |
*/
|
|
|
17 |
public class TrackWebServiceClient {
|
|
|
18 |
|
| 8397 |
manish.sha |
19 |
public static void main(String[] args){
|
|
|
20 |
ClientDetail clientDetail = new ClientDetail();
|
|
|
21 |
String accountNumber ="377498933";
|
|
|
22 |
String meterNumber ="105452205";
|
|
|
23 |
clientDetail.setAccountNumber(accountNumber);
|
|
|
24 |
clientDetail.setMeterNumber(meterNumber);
|
|
|
25 |
|
|
|
26 |
WebAuthenticationCredential wac = new WebAuthenticationCredential();
|
|
|
27 |
String key="ggqFObyBaF3ECQbQ";
|
|
|
28 |
String password="LIf9WMXsKqJV30AsGbK2Fy4TQ";
|
|
|
29 |
wac.setKey(key);
|
|
|
30 |
wac.setPassword(password);
|
|
|
31 |
|
|
|
32 |
String endPoint="https://ws.fedex.com:443/web-services/track";
|
|
|
33 |
TrackReply trck= getTrackingUpdates("796869788166", clientDetail, new WebAuthenticationDetail(wac), endPoint);
|
|
|
34 |
}
|
| 7908 |
manish.sha |
35 |
|
| 7925 |
manish.sha |
36 |
public static TrackReply getTrackingUpdates(String trackingNumber, ClientDetail clientDetail, WebAuthenticationDetail wac, String endpointAddress){
|
| 7908 |
manish.sha |
37 |
TrackRequest request = new TrackRequest();
|
|
|
38 |
|
| 7925 |
manish.sha |
39 |
request.setClientDetail(clientDetail);
|
|
|
40 |
request.setWebAuthenticationDetail(wac);
|
| 7908 |
manish.sha |
41 |
|
|
|
42 |
TransactionDetail transactionDetail = new TransactionDetail();
|
|
|
43 |
transactionDetail.setCustomerTransactionId("Tracking Request");
|
|
|
44 |
request.setTransactionDetail(transactionDetail);
|
|
|
45 |
|
|
|
46 |
VersionId versionId = new VersionId("trck", 6, 0, 0);
|
|
|
47 |
request.setVersion(versionId);
|
|
|
48 |
|
|
|
49 |
TrackPackageIdentifier packageIdentifier = new TrackPackageIdentifier();
|
|
|
50 |
packageIdentifier.setValue(trackingNumber); // tracking number
|
|
|
51 |
packageIdentifier.setType(TrackIdentifierType.TRACKING_NUMBER_OR_DOORTAG); // Track identifier types are TRACKING_NUMBER_OR_DOORTAG, TRACKING_CONTROL_NUMBER, ....
|
|
|
52 |
request.setPackageIdentifier(packageIdentifier);
|
|
|
53 |
request.setIncludeDetailedScans(new Boolean(true));
|
|
|
54 |
TrackReply reply= new TrackReply();
|
|
|
55 |
|
|
|
56 |
try{
|
|
|
57 |
// Initializing the service
|
|
|
58 |
TrackServiceLocator service;
|
|
|
59 |
TrackPortType port;
|
|
|
60 |
|
|
|
61 |
service = new TrackServiceLocator();
|
| 7925 |
manish.sha |
62 |
updateEndPoint(service,endpointAddress);
|
| 7908 |
manish.sha |
63 |
port = service.getTrackServicePort();
|
| 8395 |
manish.sha |
64 |
System.out.println("In Tracking Method of Fedex");
|
| 7908 |
manish.sha |
65 |
reply = port.track(request); // This is the call to the web service passing in a request object and returning a reply object
|
|
|
66 |
|
|
|
67 |
printNotifications(reply.getNotifications());
|
|
|
68 |
|
|
|
69 |
if (isResponseOk(reply.getHighestSeverity())) // check if the call was successful
|
|
|
70 |
{
|
|
|
71 |
return reply;
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
catch (Exception e) {
|
|
|
75 |
e.printStackTrace();
|
|
|
76 |
}
|
|
|
77 |
return null;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
private static boolean isResponseOk(NotificationSeverityType notificationSeverityType) {
|
|
|
81 |
if (notificationSeverityType == null) {
|
|
|
82 |
return false;
|
|
|
83 |
}
|
|
|
84 |
if (notificationSeverityType.equals(NotificationSeverityType.WARNING) ||
|
|
|
85 |
notificationSeverityType.equals(NotificationSeverityType.NOTE) ||
|
|
|
86 |
notificationSeverityType.equals(NotificationSeverityType.SUCCESS)) {
|
|
|
87 |
return true;
|
|
|
88 |
}
|
|
|
89 |
return false;
|
|
|
90 |
}
|
|
|
91 |
|
| 7925 |
manish.sha |
92 |
private static void updateEndPoint(TrackServiceLocator serviceLocator, String endPoint) {
|
| 7908 |
manish.sha |
93 |
if (endPoint != null) {
|
|
|
94 |
serviceLocator.setTrackServicePortEndpointAddress(endPoint);
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
private static void printNotifications(Notification[] notifications) {
|
|
|
99 |
System.out.println("Notifications:");
|
|
|
100 |
if (notifications == null || notifications.length == 0) {
|
|
|
101 |
System.out.println(" No notifications returned");
|
|
|
102 |
}
|
|
|
103 |
for (int i=0; i < notifications.length; i++){
|
|
|
104 |
Notification n = notifications[i];
|
|
|
105 |
System.out.print(" Notification no. " + i + ": ");
|
|
|
106 |
if (n == null) {
|
|
|
107 |
System.out.println("null");
|
|
|
108 |
continue;
|
|
|
109 |
} else {
|
|
|
110 |
System.out.println("");
|
|
|
111 |
}
|
|
|
112 |
NotificationSeverityType nst = n.getSeverity();
|
|
|
113 |
|
|
|
114 |
System.out.println(" Severity: " + (nst == null ? "null" : nst.getValue()));
|
|
|
115 |
System.out.println(" Code: " + n.getCode());
|
|
|
116 |
System.out.println(" Message: " + n.getMessage());
|
|
|
117 |
System.out.println(" Source: " + n.getSource());
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
}
|