Versions Compared

Key

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

...

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.3.0-SNAPSHOT/";
            System.setProperty("javax.net.ssl.trustStore","/home/rajith/GREG/final_test/wso2greg-5.23.0-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();
    }
}

...