Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Executing and Testing the Sample

...

The employee.rxt shown above has been used to create the Employee[singular label of the configuration model]configurabele extension on the Governance Registry. Refer to /wiki/spaces/~yohanna@wso2.com/pages/21233734 Deploying an Extension File to deploy an extension file to the governance registry.

...

Activity 1: View the wsdl representation for the service exposed by the Employee artifact. The wsdl uri is similar to https://{IP address}:9443/services/{singular label of the artifact}?wsdl.

Activity 2: Any  Any wsdl2java tool can be used to generate the stub. In this sample, we use the WSO2 Application Server which has the wsdl2java facility.1.

  1. As the prerequisites state, download and unpack the WSO2 Application Server binary distribution

...

  1. from http://wso2.com/products/application-server

...

  1.  if you haven't done already.

...

  1. Change the value of the <HideAdminServiceWSDLs> element in the <AS_HOME>/repository/conf/carbon.xml file to false.
  2. Navigate to <AS_HOME>/bin directory execute wso2server.sh (for Linux) or wso2server.bat (for Windows) to start the Application Server.

...

  1. Log-in to the AS management console and click the "tools" menu. Management console log-in is similar to that of Governance Registry.

...

  1.  
  2. Select wsdl2java from the tools pane which is in the left hand side of the management console.

...

  1. Provide the uri of the wsdl or file path of the wsdl. If the uri does not work, copy the wsdl from the browser to a text document and save it as .wsdl file and give the file path.

Activity 3: Result contains the stub java file and other skeletons with build.xml and pom.xml.

...

Code Block
languagejava
package org.apache.ws.axis2;
import java.rmi.RemoteException;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.ws.axis2.EmployeeStub.AddEmployee;
import org.apache.ws.axis2.EmployeeStub.AddEmployeeResponse;
import org.apache.ws.axis2.EmployeeStub.DeleteEmployee;
import org.apache.ws.axis2.EmployeeStub.DeleteEmployeeResponse;
import org.apache.ws.axis2.EmployeeStub.GetEmployee;
import org.apache.ws.axis2.EmployeeStub.GetEmployeeArtifactIDs;
import org.apache.ws.axis2.EmployeeStub.GetEmployeeArtifactIDsResponse;
import org.apache.ws.axis2.EmployeeStub.GetEmployeeDependencies;
import org.apache.ws.axis2.EmployeeStub.GetEmployeeDependenciesResponse;
import org.apache.ws.axis2.EmployeeStub.GetEmployeeResponse;
import org.wso2.carbon.utils.CarbonUtils;

public class Employee {
    /**
     * @param args
     * @throws AddEmployeeServiceGovernanceException
     * @throws RemoteException
     * @throws GetEmployeeArtifactIDsServiceGovernanceException
     * @throws GetEmployeeServiceGovernanceException
     * @throws UpdateEmployeeServiceGovernanceException
     * @throws DeleteEmployeeServiceGovernanceException
     *
     */

    EmployeeStub stub;
    public static void main(String[] args) throws RemoteException,
            AddEmployeeServiceGovernanceException,
            GetEmployeeArtifactIDsServiceGovernanceException,
            GetEmployeeServiceGovernanceException,
            UpdateEmployeeServiceGovernanceException,
            DeleteEmployeeServiceGovernanceException,
            GetEmployeeDependenciesServiceGovernanceException{
        // TODO Autogenerated method stub
        try{
            String GREG_HOME ="/home/user/GREG/final_test/wso2greg-5.0.01-SNAPSHOT/";
            System.setProperty("javax.net.ssl.trustStore","/home/rajith/GREG/final_test/wso2greg-5.0.01-SNAPSHOT/repository/resources/security/client-truststore.jks");
            System.setProperty("javax.net.ssl.trustStorePassword","wso2carbon");
            System.setProperty("javax.net.ssl.trustStoreType","JKS");
            String axis2Repo =GREG_HOME + "repository/deployment/client";
            String axis2Conf =GREG_HOME +"repository/conf/axis2/axis2_client.xml";
            ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(axis2Repo, axis2Conf);
            String backendServerURL = "https://localhost:9443/services/";
            String epr =backendServerURL+"Employee";
            Employee employee = new Employee(configContext,epr,false);

            /**@metadata defines the employee data to be added. The xml representation of the content should be passed which can be retrieved from the standard view of the content panel of an the employee artifact.*/
            String metadata = "<metadata xmlns=\"http://www.wso2.org/governance/metadata\">"+"<overview><sex>female</sex><name>Leonii</name>"+"<address>spain</address></overview></metadata>";
            employee.addEmployee(metadata);
            String[] artifactIDs = employee.getEmployeeArtifactIDs();
            String id = artifactIDs[0];
            for(int i=0; i<artifactIDs.length; i++){
                employee.getEmployee(artifactIDs[i]);
                employee.getEmployeeDependencies(artifactIDs[i]);
            }
            employee.deleteEmployee(id);
        } catch (AxisFault e) {
            // TODO Autogenerated catch block
            e.printStackTrace();
        }
    }

