个性化阅读
专注于IT技术分析

jBPM作为远程服务

点击下载

本文概述

jBPM平台提供了许多远程API服务。在设计需要jBPM集成的解决方案时, 它为开发人员提供了更高水平的灵活性。这种远程API通过灵活, 开放的体系结构开辟了许多可能性, 以满足并快速响应不断变化的应用程序需求。

JBPM使用以下远程服务API-

jBPM远程服务

REST API

该API用于管理任务, 流程, 创建流程实例以及其他需要使用简单HTTP客户端库的操作。它提供以下领域的功能-

RuntimeEngine-它为用户提供流程实例创建, 流程实例查询和工作项操作。

历史记录-提供审核数据。

任务-提供任务操作和任务查询方法。

部署-提供部署管理操作。

认证方式

jBPM为REST API提供身份验证。调用后, REST服务操作将检查当前HTTP会话的基本身份验证用户ID。如果我们未被授权, 则会出现错误, 否则请设置用户ID和密码进行身份验证。这将返回以下响应-

<deployment-unit>
	<groupId>com.sample</groupId>
	<artifactId>helloworld</artifactId>
	<version>1.0</version>
	<kbaseName/>
	<ksessionName/>
	<strategy>SINGLETON</strategy>
	<status>DEPLOYED</status>
</deployment-unit>

远程Java API

如果我们不想手动创建HTTP请求以远程访问jBPM, 则可以使用Java API。 Java API是高级API。它使用REST或JMS API与远程引擎服务进行交互, 以为用户提供服务API类, 例如TaskService, KieSession等。 Java API的入口点是classRuntimeEngine, 我们可以使用如下所示的类RemoteRuntimeEngineFactory来访问它。

// the deploymentId identifies the KIE module
        	public static String deploymentId = "com.abc.sasa:1.0";
        	RemoteRestRuntimeEngineBuilder restEngineBuilder = RemoteRuntimeEngineFactory.newRestBuilder()
        	.addDeploymentId(deploymentId)
        	.addUrl(instanceurl).addUserName(user)
        	.addPassword(password);
        	RemoteRestRuntimeEngineFactory engineFactory = restEngineBuilder
        	.buildFactory();

    // get the engine
        	RemoteRuntimeEngine engine = engineFactory.newRuntimeEngine();

    // get the services
        	TaskService taskService = engine.getTaskService();
        	KieSession ksession = engine.getKieSession();
        	ProcessInstance processInstance = ksession.startProcess(processID);

现在, 我们必须访问KieSession, TaskService和AuditService远程接口。这些接口有助于使用纯Java代码执行远程调用, 并管理与远程jbpm服务器的HTTP连接。远程API必须具有以下maven依赖关系。

<dependency>
    <groupId>org.kie.remote</groupId>
    <artifactId>kie-remote-client</artifactId>
    <version>7.7.0.Final</version>
</dependency>

SOAP API

SOAP代表简单对象访问协议。它是一种消息传递协议, 它允许程序在不同的操作系统上运行以使用HTTP协议交换信息。它允许我们客户端与服务器之间的通信。在此API中, 客户端可以向服务器发起请求, 然后服务器处理该请求并将响应返回给用户。

依赖-

SOAP API的Maven依赖关系如下-

<dependency>
    <groupId>org.kie.remote.ws</groupId>
    <artifactId>kie-remote-ws-common</artifactId>
    <version>7.7.0.Final</version>
</dependency>

命令Web服务

在本节中, 我们现在将描述如何使用其SOAP API调用jBPM。我们的jbpm-remote-server测试项目SOAPTest jUnit测试类创建一个Web服务客户端, 然后启动一个新的流程实例。

JBoss BPM Suite提供了CommandWebService形式的SOAP接口。 Java客户端被转换为生成的CommandWebService类。由kie-remote-client模块生成的类充当SOAP的客户端接口。下面的测试代码中引用的CommandWebServiceClient类是由kie-remote-clientJAR中的Web服务描述语言(WSDL)生成的。

import org.kie.remote.client.api.RemoteRuntimeEngineFactory;
import org.kie.remote.client.jaxb.JaxbCommandsRequest;
import org.kie.remote.client.jaxb.JaxbCommandsResponse;
import org.kie.remote.jaxb.gen.StartProcessCommand;
import org.kie.remote.services.ws.command.generated.CommandWebService;
import org.kie.services.client.serialization.jaxb.impl.JaxbCommandResponse;

public JaxbProcessInstanceResponse startProcessInstance(String user, String password, String processId, String deploymentId, String applicationUrl) throws Exception {

  CommandWebService client = RemoteRuntimeEngineFactory
    .newCommandWebServiceClientBuilder()
    .addDeploymentId(deploymentId)
    .addUserName(user)
    .addPassword(password)
    .addServerUrl(applicationUrl)
    .buildBasicAuthClient();

  // Get a response from the WebService:
  StartProcessCommand cmd = new StartProcessCommand();
  cmd.setProcessId(processId);
  JaxbCommandsRequest req = new JaxbCommandsRequest(deploymentId, cmd);
  final JaxbCommandsResponse response = client.execute(req);

  JaxbCommandResponse<?> cmdResp = response.getResponses().get(0);

  return (JaxbProcessInstanceResponse) cmdResp;
}
赞(0)
未经允许不得转载:srcmini » jBPM作为远程服务

评论 抢沙发

评论前必须登录!