Subversion Repositories SmartDukaan

Rev

Rev 7925 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
19
 
7925 manish.sha 20
	public static TrackReply getTrackingUpdates(String trackingNumber, ClientDetail clientDetail, WebAuthenticationDetail wac, String endpointAddress){
7908 manish.sha 21
		TrackRequest request = new TrackRequest();
22
 
7925 manish.sha 23
        request.setClientDetail(clientDetail);
24
        request.setWebAuthenticationDetail(wac);
7908 manish.sha 25
 
26
        TransactionDetail transactionDetail = new TransactionDetail();
27
        transactionDetail.setCustomerTransactionId("Tracking Request"); 
28
        request.setTransactionDetail(transactionDetail);
29
 
30
        VersionId versionId = new VersionId("trck", 6, 0, 0);
31
        request.setVersion(versionId);
32
 
33
        TrackPackageIdentifier packageIdentifier = new TrackPackageIdentifier();
34
        packageIdentifier.setValue(trackingNumber); // tracking number
35
        packageIdentifier.setType(TrackIdentifierType.TRACKING_NUMBER_OR_DOORTAG); // Track identifier types are TRACKING_NUMBER_OR_DOORTAG, TRACKING_CONTROL_NUMBER, ....
36
        request.setPackageIdentifier(packageIdentifier);
37
        request.setIncludeDetailedScans(new Boolean(true));
38
        TrackReply reply= new TrackReply();
39
 
40
        try{
41
        	// Initializing the service
42
			TrackServiceLocator service;
43
			TrackPortType port;
44
 
45
			service = new TrackServiceLocator();
7925 manish.sha 46
			updateEndPoint(service,endpointAddress);
7908 manish.sha 47
			port = service.getTrackServicePort();
8395 manish.sha 48
		    System.out.println("In Tracking Method of Fedex");
7908 manish.sha 49
			reply = port.track(request); // This is the call to the web service passing in a request object and returning a reply object
50
 
51
			printNotifications(reply.getNotifications());
52
 
53
			if (isResponseOk(reply.getHighestSeverity())) // check if the call was successful
54
			{
55
				return reply;
56
			}
57
        }
58
        catch (Exception e) {
59
			e.printStackTrace();
60
		} 
61
		return null;
62
	}
63
 
64
	private static boolean isResponseOk(NotificationSeverityType notificationSeverityType) {
65
		if (notificationSeverityType == null) {
66
			return false;
67
		}
68
		if (notificationSeverityType.equals(NotificationSeverityType.WARNING) ||
69
			notificationSeverityType.equals(NotificationSeverityType.NOTE)    ||
70
			notificationSeverityType.equals(NotificationSeverityType.SUCCESS)) {
71
			return true;
72
		}
73
 		return false;
74
	}
75
 
7925 manish.sha 76
	private static void updateEndPoint(TrackServiceLocator serviceLocator, String endPoint) {
7908 manish.sha 77
		if (endPoint != null) {
78
			serviceLocator.setTrackServicePortEndpointAddress(endPoint);
79
		}
80
	}
81
 
82
	private static void printNotifications(Notification[] notifications) {
83
		System.out.println("Notifications:");
84
		if (notifications == null || notifications.length == 0) {
85
			System.out.println("  No notifications returned");
86
		}
87
		for (int i=0; i < notifications.length; i++){
88
			Notification n = notifications[i];
89
			System.out.print("  Notification no. " + i + ": ");
90
			if (n == null) {
91
				System.out.println("null");
92
				continue;
93
			} else {
94
				System.out.println("");
95
			}
96
			NotificationSeverityType nst = n.getSeverity();
97
 
98
			System.out.println("    Severity: " + (nst == null ? "null" : nst.getValue()));
99
			System.out.println("    Code: " + n.getCode());
100
			System.out.println("    Message: " + n.getMessage());
101
			System.out.println("    Source: " + n.getSource());
102
		}
103
	}
104
 
105
}