2

我已经完成了通过 camunda http 连接器从 camunda bpmn 调用 http REST 端点的实现。

在这种情况下,首先,BpmnInvoker将调用 REST 端点,提供bpmnProcessId作为路径参数和Authorization键作为标头参数以及 requestBody 然后在BpmnInvoker相关 bpmn 图中将调用传递 requestBody 值。在这些 bpmn 任务中,会有一些服务任务会调用 REST 端点。

为了从 BPMN 图中调用 REST 端点,我使用了 camunda http 连接器。在这种情况下,我需要将授权密钥作为 http 标头传递给 REST 端点。

为此,我将授权密钥添加到变量映射中,并将其作为 bpmn 图中的变量,并添加到图像和 bpmn 图中提到的标题映射中。

但问题是因为这个授权通常长度超过 4000 个字符。因此,它不能通过 camunda 引擎作为字符串传递。我尝试将其转换为另一个对象(例如:byte [] / StringBuffer 等),假设它将被存储为 blob,但在这种情况下,当它要分配给 http 标头时,它会给出 Class Cast Exception。

  • 如何在卡蒙达做到这一点?
  • 无论如何不要将这些对象存储在数据库中?
  • 我注意到有一些选项可以将列类型更改为 Text CLOB / 增加大小等。这是个好主意吗?

BPMNInvoke.java

@Path("/base")
public class BpmnInvoker {

    ProcessEngine defaultProcessEngine = BpmPlatform.getProcessEngineService().getDefaultProcessEngine();
    RuntimeService runtimeService = defaultProcessEngine.getRuntimeService();

    @POST
    @Path("/path/{bpmnProcessId}")
    public Response start(@PathParam("bpmnProcessId") String bpmnProcessId, String requestBody, @HeaderParam("Authorization") String authorization) {

        Map<String, Object> variableMap = new HashMap<String, Object>();
        variableMap = IntegrationUtility.convertJSONStringToMap(requestBody);

        // Set the Authorization token to the variable map. 
        // Normally this is more than 4000 characters long dynamic key. 
        // It must be set as a http header value when invoking REST endpoint via http connector.
        variableMap.put("Authorization", authorization);

        // Invoke the bpmn diagram by calling the startProcessInstanceByKey on runtimeService.
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(bpmnProcessId, variableMap);

        // rest of the work after completing the process engine
    }

}

BPMN图 在此处输入图像描述

----
----
    <bpmn:serviceTask id="Task_1ujngj7" name="Dummy Service 2">
      <bpmn:extensionElements>
        <camunda:connector>
          <camunda:inputOutput>
            <camunda:inputParameter name="url">http://localhost:8080/x-services/path/to/rest/service</camunda:inputParameter>
            <camunda:inputParameter name="method">POST</camunda:inputParameter>
            <camunda:inputParameter name="headers">
              <camunda:map>
                <camunda:entry key="Authorization">${Authorization}</camunda:entry>
                <camunda:entry key="Content-Type">application/json</camunda:entry>
              </camunda:map>
            </camunda:inputParameter>
            <camunda:inputParameter name="payload">${payload}</camunda:inputParameter>
            <camunda:outputParameter name="payload">${response}</camunda:outputParameter>
          </camunda:inputOutput>
          <camunda:connectorId>http-connector</camunda:connectorId>
        </camunda:connector>
      </bpmn:extensionElements>
      <bpmn:incoming>SequenceFlow_0w4wfbo</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_153ti9s</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:sequenceFlow id="SequenceFlow_1kvov2r" sourceRef="Task_0i9s02e" targetRef="EndEvent_0o062nq" />
    <bpmn:serviceTask id="Task_0i9s02e" name="DummyServiceClear" camunda:delegateExpression="${dummyServiceClear}">
      <bpmn:incoming>SequenceFlow_153ti9s</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_1kvov2r</bpmn:outgoing>
    </bpmn:serviceTask>
----
----
4

1 回答 1

1

试试这个:

import org.camunda.bpm.engine.variable.Variables;
import org.camunda.bpm.engine.variable.Variables.SerializationDataFormats;

variableMap.put("Authorization", Variables
                              .objectValue(authorization)
                                  // tells the engine to use java serialization for persisting the value 
                              .serializationDataFormat(SerializationDataFormats.JAVA)  
                              .create());
于 2018-11-25T21:02:01.783 回答