    public Employee(ConfigurationContext configContext,String epr, boolean listener) throws AxisFault{
        stub = new EmployeeStub(configContext,epr,listener);
        CarbonUtils.setBasicAccessSecurityHeaders("admin", "admin", stub._getServiceClient());
    }

    /**this method add the employee details to the running GReg instance by invoking the addEmployee() method of the EmployeeStub*/

    public String addEmployee(String addEmployeeXmlString) throws RemoteException, AddEmployeeServiceGovernanceException{
        AddEmployee addEmp = new AddEmployee();
        addEmp.setInfo(addEmployeeXmlString);
        AddEmployeeResponse response = stub.addEmployee(addEmp);

        //prints the artifact id of the added employee artifact
        System.out.println(response.get_return());

        return response.get_return();
    }

    /**Get all the artifact ids of the Employees, method returns the array of artifacts */

    public String[] getEmployeeArtifactIDs() throws RemoteException, GetEmployeeArtifactIDsServiceGovernanceException{
        GetEmployeeArtifactIDs artifactIDs = new GetEmployeeArtifactIDs();
        GetEmployeeArtifactIDsResponse getEmployeeArtifactIDsResponse = stub.getEmployeeArtifactIDs(artifactIDs);
        String[] employeeArifactIDs = getEmployeeArtifactIDsResponse.get_return();
        return employeeArifactIDs;
    }

    /**Method takes artifactID as an input and returns the corresponding employee instance */
    public String getEmployee(String artifactID) throws RemoteException, GetEmployeeServiceGovernanceException{
        GetEmployee getEmployee = new GetEmployee();
        getEmployee.setArtifactId(artifactID);
        GetEmployeeResponse getEmployeeResponse = stub.getEmployee(getEmployee);
        System.out.println(artifactID+":"+getEmployeeResponse.get_return());
        return getEmployeeResponse.get_return();
    }

    /**Method takes artifactID of the employee instance to be deleted and returns the boolean value */
    public boolean deleteEmployee(String artifactID) throws RemoteException, DeleteEmployeeServiceGovernanceException{
        DeleteEmployee deleteEmployee = new DeleteEmployee();
        deleteEmployee.setArtifactId(artifactID);
        DeleteEmployeeResponse deleteEmployeeResponse = stub.deleteEmployee(deleteEmployee);
        boolean deleted = deleteEmployeeResponse.get_return();
        if(deleted){
            System.out.println(artifactID+":The specified artifact has been deleted");
        }
        return deleted;
    }

    /**Get all the dependencies for a given artifactID, method returns the array of dependencies */

    public String[] getEmployeeDependencies(String artifactID) throws RemoteException, GetEmployeeDependenciesServiceGovernanceException{
        GetEmployeeDependencies employeeDependencies = new GetEmployeeDependencies();
        employeeDependencies.setArtifactId(artifactID);
        GetEmployeeDependenciesResponse employeeDependenciesResponse = stub.getEmployeeDependencies(employeeDependencies);
        return employeeDependenciesResponse.get_return();
    }
}

...