Advertisement
robgonsalves

Interplay WS Test - Changing Endpoint

Mar 8th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.08 KB | None | 0 0
  1. // This is a sample program to:
  2. // 1. get the latest version of an AAF file from Interplay
  3. // 2. check in an AAF into Interplay
  4. // 3. print out the contents of a folder in Interplay
  5. package testws;
  6.  
  7. import javax.activation.FileDataSource;
  8. import javax.activation.DataHandler;
  9. import java.io.*;
  10. import java.util.*;
  11. import javax.xml.ws.*;
  12.  
  13. public class TestWS {
  14.  
  15.     public static void main(String[] args) {
  16.         getLatest();
  17.         checkInAAF();
  18.         getChildren();
  19.     }
  20.  
  21.     static String username = "uuu";
  22.     static String password = "ppp";
  23.     static String endpoint = "http://54.152.240.129/services/Assets";
  24.    
  25.     public static void getLatest() {
  26.         // setup the credentials
  27.         UserCredentialsType creds = new UserCredentialsType();
  28.         creds.setUsername(username);
  29.         creds.setPassword(password);
  30.  
  31.         // setup the service
  32.         Assets service = new Assets();
  33.         AssetsPortType port = service.getAssetsPort();
  34.        
  35.         // Change the endpoint
  36.         BindingProvider bp = (BindingProvider)port;
  37.         Map <String,Object> requestConext = bp.getRequestContext();
  38.         requestConext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
  39.  
  40.         // set the Interplay URI
  41.         GetLatestType body = new GetLatestType();
  42.         body.setInterplayURI("interplay://WGC?mobid=060a2b340101010101010f0013-000000-5649977d2af0818d-060e2b347f7f-2a80");
  43.  
  44.         try {
  45.             // make the call
  46.             GetLatestResponseType result;
  47.             result = port.getLatest(body, creds);
  48.  
  49.             // print out the results
  50.             if (result.getErrors() != null && result.getErrors().getError().size() > 0) {
  51.                 for (ErrorType error : result.getErrors().getError()) {
  52.                     System.out.println("Checkin error: " + error.getDetails());
  53.                 }
  54.             } else {
  55.                 // save out the file
  56.                 DataHandler dataHandler = result.getFile();
  57.                 FileOutputStream os = new FileOutputStream("c:\\folder\\theFile.aaf");
  58.                 dataHandler.writeTo(os);
  59.                 os.close();
  60.  
  61.                 System.out.println("GetLatest Success!");
  62.             }
  63.  
  64.         } catch (AssetsFault e) {
  65.             e.printStackTrace();
  66.         } catch (FileNotFoundException e) {
  67.             e.printStackTrace();
  68.         } catch (IOException e) {
  69.             e.printStackTrace();
  70.         }
  71.     }
  72.  
  73.     public static void checkInAAF() {
  74.         // setup the credentials
  75.         UserCredentialsType creds = new UserCredentialsType();
  76.         creds.setUsername(username);
  77.         creds.setPassword(password);
  78.  
  79.         // setup the service
  80.         Assets service = new Assets();
  81.         AssetsPortType port = service.getAssetsPort();
  82.  
  83.         // set the parameters
  84.         CheckInAAFType body = new CheckInAAFType();
  85.         body.setInterplayURI("interplay://WGC/Catalogs/MyClips/CheckCallg/");
  86.  
  87.         // setup the data handler
  88.         FileDataSource fileDataSource = new FileDataSource(new File("c:\\folder\\theFile.aaf"));
  89.         DataHandler dataHandler = new DataHandler(fileDataSource);
  90.         body.setAAF(dataHandler);
  91.  
  92.         try {
  93.             // make the call
  94.             CheckInAAFResponseType result;
  95.             result = port.checkInAAF(body, creds);
  96.  
  97.             // print out the results
  98.             if (result.getErrors() != null && result.getErrors().getError().size() > 0) {
  99.                 for (ErrorType error : result.getErrors().getError()) {
  100.                     System.out.println("Checkin error: " + error.getDetails());
  101.                 }
  102.             } else {
  103.                 System.out.println("Success! Checked in: " + result.getInterplayURI());
  104.             }
  105.  
  106.         } catch (AssetsFault e) {
  107.             e.printStackTrace();
  108.         }
  109.     }
  110.  
  111.     public static void getChildren() {
  112.         // setup the credentials
  113.         UserCredentialsType creds = new UserCredentialsType();
  114.         creds.setUsername(username);
  115.         creds.setPassword(password);
  116.  
  117.         // setup the service
  118.         Assets service = new Assets();
  119.         AssetsPortType port = service.getAssetsPort();
  120.  
  121.         // set the parameters
  122.         GetChildrenType body = new GetChildrenType();
  123.         body.setInterplayURI("interplay://WGC/Catalogs/MyClips/CheckCallg/");
  124.         body.setIncludeFiles(false);
  125.         body.setIncludeFolders(false);
  126.         body.setIncludeMOBs(true);
  127.  
  128.         try {
  129.             // make the call
  130.             GetChildrenResponseType result;
  131.             result = port.getChildren(body, creds);
  132.  
  133.             // print out the results
  134.             for (AssetDescriptionType asset : result.getResults().getAssetDescription()) {
  135.                 System.out.println(asset.getInterplayURI());
  136.                 for (AttributeType att : asset.getAttributes().getAttribute()) {
  137.                     System.out.println(att.getGroup() + "." + att.getName() + " = " + att.getValue());
  138.                 }
  139.                 System.out.println();
  140.             }
  141.         } catch (AssetsFault e) {
  142.             e.printStackTrace();
  143.         }
  144.     }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement