CAA Web Services Home

 

Consuming the ENOVWSLCMgmtCpp CAA Web Service

Using the ENOVWSLCMgmtCpp CAA Web service for lifecycle management
Use Case

Abstract

This article discusses CAAENOVWSLCMgmtCppAxis1_3Client use case. It describes how to use the Java client binding that is generated using the Axis WSDL2Java emitter in order to consume ENOVWSLCMgmtCpp CAA Web Service. It provides a sample usage scenario that demonstrates how to retrieve Affected Objects from ENOVIA LCA V5.


What You Will Learn With This Use Case

This use case is intended to demonstrate how to write a client application that consumes the ENOVWSLCMgmtCpp CAA Web service. It uses the getTransitions and applyTransition methods within this service as an example. More specifically, you will learn how to:

This article also provides guidance on how to build and run the sample client application using IRAD (IBM Rational Application Developer) 6.0, although any other Java IDE (Integrated Development Environment) or stand-alone JDK/JRE (Java Development Kit/Java Runtime Environment) could be used for that purpose.

[Top]

The CAAENOVWSLCMgmtCppAxis1_3Client Use Case

CAAENOVWSLCMgmtCppClient is a use case in the CAAENOVWS.edu framework. It illustrates capabilities of the ENOVWSLCMgmtCpp CAA Web service.

[Top]

What Does CAAENOVWSLCMgmtCppClient use case do

The sample usage scenario delivered with this use case contains the following steps:

The ENOVWSProdStructCpp CAA Web services (CreatePartRef and DeletePartRef ) are used in support of the primary objective of this use case, which is to get and apply transitions using the ENOVWSLCMgmtCpp CAA Web service.

[Top]

Where To Find the CAAENOVWSLCMgmtCppAxis1_3Client Code

The CAAENOVWSLCMgmtCppAxis1_3Client use case is made of several classes located in the CAAENOVWSAxis1_3Client.mj module of the CAAENOVWS.edu framework:

Windows: <Install>\CAAENOVWS.edu\CAAENOVWSAxis1_3Client.mj\src
Unix: <Install>/CAAENOVWS.edu/CAAENOVWSAxis1_3Client.mj/src

The sample Java resources generated using the Axis WSDL2Java emitter are delivered at the following location (Windows):

<Source>\<Output-package>\CATServiceExceptionType.java
<Source>\<Output-package>\ENOVWSLCMgmtCpp.java
<Source>\<Output-package>\ENOVWSLCMgmtCppLocator.java
<Source>\<Output-package>\ILCMgmtWS.java
<Source>\<Output-package>\ILCMgmtWSBindingStub.java
<Source>\<Output-package>\Identifier.java
<Source>\<Output-package>\Status.java
<Source>\<Output-package>\holders\StringArrayTypeHolder.java

The CAAENOVWSAxis1_3Client.mj module contains the other following resources:

<Source>\<Root-package>\CAAENOVWSClient.java
<Source>\<Root-package>\CAAENOVWSLCMgmtCppUseCase.java
<Source>\<Root-package>\CAAENOVWSLCMgmtCppWrapper.java

The CAAENOVWSLCMgmtCppWrapper class describes how to configure the generated proxy and how to invoke its methods. The CAAENOVWSLCMgmtCppUseCase class demonstrates a sample use case scenario of the ENOVWSLCMgmtCpp CAA Web service. The CAAENOVWSClient class contains the main program. It parses the command line inputs and starts up the use case.

This use case has a dependency on the CustomSessionHandler class which is available in the CAAJAXRPCHTTPSessionHandler.mj module of the CAAWebServices.edu framework. Please refer to [1] for details on HTTP session management and where to find the related class.

This use case has also a dependency on the CAAENOPosAppBinderImplAxis1_3Client use case in order to manage a session with ENOVIA LCA V5. Please refer to [2] for details on where to find the related code.

[Top]

How to Launch CAAENOVWSLCMgmtCppCommandLineClient

To launch the CAAENOVWSLcMgmtCppAxis1_3Client use case, you will need to set up a buildtime environment, build the code along with its prerequisites, set up a runtime configuration and then execute the use case. You can see [3] for details on how to perform these steps within the IRAD 6 environment.

There is no prerequisites to running this use case.

The sample usage scenario delivered within this use case is launched from the CAAENOVWSClient class. It defines a main method that takes several options as parameters, as described below:

 

--w <URI> -e <ENOVIA username> -u <Basic Authentication username> -p <Basic Authentication password> -t ENOVWSLCMgmtCpp

Here follows a sample command, to be updated with your own environment configuration:

-w http://stophe1dsy.dsy.ds:9080/B17 -e cjk -u wpsadmin -p wpsadmin -t ENOVWSLCMgmtCpp

 

[Top]

Step-by-step

The following section first explains how to generate the Java client binding for the ENOVWSLCMgmtCpp CAA Web service demonstrated. The remaining sections then describe the code that must be written in order to consume this Web service:

  1. Creating the Java Client Binding
  2. Instantiating the Generated Proxy
  3. Applying a transition
  4. Get an array of transition names
  5. Sample Usage Scenario

[Top]

Creating the Java Client Binding

Please refer to [4] for details on how to generate the Java client binding using the Axis WSDL2Java emitter.

Here follows a sample command in order to generate the Java client binding for the ENOVWSLCMgmtCpp CAA Web service:

%JDK_HOME%\bin\java org.apache.axis.wsdl.WSDL2Java -o C:\CAAENOVWS\src -p com.dassault_systemes.caaenovws/caaenovwsaxis1_3client.generated  http://karindsy.dsy.ds:9080/V5R16/wsdl?service=urn:com:dassault_systemes:ENOVWSLCMgmtImpl:ENOVWSLCMgmtImpl:ENOVWSLCMgmtCpp

The server name, port, and context root URI information must be updated to match the server where the CAA Web service has been deployed. The list of generated resources is available from the above section: "Where To Find the CAAENOVWSLCMgmtCppClient Code".

[Top]

Instantiating the Generated Proxy

In order to be able to consume the ENOVWSLCMgmtCpp CAA Web service implementation that has been deployed on a target server, you need to retrieve an instance of the ILCMgmtWSBindingStub generated class (also often referred to as the proxy). It's a common best practice to manipulate an instance through its dedicated interface whenever available. The WSDL2Java emitter produces an interface that is implemented by the ILCMgmtWSBindingStub class: ILCMgmtWS. It describes the methods available on the remote CAA Web service.

Warning  Although the ILCMgmtWSBindingStub class can be directly instantiated using its own set of constructors, the Axis User's Guide recommends to discard this approach. Instead, the recommended approach is to use another generated class for that purpose: ENOVWSLCMgmtImplLocator. It implements the ENOVWSLCMgmtCpp interface.

The following code describes how to instantiate the generated proxy. Such proxy is used in order to marshall method calls and objects to SOAP requests, and to unmarshall SOAP responses to objects. This proxy must be configured in order to manage authentication on the remote Web server, timeout, and session management. Maintaining the HTTP session state is mandatory when consuming ENOVIA LCA V5 CAA Web services.

