Retrieving Information About BPEL Processes via APIs
The Business Process profile of WSO2 EI has a management API for you to retrieve information on deployed processes, running and completed instances, variables, values etc. It consists of the below services. You can find the methods that are available in the below WSDL files.
You can invoke the above services via any web service client.
It is mandatory to authenticate the user before invoking management services.
The below sections walk you through the instructions on retrieving information about managing BPEL processes and instances from the management API via a sample Java client. You can customize this client based on your requirements.
Creating the Sample Client
Follow the steps below to create the sample Java Client using WSO2 EI Tooling.
Creating the Maven Project
Create a Maven Project using the following information. For instructions, see Creating the Maven project.
You can skip step 5 since you do not need to add external JAR files in this example.
Group Id:
org.wso2.bpel
Artifact Id :
BPELSampleClient
Creating the Java Package
Create a Java Package inside the Maven Project using the following information. For instructions, see /wiki/spaces/EI6xx/pages/49614451.
Name:
org.wso2.bpel.bpelclient.v1
Creating the Java Class
- Create a Java Class inside the Maven Project using the following information. For instructions, see /wiki/spaces/EI6xx/pages/49614451.
- Name:
BPSManagementClient
- Name:
In the Project Explorer, double-click on the BPSManagementClient.java file and replace its source with the below content.
BPSManagementClient.javapackage org.wso2.bpel.bpelclient.v1; import java.rmi.RemoteException; import org.apache.axis2.client.Options; import org.apache.axis2.client.ServiceClient; import org.apache.axis2.context.ServiceContext; import org.apache.axis2.transport.http.HTTPConstants; import org.wso2.carbon.authenticator.stub.AuthenticationAdminStub; import org.wso2.carbon.authenticator.stub.Login; import org.wso2.carbon.authenticator.stub.LoginAuthenticationExceptionException; import org.wso2.carbon.bpel.stub.mgt.InstanceManagementException; import org.wso2.carbon.bpel.stub.mgt.InstanceManagementServiceStub; import org.wso2.carbon.bpel.stub.mgt.ProcessManagementException; import org.wso2.carbon.bpel.stub.mgt.ProcessManagementServiceStub; import org.wso2.carbon.bpel.stub.mgt.types.LimitedInstanceInfoType; import org.wso2.carbon.bpel.stub.mgt.types.LimitedProcessInfoType; import org.wso2.carbon.bpel.stub.mgt.types.PaginatedInstanceList; import org.wso2.carbon.bpel.stub.mgt.types.PaginatedProcessInfoList; public class BPSManagementClient { final String backendServerURL = "https://localhost:9445/services/"; final String AUTHENTICATION_ADMIN_SERVICE = "AuthenticationAdmin"; final String trustStore = "/Users/praneesha/Documents/Product_Packs/wso2ei-6.6.0/repository/resources/security"; String userName = "admin"; String password = "admin"; String clientIPAddr = "localhost"; String cookie = null; public static void main(String[] args) { boolean isLogged = false; BPSManagementClient client = new BPSManagementClient(); try { isLogged = client.authenticate(); PaginatedProcessInfoList processList = null; if (isLogged) { System.out.println("User: " + client.userName + " loggin successful"); processList = client.listProcessesPaginated("name}}* namespace=*", "deployed name", 0); LimitedProcessInfoType[] processes = processList.getProcessInfo(); if (processes != null) { System.out.println("---------------------------PROCESS LIST---------------------------"); String leftAlignFormat = "| %-60s | %-10s | %-10s | %-20s | %-30s | %n"; System.out.format("+--------------------------------------------------------------+------------+------------+----------------------+--------------------------------+%n"); System.out.format("| %-60s | %-10s | %-10s | %-20s | %-30s | %n", "PROCESS ID", "STATUS", "VERSION", "PACKAGE", "DEPLOYED ON"); System.out.format("+--------------------------------------------------------------+------------+------------+----------------------+--------------------------------+%n"); for (LimitedProcessInfoType process: processes) { System.out.format(leftAlignFormat, process.getPid(), process.getStatus(), process.getVersion(), process.getPackageName(), process.getDeployedDate().getTime().toString()); } System.out.format("+--------------------------------------------------------------+------------+------------+----------------------+--------------------------------+%n"); } else { System.out.println("NULL process list"); } System.out.println("\n"); PaginatedInstanceList instanceList = client.listInstancesPaginated("pid=*", "pid", 10, 0); LimitedInstanceInfoType[] instances = instanceList.getInstance(); if (instances != null) { System.out.println("---------------------------INSTANCE LIST---------------------------"); String leftAlignFormat = "| %-60s | %-10s | %-10s | %n"; System.out.format("+--------------------------------------------------------------+------------+------------+%n"); System.out.format("| %-60s | %-10s | %-10s | %n", "PROCESS ID", "TASK ID", "STATUS"); System.out.format("+--------------------------------------------------------------+------------+------------+%n"); for (LimitedInstanceInfoType instance: instances) { System.out.format(leftAlignFormat, instance.getPid(), instance.getIid(), instance.getStatus()); } System.out.format("+--------------------------------------------------------------+------------+------------+%n"); } else { System.out.println("NULL instance list"); } } else { System.out.println("User: " + client.userName + " loggin FAILED!"); } } catch (LoginAuthenticationExceptionException e) { System.out.println("User: " + client.userName + " login failed due to :" + e); } catch (RemoteException | ProcessManagementException | InstanceManagementException e) { System.out.println("Error while retriving process list " + e); } } public boolean authenticate() throws RemoteException, LoginAuthenticationExceptionException { String serviceURL = backendServerURL + AUTHENTICATION_ADMIN_SERVICE; AuthenticationAdminStub authenticationAdminStub = new AuthenticationAdminStub(null, serviceURL); Login loginRequest = new Login(); loginRequest.setUsername(userName); loginRequest.setPassword(password); loginRequest.setRemoteAddress(clientIPAddr); System.setProperty("javax.net.ssl.trustStore", trustStore + "/client-truststore.jks"); System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon"); boolean isLogged = authenticationAdminStub.login(userName, password, "localhost"); if (isLogged) { System.out.println("Login Successful"); ServiceContext serviceContext = authenticationAdminStub._getServiceClient().getLastOperationContext() .getServiceContext(); cookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING); System.out.println(cookie); } return isLogged; } public PaginatedProcessInfoList listProcessesPaginated(String filter, String orderBy, int pageNumber) throws RemoteException, ProcessManagementException { String serviceURL = backendServerURL + "ProcessManagementService"; ProcessManagementServiceStub stub = new ProcessManagementServiceStub(null, serviceURL); ServiceClient client = stub._getServiceClient(); Options option = client.getOptions(); option.setManageSession(true); option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie); return stub.getPaginatedProcessList(filter, orderBy, pageNumber); } public PaginatedInstanceList listInstancesPaginated(String filter, String orderBy, int limit, int pageNumber) throws RemoteException, InstanceManagementException { String serviceURL = backendServerURL + "InstanceManagementService"; InstanceManagementServiceStub stub = new InstanceManagementServiceStub(null, serviceURL); ServiceClient client = stub._getServiceClient(); Options option = client.getOptions(); option.setManageSession(true); option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie); return stub.getPaginatedInstanceList(filter, orderBy, limit, pageNumber); } }
In the Project Explorer, double-click on the pom.xml file and replace its source with the below content.
pom.xml<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.wso2.bpel</groupId> <artifactId>BPELSampleClient</artifactId> <version>0.0.1-SNAPSHOT</version> <repositories> <repository> <id>wso2.releases</id> <name>WSO2 internal Repository</name> <url>http://maven.wso2.org/nexus/content/repositories/releases/</url> <releases> <enabled>true</enabled> <updatePolicy>daily</updatePolicy> <checksumPolicy>ignore</checksumPolicy> </releases> </repository> </repositories> <dependencies> <dependency> <groupId>org.apache.axis2.wso2</groupId> <artifactId>axis2</artifactId> <version>1.6.1-wso2v27</version> </dependency> <dependency> <groupId>org.wso2.carbon.business-process</groupId> <artifactId>org.wso2.carbon.bpel.stub</artifactId> <version>4.4.70</version> </dependency> <dependency> <groupId>org.wso2.carbon</groupId> <artifactId>org.wso2.carbon.authenticator.stub</artifactId> <version>4.4.6</version> </dependency> </dependencies> </project>
Executing the Sample Client
Follow the steps below to execute the above Sample Client.
Start the Business Process Profile and log in to the Management Console using admin/admin credentials. For instructions, see Starting the product profiles.
You need to have at least one BPEL package deployed and one instance created to view them in the output. Also, this sample client uses the default username (admin), password (admin) credentials to log in to the Business Process Profile and retrieve the information.
- In the Project Explorer, right click on the
pom.xml
file and click Run As → 6 Maven Install. - In the Project Explorer, right click on the BPELSampleClient and click Run As → 1 Java Application.
You view the output printed in the Terminal. This includes information about the BPEL processes and instances, which are currently deployed in the Business Process profile.