KIE Server :: Java SE Client Example

Environment

  • Wildfly 10.0.0.Final
  • kie-server-7.4.1
  • nexus

KJAR

Process

 

KJAR project structure

pom.xml


	4.0.0

	blog.zciok.bpm.kieserver
	hello-kie-server-kjar
	1.0.0
	
	kjar

	hello-kie-server-kjar

	
		UTF-8
		7.4.1.Final
	

	
		${project.name}
		
			
				maven-compiler-plugin
				3.2
				
					1.8
					1.8
				
			

			
				org.kie
				kie-maven-plugin
				${jbpm.version}
				true
			
		
	
	
	
	
		
			nexus-snapshots
			http://localhost:8081/repository/maven-snapshots/
		
		
			nexus-releases
			http://localhost:8081/repository/maven-releases/
		
		

Deploy on Nexus
mvn deploy (mvn clean deploy)

Maven repository settings (settings.xml)

    
      nexus-snapshots
      admin
      admin123
    
    
      nexus-releases
      admin
      admin123
    

  

 

WildFly

Create user (if it’s required):
./add-user.sh -a -u kieserver -p kieserver1 -g admin,kie-server

Start server:
./standalone.sh -c standalone-full.xml -Dorg.kie.server.id=hello-kie-server -Dorg.kie.server.location=http://localhost:8080/kie-server/services/rest/server

 

Client

public class KieServerJavaSEClient {

    public static void main(String[] args) throws Exception {

    	String serverUrl = "http://localhost:8080/kie-server-7.4.1.Final/services/rest/server";
        String user = "kieserver";
        String password = "kieserver1";

        String containerId = "hello-kie-server-container";
        String processId = "Process_1";

        KieServicesConfiguration configuration = KieServicesFactory.newRestConfiguration(serverUrl, user, password);
        System.out.println(">>>>> configuration CredentialProvider = " + configuration.getCredentialsProvider().getAuthorization());

        configuration.setMarshallingFormat(MarshallingFormat.JAXB);
        System.out.println(">>>>> configuration getMarshallingFormat().name() = " + configuration.getMarshallingFormat().name());
        
        KieServicesClient kieServicesClient =  KieServicesFactory.newKieServicesClient(configuration);
        System.out.println(">>>>> kieServicesClient serverInfo = " + kieServicesClient.getServerInfo());
        
        boolean deployContainer = true;
        KieContainerResourceList containers = kieServicesClient.listContainers().getResult();
        
        // check if container is deployed
        if (containers != null) {
            for (KieContainerResource kieContainerResource : containers.getContainers()) {
                if (kieContainerResource.getContainerId().equals(containerId)) {
                    System.out.println(">>>>> Found container " + containerId + " skipping deployment...");
                    deployContainer = false;
                    break;
                }
            }
        }
        
        // deploy container        
        if (deployContainer) {
            System.out.println(">>>>> Deploying container " + containerId);
            KieContainerResource resource = new KieContainerResource(containerId, new ReleaseId("blog.zciok.bpm.kieserver", "hello-kie-server-kjar", "1.0.0"));
            kieServicesClient.createContainer(containerId, resource);
        }
        
        // query for available process definitions
        QueryServicesClient queryClient = kieServicesClient.getServicesClient(QueryServicesClient.class);
        List processes = queryClient.findProcesses(0, 10);
        System.out.println(">>>>> Available processes" + processes);

        // get details of process definition
        ProcessServicesClient processClient = kieServicesClient.getServicesClient(ProcessServicesClient.class);
        ProcessDefinition definition = processClient.getProcessDefinition(containerId, processId);
        System.out.println(">>>>> Definition details: " + definition);

        Map params = null;
        Long processInstanceId = processClient.startProcess(containerId, processId, params);
        System.out.println(">>>>> Process instance id: " + processInstanceId);

        List instances = queryClient.findProcessInstances(0, 10);
        System.out.println(">>>>> Active process instances: " + instances.size());
    }
}

 

Output

 

WildfFly console:

 

This entry was posted in kie server and tagged . Bookmark the permalink.

Leave a Reply