public class CAAENOVWSLCMgmtCppWrapper {
    private String SERVICE_ID = "urn:com:dassault_systemes:ENOVWSLCMgmtImpl:ENOVWSLCMgmtImpl:ENOVWSLCMgmtCpp";
    private ILCMgmtWS proxy = null;
    /**
     * Creates a new proxy for the ENOVWSLCMgmtCpp CAA Web service
     * implementation and configures it.
     * 
     * @param clientId the client identifier used to maintain the session state
     * accross distinct proxies
     * @param uri the root URI of the Web application hosting the implementation
     * of the ENOVWSLCMgmtCpp CAA Web service
     * @param timeOut the proxy timeout
     */
    public CAAENOVWSLCMgmtCppWrapper(String clientId, String uri, int timeOut) {
        // Compute the SOAP endpoint URI value that bounds to the deployed
        // implementation of the ENOVWSLCMgmtCpp CAA Web service
        String endpoint = uri + "servicerouter?service=" + SERVICE_ID;
        // Retrieve proxy instance
        ENOVWSLCMgmtCppLocator locator = new ENOVWSLCMgmtCppLocator();
        try {
            proxy = locator.getENOVWSLCMgmtCppPort(new URL(endpoint));
        } catch (MalformedURLException e) {
            e.printStackTrace();
            throw new RuntimeException(
                    "Invalid SOAP endpoint URI specified for the ENOVWSLCMgmtCpp CAA Web service proxy");
        } catch (ServiceException e) {
            e.printStackTrace();
            throw new RuntimeException(
                    "Unable to instantiate the ENOVWSLCMgmtCpp CAA Web service proxy");
        }
        // Required for HTTP session state management on the current proxy
        ((ILCMgmtWSBindingStub) proxy).setMaintainSession(true);
        if (clientId != null) {
            // Used to maintain the HTTP session state accross distinct proxies
            HandlerInfo info = new HandlerInfo();
            info.setHandlerClass(CustomSessionHandler.class);
            Map handlerConfig = new HashMap();
            handlerConfig.put(CustomSessionHandler.CLIENT_ID, clientId);
            info.setHandlerConfig(handlerConfig);
            HandlerRegistry registry = locator.getHandlerRegistry();
            String portName = locator.getENOVWSLCMgmtCppPortWSDDServiceName();
            QName name = new QName(portName);
            List chain = registry.getHandlerChain(name);
            chain.add(info);
        }
        // Increase the default client time-out
        ((ILCMgmtWSBindingStub) proxy).setTimeout(timeOut);
    }
 }
 

(1): in order to maintain the HTTP session state between successive calls performed using the same proxy instance, the setMaintainSession method must be used. This is mandatory in the context of ENOVIA LCA V5 CAA Web services,
(2): the default timeout is set to 60 seconds. This value can be increased in order to avoid potential issues at runtime, such as losing the HTTP connection before receiving the SOAP response. For security, the timeout is set to 360 seconds (the value specified in the code is in milliseconds),
(3): when security is enabled, it is mandatory to set the username and password attributes on the generated proxy. The values specified must match a valid set of credentials for the Basic Authentication mechanism.

[Top]

Applying a transition

To apply a lifecycle transition in ENOVIA LCA V5 use the following method, which is available through the generated ILCMgmtWS proxy interface: 

Status applyTransition (
iObjectId,
iTransitionName) throws RemoteException, CATServiceExceptionType;

This method accepts the following parameters:

[in] iObjectId  The identifier of the target object
[in] iTransitionName  The name of the transition to apply

The following code demonstrates the use of the getAffectedObjects method:

public class CAAENOVWSLCMgmtCppWrapper {
...
    public void applyTransition(String objectUUID, String transitionName)
            throws Exception {
        System.out.println(">>> Invoking 'applyTransition' on ENOVWSLCMgmtCpp CAA Web service proxy");
        if (objectUUID == null) {
            throw new IllegalArgumentException("Object UUID is null");
        } else if (transitionName == null) {
            throw new IllegalArgumentException("Transition name is null");
        }
        System.out.println("Object UUID: " + objectUUID);
        System.out.println("Transition name: " + transitionName);
        // Create input data
        Identifier objectId = CAAENOVWSUtils.toIdentifier(objectUUID);
        // Invoke method on remote CAA Web service
        try {
            Status status = proxy.applyTransition(objectId, transitionName);
            System.out.println("Status: " + status.getStatus());
        } catch (CATServiceExceptionType e) {
            throw e;
        } catch (Throwable t) {
            throw new Exception("Failed to apply transition", t);
        }
    }
}
 

