User Tools

Site Tools


Plate2D.java


Plate2D.java
  import com.easa.ws.client.stub.Easa;
  import com.easa.ws.client.stub.EasaService;
  import javax.xml.ws.BindingProvider;
 
  /*
  * An example of a java web service client for the EASA web service. This accesses 
  * and runs the  cantilever plate example easap.
  *
  */
  public class Plate2D {
    public static void main(String[] args) {
 
      /* Set the URL where the web service is running */
 
      /* The method below requires "service.wsdl" to be downloaded from the server: 
       * http://easaserver1:80/easa-ws/service
       *
       * and saved into directory:
       *
       * com\easa\ws\client\stub
       *
       * in the easa-common.jar archive.
       * (if the server changes the new WSDL file must be downloaded and saved again)
       */ 
      EasaService.setUrl("service.wsdl");
 
     /*
      * Retrieve a proxy to the web service. The proxy can then be used to call all
      * the public methods supported by the web service.
      */
      Easa easap = new EasaService().getEasaPort();
 
     /*
      * Set client to maintain session. This enables the client to use the same session
      * to interact with the web service instead of
      *  creating a new session every time a method is invoked
      */
      ((BindingProvider)easap).getRequestContext().put(
        BindingProvider.SESSION_MAINTAIN_PROPERTY,true
        );
 
     /*
      * Set authentication parameters if necessary.
      * If the EASA web service is set to require authentication,
      * then set the following parameters:
      */
      ((BindingProvider)easap).getRequestContext().put(
        BindingProvider.USERNAME_PROPERTY, "easaws"
        );
      ((BindingProvider)easap).getRequestContext().put(
        BindingProvider.PASSWORD_PROPERTY, "easaws"
        );
 
      try{
 
        /* Find the published folder path.*/
 
        String appId = easap.getPublishedAppId("examples/tutorial_cant_plate");
       /*
        * Start the web service session by specifying a relative path for an EASAP.
        *  When a session is started, a user license is also checked out.
        */
 
        System.out.println("Start EASAP: " + appId);
        easap.startSession(appId);
 
        System.out.println("EASAP started...");
 
       /*
        * Get current run status.
        * Run status can be one of several statuses such as
        * No Run, Adding to Queue, Run Completed, Not Completed etc.
        */
        System.out.println("\nCheck EASAP status = "+easap.getRunStatus());
 
       /*
        * Invoke getValue method. 
        * The getValue method of the web service end point returns
        * the value of the dor variable whose name is supplied as parameter.
        */
        System.out.println("\nCheck input values:");
        System.out.println("Length = "+easap.getValue("L"));
        System.out.println("Thickness = "+easap.getValue("t"));
        System.out.println("\nSetting Length to 5.2, ft");
 
       /*
        * invoke setValue method. The setValue method of the web service end point sets
        *  the value of the dor variable to the value supplied as parameter.
        */
        easap.setValue("L","5.2, ft");
 
       /*
        * We again use the getValue method to read our new Width
        */
        System.out.println("Length = "+easap.getValue("L"));
 
       /*
        * Invoke getProperty method.
        * This method of the web service end point reads the value of the property
        * (supplied as parameter) of a DOR variable (also supplied as parameter).
        */
        System.out.println("\nCheck material choices and selected material:");
        System.out.println("Material choices = "+easap.getProperty("mat","Choices"));
        System.out.println("Selected material = "+easap.getProperty("mat", "Default"));
 
       /*
        * Invoke actions.
        * The runActions method of the web service end point invokes actions
        * when a button is pressed. The name of the button is supplied as parameter.
        * For example, in our case, invoking the following code
        * has the same effect as pressing the "button_Submit" button.
        * The code is commented out since there are no buttons in the plate example.
        */
        //easap.runActions("button_submit");
 
       /*We submit the easap*/
        easap.submit();
 
       /*
        * We can now repeatedly poll the web service to follow the sequence of states
        * an EASAP goes through after it has been submitted.
        */
        System.out.println("\nChecking Run Status:");
        for (int i = 0; i <5; i++) {
          System.out.println("Run Status : "+ easap.getRunStatus());
          Thread.sleep(1000);
        }
      }
      catch (Exception e) {
       /*Print exceptions if appear*/
        e.printStackTrace();
      }
      finally{
       /*
        * End session. This method ends the EASAP session and releasing
        * or freeing the user license that was being used.
        */
        System.out.println("\nEnding session...");
        easap.endSession();
        System.out.println("Session ended");
      }
    }
  }