0

I am trying to load an external bmpn2 file and run it in Apache Karaf environment. Here's the bmpn2 file

<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.jboss.org/drools" xmlns="http://www.jboss.org/drools" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd http://www.jboss.org/drools drools.xsd http://www.bpsim.org/schemas/1.0 bpsim.xsd" id="Definition" expressionLanguage="http://www.mvel.org/2.0" targetNamespace="http://www.jboss.org/drools" typeLanguage="http://www.java.com/javaTypes">
  <bpmn2:itemDefinition id="ItemDefinition_3" structureRef="java.lang.String"/>
  <bpmn2:itemDefinition id="_ItemDefinition_5210" structureRef="com.test.ToolsServicesTwo"/>
  <bpmn2:message id="String" itemRef="ItemDefinition_3" name="String"/>
  <bpmn2:interface id="Interface_4" implementationRef="com.test.ToolsServicesOne" name="com.test.ToolsServicesOne">
    <bpmn2:operation id="_Operation_239" name="doService">
      <bpmn2:inMessageRef>String</bpmn2:inMessageRef>
    </bpmn2:operation>
  </bpmn2:interface>
  <bpmn2:interface id="Interface_5" implementationRef="com.test.ToolsServicesTwo" name="com.test.ToolsServicesTwo">
    <bpmn2:operation id="_Operation_306" name="doService">
      <bpmn2:inMessageRef>String</bpmn2:inMessageRef>
    </bpmn2:operation>
  </bpmn2:interface>
  <bpmn2:process id="com.test.sample_process" tns:version="1" tns:packageName="com.test" tns:adHoc="false" name="sample_process" isExecutable="true" processType="Private">
    <bpmn2:extensionElements>
      <tns:import name="com.test.ToolsServicesOne"/>
      <tns:import name="java.lang.String"/>
      <tns:import name="com.test.ToolsServicesTwo"/>
    </bpmn2:extensionElements>
    <bpmn2:property id="toolsMessage" itemSubjectRef="ItemDefinition_3"/>
    <bpmn2:startEvent id="StartEvent_1" name="StartProcess">
      <bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing>
    </bpmn2:startEvent>
    <bpmn2:serviceTask id="ServiceTask_1" name="ToolsServiceOne" implementation="##WebService" operationRef="_Operation_239">
      <bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_2</bpmn2:outgoing>
      <bpmn2:ioSpecification id="InputOutputSpecification_3">
        <bpmn2:dataInput id="DataInput_8" itemSubjectRef="ItemDefinition_3" name="Parameter"/>
        <bpmn2:inputSet id="InputSet_1" name="Input Set 1">
          <bpmn2:dataInputRefs>DataInput_8</bpmn2:dataInputRefs>
        </bpmn2:inputSet>
        <bpmn2:outputSet id="OutputSet_1" name="Output Set 1"/>
      </bpmn2:ioSpecification>
      <bpmn2:dataInputAssociation id="DataInputAssociation_4">
        <bpmn2:sourceRef>toolsMessage</bpmn2:sourceRef>
        <bpmn2:targetRef>DataInput_8</bpmn2:targetRef>
      </bpmn2:dataInputAssociation>
    </bpmn2:serviceTask>
    <bpmn2:sequenceFlow id="SequenceFlow_1" tns:priority="1" name="" sourceRef="StartEvent_1" targetRef="ServiceTask_1"/>
    <bpmn2:serviceTask id="ServiceTask_2" name="ToolsServiceTwo" implementation="##WebService" operationRef="_Operation_306">
      <bpmn2:incoming>SequenceFlow_2</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_3</bpmn2:outgoing>
      <bpmn2:ioSpecification id="InputOutputSpecification_5">
        <bpmn2:dataInput id="DataInput_9" itemSubjectRef="ItemDefinition_3" name="Parameter"/>
        <bpmn2:inputSet id="InputSet_2" name="Input Set 2">
          <bpmn2:dataInputRefs>DataInput_9</bpmn2:dataInputRefs>
        </bpmn2:inputSet>
        <bpmn2:outputSet id="OutputSet_2" name="Output Set 2"/>
      </bpmn2:ioSpecification>
      <bpmn2:dataInputAssociation id="DataInputAssociation_5">
        <bpmn2:sourceRef>toolsMessage</bpmn2:sourceRef>
        <bpmn2:targetRef>DataInput_9</bpmn2:targetRef>
      </bpmn2:dataInputAssociation>
    </bpmn2:serviceTask>
    <bpmn2:sequenceFlow id="SequenceFlow_2" tns:priority="1" name="" sourceRef="ServiceTask_1" targetRef="ServiceTask_2"/>
    <bpmn2:endEvent id="EndEvent_1" name="">
      <bpmn2:incoming>SequenceFlow_3</bpmn2:incoming>
    </bpmn2:endEvent>
    <bpmn2:sequenceFlow id="SequenceFlow_3" tns:priority="1" name="" sourceRef="ServiceTask_2" targetRef="EndEvent_1"/>
  </bpmn2:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_Process_1" bpmnElement="com.test.sample_process">
      <bpmndi:BPMNShape id="BPMNShape_StartEvent_1" bpmnElement="StartEvent_1">
        <dc:Bounds height="0.0" width="0.0" x="45.0" y="45.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="BPMNShape_ServiceTask_1" bpmnElement="ServiceTask_1">
        <dc:Bounds height="50.0" width="110.0" x="186.0" y="38.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="BPMNShape_ServiceTask_2" bpmnElement="ServiceTask_2">
        <dc:Bounds height="50.0" width="110.0" x="401.0" y="38.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="BPMNShape_EndEvent_1" bpmnElement="EndEvent_1">
        <dc:Bounds height="36.0" width="36.0" x="579.0" y="45.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_1" bpmnElement="SequenceFlow_1" sourceElement="BPMNShape_StartEvent_1" targetElement="BPMNShape_ServiceTask_1">
        <di:waypoint xsi:type="dc:Point" x="81.0" y="63.0"/>
        <di:waypoint xsi:type="dc:Point" x="128.0" y="63.0"/>
        <di:waypoint xsi:type="dc:Point" x="128.0" y="63.0"/>
        <di:waypoint xsi:type="dc:Point" x="186.0" y="63.0"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_2" bpmnElement="SequenceFlow_2" sourceElement="BPMNShape_ServiceTask_1" targetElement="BPMNShape_ServiceTask_2">
        <di:waypoint xsi:type="dc:Point" x="296.0" y="63.0"/>
        <di:waypoint xsi:type="dc:Point" x="343.0" y="63.0"/>
        <di:waypoint xsi:type="dc:Point" x="343.0" y="63.0"/>
        <di:waypoint xsi:type="dc:Point" x="401.0" y="63.0"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_3" bpmnElement="SequenceFlow_3" sourceElement="BPMNShape_ServiceTask_2" targetElement="BPMNShape_EndEvent_1">
        <di:waypoint xsi:type="dc:Point" x="511.0" y="63.0"/>
        <di:waypoint xsi:type="dc:Point" x="541.0" y="63.0"/>
        <di:waypoint xsi:type="dc:Point" x="541.0" y="63.0"/>
        <di:waypoint xsi:type="dc:Point" x="579.0" y="63.0"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn2:definitions>

