Versions Compared

Key

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

...

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

Info

Note: Add the following dependencies to the pom.xml file if they are missing:

Code Block
languagexml
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.base</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-json</artifactId>
<version>$
{axis2_version}</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>om-aspects</artifactId>
<version>1.2.15</version>
</dependency>

 

1. Convert that project to maven project using the mvn eclipse:eclipse command.

...

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 GetEmployeeServiceGovernanceException   * @throws UpdateEmployeeServiceGovernanceException
     * @throws DeleteEmployeeServiceGovernanceException
     *
     */

    EmployeeStub stub;
    public static void main(String[] args) throws RemoteException,
,
            AddEmployeeServiceGovernanceException,
            GetEmployeeArtifactIDsServiceGovernanceException,
            GetEmployeeServiceGovernanceException,
     AddEmployeeServiceGovernanceException,       GetEmployeeArtifactIDsServiceGovernanceExceptionUpdateEmployeeServiceGovernanceException,
      GetEmployeeServiceGovernanceException,       UpdateEmployeeServiceGovernanceExceptionDeleteEmployeeServiceGovernanceException,
      DeleteEmployeeServiceGovernanceException,       GetEmployeeDependenciesServiceGovernanceException{
        // TODO Autogenerated method stub
        try{
            String GREG_HOME ="/home/rajith/raguGREG/Greg_4.0.0/platform/4final_test/wso2greg-5.0.0/products/greg/4.5.3/modules/distribution/target/wso2greg4.5.3-SNAPSHOT/";
            System.setProperty("javax.net.ssl.trustStore","/home/rajith/raguGREG/Greg_4.0.0/platform/4final_test/wso2greg-5.0.0/products/greg/4.5.3/modules/distribution/target/wso2greg4.5.3-SNAPSHOT/repository/resources/security/clienttruststoreclient-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 ConfigurationContextconfigContextconfigContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(axis2Repo, axis2Conf);
            StringbackendServerURLString 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 = "<metadataxmlns<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();
    }
}

2. Start the Governance Registry instance and open its Management Console. Then run the Employee.java as a java application from you your IDE.

3. User can see the printed messages from the IDE's Console panel along with the log at the terminal.

...