Get an array of transition names

To get an array of lifecycle transition names in ENOVIA LCA V5 use the following method, which is available through the generated ILCMgmtWS proxy interface: 

Status getTransitions(
Identifier iObjectId,
StringArrayTypeHolder oTransitionNames) throws RemoteException, com.dassault_systemes.caaenovws.caaenovwsaxis1_1clientgen.generated.CATServiceExceptionType;

This method accepts the following parameters:

[in] iObjectId  The identifier of the target object
[out] oTransitionNames  The string array of transition names which are available to apply

The following code demonstrates the use of the getTransitions method:

public class CAAENOVWSLCMgmtCppWrapper {
 ....
    public String[] getTransitions(String objectUUID) throws Exception {
        System.out.println(">>> Invoking 'getTransitions' on ENOVWSLCMgmtCpp CAA Web service proxy");
        if (objectUUID == null) {
            throw new IllegalArgumentException("Object UUID is null");
        }
        System.out.println("Object UUID: " + objectUUID);
        // Create input data
        Identifier objectId = CAAENOVWSUtils.toIdentifier(objectUUID);
        StringArrayTypeHolder transitionNames = new StringArrayTypeHolder();
        // Invoke method on remote CAA Web service
        try {
            Status status = proxy.getTransitions(objectId, transitionNames);
            System.out.println("Status: " + status.getStatus());
        } catch (CATServiceExceptionType e) {
            throw e;
        } catch (Throwable t) {
            throw new Exception("Failed to get transition(s)", t);
        }
        if (transitionNames == null || transitionNames.value == null) {
            throw new Exception("Failed to get transitions");
        }
        return transitionNames.value;
    }
}
 

 

[Top]

Sample Usage Scenario

The sample usage scenario consumes the following CAA web services:

The following code demonstrates a sample usage scenario for the ENOVWSLCMgmtCpp CAA Web service:

public class CAAENOVWSLCMgmtCppUseCase {
    private String uri = null;
    private String credUser = null;
    private String credPwd = null;
    public CAAENOVWSLCMgmtCppUseCase(String uri, String credUser, String credPwd) {
        this.uri = uri;
        this.credUser = credUser;
        this.credPwd = credPwd;
    }
    public void runSampleUsageScenario(String enoviaUser) {
        boolean success = false;
        Exception exception = null;
        CAAENOPosApplicationBinderImplWrapper binderWrapper = null;
        SessionToken sessionToken = null;
        try {
            // ------------------------------------------------------------
            // Step 1 - Instantiate and configure the proxy
            // ------------------------------------------------------------
            System.out.println("STEP 1: Instantiating and configuring CAA Web service proxy");
            String clientId = new Long(System.currentTimeMillis()).toString();
            int timeOut = 360000;
            // Instantiate the wrapper client classes
            binderWrapper = new CAAENOPosApplicationBinderImplWrapper(clientId,
                    uri, credUser, credPwd, timeOut);
            CAAENOVWSProdStructCppWrapper prodStructWrapper = new CAAENOVWSProdStructCppWrapper(
                    clientId, uri, timeOut);
            CAAENOVWSLCMgmtCppWrapper lcMgmtWrapper = new CAAENOVWSLCMgmtCppWrapper(
                    clientId, uri, timeOut);
            // ------------------------------------------------------------
            // Step 2 - Open session with ENOVIA LCA V5
            // ------------------------------------------------------------
            System.out.println("--------------------------------------------------------------------------------");
            System.out.println("STEP 2: Opening session with ENOVIA LCA V5");
            System.out.println("--------------------------------------------------------------------------------");
            String[] userContexts = binderWrapper.getUserContexts(enoviaUser);
            System.out.println("Found " + userContexts.length + " context(s) in database");
            System.out.println("Displaying list of available contexts:");
            for (int i = 0; i < userContexts.length; i++) {
                System.out.println("Context[" + i + "]: " + userContexts[i]);
            }
            System.out.println("\n--------------------------------------------------------------------------------");
            System.out.println("STEP 3: Logging on to ENOVIA LCA V5");
            System.out.println("--------------------------------------------------------------------------------");
            if (userContexts.length == 0) {
                throw new Exception("No context found for the user specified");
            }
            sessionToken = binderWrapper.login(userContexts[0]);
            // ------------------------------------------------------------
            // Step 3 - Create a part reference to test with
            // ------------------------------------------------------------
            System.out.println("--------------------------------------------------------------------------------");
            System.out.println("STEP 3: Creating part reference");
            System.out.println("--------------------------------------------------------------------------------");
            ENOVIA createPartResultSet = prodStructWrapper.createPartRef(new String[] { "ILCMgmtWS_CAA_PartRef1" },
                                                                         "",
                                                                         "FALSE");
            String[] partRefUUIDs = prodStructWrapper.getENOVIA_VPMPartVersionUUIDs(createPartResultSet);
            if (partRefUUIDs.length > 1) {
                throw new Exception(
                        "Invalid state: more than 1 part reference was returned");
            } else if (partRefUUIDs.length != 1) {
                throw new Exception("Failed to create part reference");
            }
            String partRefUUID = partRefUUIDs[0];
            // ------------------------------------------------------------
            // Step 4 - Get 'Promote' transition
            // ------------------------------------------------------------
            System.out.println("--------------------------------------------------------------------------------");
            System.out.println("STEP 4: Getting transitions");
            System.out.println("--------------------------------------------------------------------------------");
            String[] transitionNames = lcMgmtWrapper.getTransitions(partRefUUID);
            for (int i = 0; i < transitionNames.length; i++) {
                System.out.println("Transition[" + i + "]: " + transitionNames[i]);
            }
            // ------------------------------------------------------------
            // Step 5 - Apply default transition
            // ------------------------------------------------------------
            System.out.println("--------------------------------------------------------------------------------");
            System.out.println("STEP 5: Applying 'Promote' transition");
            System.out.println("--------------------------------------------------------------------------------");
            // As we just created the part, there should only be 1 transition,
            // 'Promote'
            if (transitionNames.length == 0) {
                throw new Exception("Failed to get default transition");
            } else if (transitionNames.length != 1 || !"Promote".equals(transitionNames[0])) {
                throw new Exception(
                        "Use case does not handle customized lifecycle");
            }
            lcMgmtWrapper.applyTransition(partRefUUID, transitionNames[0]);
            // ------------------------------------------------------------
            // Step 6 - Get transitions
            // ------------------------------------------------------------
            System.out.println("--------------------------------------------------------------------------------");
            System.out.println("STEP 6: Getting transitions");
            System.out.println("--------------------------------------------------------------------------------");
            transitionNames = lcMgmtWrapper.getTransitions(partRefUUID);
            for (int i = 0; i < transitionNames.length; i++) {
                System.out.println("Transition[" + i + "]: " + transitionNames[i]);
            }
            // ------------------------------------------------------------
            // Step 7 - Apply 'Demote' transition
            // ------------------------------------------------------------
            System.out.println("--------------------------------------------------------------------------------");
            System.out.println("STEP 7: Applying 'Demote' transition");
            System.out.println("--------------------------------------------------------------------------------");
            // As we promoted the part, there should now only be 2 transitions,
            // 'Promote' & 'Demote'
            if (transitionNames.length == 0) {
                throw new Exception("Failed to get default transition");
            } else if (transitionNames.length != 2 || !"Promote".equals(transitionNames[0]) || !"Demote".equals(transitionNames[1])) {
                throw new Exception(
                        "Use case does not handle customized lifecycle");
            }
            // Apply 'Demote' transition
            lcMgmtWrapper.applyTransition(partRefUUID, transitionNames[1]);
            // ------------------------------------------------------------
            // Step 8 - Get default transition again
            // ------------------------------------------------------------
            System.out.println("--------------------------------------------------------------------------------");
            System.out.println("STEP 8: Getting transitions");
            System.out.println("--------------------------------------------------------------------------------");
            transitionNames = lcMgmtWrapper.getTransitions(partRefUUID);
            // As we demoted the part, we should be back to the same start state
            for (int i = 0; i < transitionNames.length; i++) {
                System.out.println("Transition[" + i + "]: " + transitionNames[i]);
            }
            if (transitionNames.length != 1 || !"Promote".equals(transitionNames[0])) {
                throw new Exception("Failed to return to initial state");
            }
            // ------------------------------------------------------------
            // Step 9 - Cleanup by deleting created part reference
            // ------------------------------------------------------------
            System.out.println("--------------------------------------------------------------------------------");
            System.out.println("STEP 9: Deleting part reference");
            System.out.println("--------------------------------------------------------------------------------");
            prodStructWrapper.deletePartRef(new String[] { partRefUUID });
            success = true;
        } catch (CATServiceExceptionType e) {
            exception = e;
        } catch (Exception e) {
            exception = e;
        } finally {
            // ------------------------------------------------------------
            // Step 4 - Terminate opened session
            // ------------------------------------------------------------
            System.out.println("--------------------------------------------------------------------------------");
            System.out.println("STEP 5: Terminating opened session with ENOVIA LCA V5");
            System.out.println("--------------------------------------------------------------------------------");
            // The session must be closed even if a call to a method on the
            // ENOVWSLCMgmtCpp CAA Web service fails
            try {
                binderWrapper.logout(sessionToken);
            } catch (Exception e) {
                System.err.println("Failed to logout gracefully");
            }
        }
        if (success) {
            System.out.println("================================================================================");
            System.out.println("Use case execution successful");
        } else {
            System.out.println("================================================================================");
            System.out.println("Use case execution failed");
            System.out.println("--------------------------------------------------------------------------------");
            if (exception instanceof CATServiceExceptionType) {
                CATServiceExceptionType e = (CATServiceExceptionType) exception;
                System.out.println("Error code: " + e.getCode());
                System.out.println("Error message: " + e.getMessage());
                if (e.getErrorArguments() != null) {
                    String[] errorArguments = e.getErrorArguments();
                    System.out.println("Error arguments: " + errorArguments.length);
                    for (int i = 0; i < errorArguments.length; i++) {
                        System.out.println("\tArgument[" + i + "]: " + errorArguments[i]);
                    }
                }
            } else {
                System.out.println(exception.getMessage());
                if (exception.getCause() != null) {
                    // Handle nested exceptions launched from the use case
                    System.out.println("Exception details:");
                    exception.getCause().printStackTrace();
                } else if (exception.getStackTrace() != null && exception.getStackTrace().length != 0) {
                    // Handle unexpected exceptions
                    System.out.println("Exception details:");
                    exception.printStackTrace();
                }
            }
        }
    }
}
 

The CAAENOVWSUtils.displayResults method can be found at:

<Install>\<Source>\<Package>\CAAENOVWSUtils.java

[Top]


In Short

This use case explains how to use the Java client binding generated using the Axis WSDL2Java emitter in order to consume the ENOVWSLCMgmtCpp CAA Web service. It also gives an overview of the methods used in this use case:

[Top]


References

[1] Maintaining the Session State
[2] Consuming the ENOPosApplicationBinderImpl CAA Web Service
[3] Building and Launching a CAA Web Service Use Case
[4] Generating a Java Client Binding
[5] Consuming the ENOVWSProdStructCpp CAA Web Service
[Top]

History

Version: 1 [July 2005] Document created
Version: 2 [Feb 2006] Document updated
[Top]

Copyright © 1994-2006,  Dassault Systèmes. All rights reserved.