Here's the code which is used to start the workflow

    File file = new File(workflowFile);
    if(file == null || !file.exists()) {
        throw new FileNotFoundException("Specified file path is invalid.");
    }
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.getEmpty()
            .addAsset(ResourceFactory.newFileResource(file ), ResourceType.BPMN2)
            .get();
    RuntimeManager manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);

    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());

    KieSession ksession = runtime.getKieSession();
    ksession.startProcess(processId);
    System.out.println("Proc started!");

Where, workflowFile represents the absolute URL to the bpmn2 file kept in some directory. When I run this code on Karaf (As bundle activator or Karaf command extension), I am getting following error

java.lang.IllegalArgumentException: Cannot add asset: Error importing : 'com.test.ToolsServicesOne',Error importing : 'com.test.ToolsServicesTwo',
        at org.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment.addAsset(SimpleRuntimeEnvironment.java:111)
        at org.jbpm.runtime.manager.impl.RuntimeEnvironmentBuilder.addAsset(RuntimeEnvironmentBuilder.java:341)

Note If I run the same class as simple JUnit test, I don't get any error

Can anyone please help me resolve this issue? I tried searching google/JBPM forum but couldn't find any solution. Thanks for your time on this thread!

sanbhat
  • 17,522
  • 6
  • 48
  • 64
  • which JBPM framework are you using? Is it OSGi ready? – Achim Nierbeck Aug 26 '14 at 15:28
  • I am using 6.1.0.Final, and yes it is OSGi ready. I finally figured out that this doesn't work. Reason being, JBPM bundle is trying to load the class in my bundle without explicitly importing it. JBPM bundle can't import my classes (or any other user defined classes also) as it doesn't know. So I had to do the work with custom workItemHandlers – sanbhat Aug 27 '14 at 11:51

0 Answers0