Rev 8395 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com;import com.fedex.track.stub.*;/*** Demo of using the Track service with Axis* to track a shipment.* <p>* com.fedex.track.stub is generated via WSDL2Java, like this:<br>* <pre>* java org.apache.axis.wsdl.WSDL2Java -w -p com.fedex.track.stub http://www.fedex.com/...../TrackService?wsdl* </pre>** This sample code has been tested with JDK 5 and Apache Axis 1.4*/public class TrackWebServiceClient {public static void main(String[] args){ClientDetail clientDetail = new ClientDetail();String accountNumber ="377498933";String meterNumber ="105452205";clientDetail.setAccountNumber(accountNumber);clientDetail.setMeterNumber(meterNumber);WebAuthenticationCredential wac = new WebAuthenticationCredential();String key="ggqFObyBaF3ECQbQ";String password="LIf9WMXsKqJV30AsGbK2Fy4TQ";wac.setKey(key);wac.setPassword(password);String endPoint="https://ws.fedex.com:443/web-services/track";TrackReply trck= getTrackingUpdates("796869788166", clientDetail, new WebAuthenticationDetail(wac), endPoint);}public static TrackReply getTrackingUpdates(String trackingNumber, ClientDetail clientDetail, WebAuthenticationDetail wac, String endpointAddress){TrackRequest request = new TrackRequest();request.setClientDetail(clientDetail);request.setWebAuthenticationDetail(wac);TransactionDetail transactionDetail = new TransactionDetail();transactionDetail.setCustomerTransactionId("Tracking Request");request.setTransactionDetail(transactionDetail);VersionId versionId = new VersionId("trck", 6, 0, 0);request.setVersion(versionId);TrackPackageIdentifier packageIdentifier = new TrackPackageIdentifier();packageIdentifier.setValue(trackingNumber); // tracking numberpackageIdentifier.setType(TrackIdentifierType.TRACKING_NUMBER_OR_DOORTAG); // Track identifier types are TRACKING_NUMBER_OR_DOORTAG, TRACKING_CONTROL_NUMBER, ....request.setPackageIdentifier(packageIdentifier);request.setIncludeDetailedScans(new Boolean(true));TrackReply reply= new TrackReply();try{// Initializing the serviceTrackServiceLocator service;TrackPortType port;service = new TrackServiceLocator();updateEndPoint(service,endpointAddress);port = service.getTrackServicePort();System.out.println("In Tracking Method of Fedex");reply = port.track(request); // This is the call to the web service passing in a request object and returning a reply objectprintNotifications(reply.getNotifications());if (isResponseOk(reply.getHighestSeverity())) // check if the call was successful{return reply;}}catch (Exception e) {e.printStackTrace();}return null;}private static boolean isResponseOk(NotificationSeverityType notificationSeverityType) {if (notificationSeverityType == null) {return false;}if (notificationSeverityType.equals(NotificationSeverityType.WARNING) ||notificationSeverityType.equals(NotificationSeverityType.NOTE) ||notificationSeverityType.equals(NotificationSeverityType.SUCCESS)) {return true;}return false;}private static void updateEndPoint(TrackServiceLocator serviceLocator, String endPoint) {if (endPoint != null) {serviceLocator.setTrackServicePortEndpointAddress(endPoint);}}private static void printNotifications(Notification[] notifications) {System.out.println("Notifications:");if (notifications == null || notifications.length == 0) {System.out.println(" No notifications returned");}for (int i=0; i < notifications.length; i++){Notification n = notifications[i];System.out.print(" Notification no. " + i + ": ");if (n == null) {System.out.println("null");continue;} else {System.out.println("");}NotificationSeverityType nst = n.getSeverity();System.out.println(" Severity: " + (nst == null ? "null" : nst.getValue()));System.out.println(" Code: " + n.getCode());System.out.println(" Message: " + n.getMessage());System.out.println(" Source: " + n.getSource());}}}