SOAP API Example

Java source codes are compiled into Java Class files that can be loaded to execute the methods needed to perform the different functions and capabilities of the EnterWorks application, particularly the Web Services component. Presented below is the sample code or script that executes some EnterWorks methods described in Appendix: Web Service SOAP APIs.

The sample below shows how to perform sync in, sync out, and a validation method call using the EnterWorks API:

package com.enterworks.Enable.test.webservice; 
import java.util.ArrayList;
import com.enterworks.Enable.test.webservice.KeyValuePair;
import com.enterworks.Enable.test.webservice.Repository;
 
/* Demonstrate sync in, sync out and validation method calls using EnterWorks Web services API 
 */
public class PimWSClientSample {
 private static String hostURL =
  "http://sulley:8888/webcm/services/server";
 
 private static String usage = "Usage: java PimWSClient syncout|validatation <repository name>";
 
 public static void main(String[] args) {
  com.enterworks.Enable.test.webservice.ServerSoapBindingStub binding = null;
if (args.length < 2) {
   System.err.println(usage);
return;
  }
if (args[0].equalsIgnoreCase("syncout")) {
   System.out.println("Sync out repository:" + args[1]);
  } else if (args[0].equalsIgnoreCase("validation")) {
   System.out.println("Validation repository:" + args[1]);
  } else {
   System.err.println(usage);
return;
  }
try {
   // login first 
 
   com.enterworks.Enable.test.webservice.ServerServiceLocator loc = new
    com.enterworks.Enable.test.webservice.ServerServiceLocator();
   binding = (com.enterworks.Enable.test.webservice.ServerSoapBindingStub) 
    loc.getserver(new java.net.URL(hostURL));
   com.enterworks.Enable.test.webservice.Session mySession = login(binding);
 
   // validate result 
 
   System.err.println("login session:" +
    mySession.getSessionId());
   System.err.println("login user:" + mySession.getUserId()); 
 
   // retrieve repository list 
 
   Repository[] repList = null;
   Repository rep = null;
   repList = binding.getRepositoryList(mySession);
 
if (repList == null) {
    System.out.println("No repository to retrieve.");
return;
   }
for (int i = 0; i < repList.length; i++) {
if (args[1].equalsIgnoreCase(repList[i].getName())) {
     System.out.println("Find matching repository:" + args[1]);
     rep = repList[i];
break;
    }
   }
if (rep == null) {
    System.err.println("No matching repository found.");
return;
   }
if (args[0].equalsIgnoreCase("syncout")) {
    binding.syncOutRepository(mySession, rep, false);
   } else if (args[0].equalsIgnoreCase("validation")) {
    binding.validateRepository(mySession, rep);
   } else {
    System.err.println(usage);
return;
   }
 
   //logout 
 
   binding.logout(mySession);
   } catch (javax.xml.rpc.ServiceException jre) {
if (jre.getLinkedCause() != null) jre.getLinkedCause().printStackTrace();
throw new junit.framework.AssertionFailedError("JAX-RPC 
    ServiceException caught: " + jre); 
   } catch (Exception e) {
    System.err.println(e.getMessage());
   }
  }
  /* 
   * common login wrapper routine. 
   */
public static com.enterworks.Enable.test.webservice.Session login(com.enterworks.Enable.test.webservice.ServerSoapBindingStub binding) {
try {
    com.enterworks.Enable.test.webservice.Session value = null;
    value = binding.login("system", "system", true, null);
return value;
   } catch (Exception e) {
    System.out.println("Can't login." + e.getMessage());
   }
return null;
  } 
  /* login */
  /* 
   *   Update the item attribute values. 
   *   Refer to the java doc for API description. 
   */
public static void updateItem() {
   com.enterworks.Enable.test.webservice.ServerSoapBindingStub binding = null;
try { 
    // login first 
 
    com.enterworks.Enable.test.webservice.ServerServiceLocator loc = new
com.enterworks.Enable.test.webservice.ServerServiceLocator();
    binding = (com.enterworks.Enable.test.webservice.ServerSoapBindingStub)
     loc.getserver(new java.net.URL(hostURL));
    com.enterworks.Enable.test.webservice.Session mySession = login(binding);
 
    // validate result 
 
    System.err.println("login session:" +
     mySession.getSessionId());
    System.err.println("login user:" + mySession.getUserId());
    java.lang.String value = null;
 
    // should do repository retrieval instead of doing the following 
    // this code assumes the repository is known. 
 
    Repository rep = new Repository();
    rep.setRepositoryId(1);
    rep.setMasterIndicator(true);
    ArrayList l = new ArrayList();
 
    // again, should retrieve attribute list instead of hard code. 
 
    KeyValuePair kvp1 = new KeyValuePair("F_11", "123");
    KeyValuePair kvp2 = new KeyValuePair("F_22", "abc");
    l.add(kvp1);
    l.add(kvp2);
    binding.updateItem(login(binding), rep, 1, (KeyValuePair[]) l.toArray(new
KeyValuePair[l.size()]));
    System.out.println("done.");
   } catch (Exception e) {
    System.err.println(e.getMessage());
   }
  }
  /* 
   *   Update item data pool response. 
   *   Read the java doc for API description. 
   */
public static void updateItemStatus() {
   com.enterworks.Enable.test.webservice.ServerSoapBindingStub binding =
null;
 
try {
 
    // login first
 
    com.enterworks.Enable.test.webservice.ServerServiceLocator loc = new com.enterworks.Enable.test.webservice.ServerServiceLocator();
    binding = (com.enterworks.Enable.test.webservice.ServerSoapBindingStub) loc.getserver(new java.net.URL(hostURL));
    com.enterworks.Enable.test.webservice.Session mySession = login(binding);
 
    // validate result 
 
    System.err.println("login session:" +
     mySession.getSessionId());
    System.err.println("login user:" + mySession.getUserId());
    java.lang.String value = null;
 
    // assume the message id is "UCCNET_RESPONSE1"          
    // read java doc to see the actual status code meaning. 
 
    binding.setDataPoolResponseStatus(login(binding),
     "UCCNET_RESPONSE1", 0, "Sync from UCCNet Ok.");
   } catch (Exception e) {
    System.err.println(e.getMessage());
   }
  }
public static void updateItemResponse() {
   com.enterworks.Enable.test.webservice.ServerSoapBindingStub binding = null;
 
try {
 
    // login first             
 
    com.enterworks.Enable.test.webservice.ServerServiceLocator loc = new com.enterworks.Enable.test.webservice.ServerServiceLocator();
    binding = (com.enterworks.Enable.test.webservice.ServerSoapBindingStub) loc.getserver(new java.net.URL(hostURL));
    com.enterworks.Enable.test.webservice.Session mySession = login(binding);
 
    // validate result 
 
    System.err.println("login session:" +
     mySession.getSessionId());
    System.err.println("login user:" + mySession.getUserId());
 
    // should retrieve repository list first          
    // this code assume it exists.
    Repository rep = new Repository();          
    rep.setRepositoryId(1010946);          
    rep.setMasterIndicator(true); 
 
    // see java doc for actual status code meaning   
    binding.setItemState(login(binding), rep, 1011019, 2, true, 3, true, 1, false, 0, true); 
   } catch (Exception e) {
    System.err.println(e.getMessage());
   }
  }
 }