3 Replies Latest reply on Aug 8, 2014 2:53 AM by sanbhat

    Running an externalized bmpn2 process definition file on Karaf.

    sanbhat

      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

       

          //Code which loads the BPMN2 external file in Activator OR OsgiCommandSupport implementation class

         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
      • The two classes, com.test.ToolsServicesOne and com.test.ToolsServicesTwo, reside in the same bundle in which the Activator or the OsgiCommandSupport implementation is present.

       

       

      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!

        • 1. Re: Running an externalized bmpn2 process definition file on Karaf.
          swiderski.maciej

          have you tried to use ResourceFactory.newURLResource("file:///.....") instead of file resource, maybe that will make a difference.

           

          HTH

          • 2. Re: Running an externalized bmpn2 process definition file on Karaf.
            sanbhat

            Thank you for the reply. Unfortunately this solution also did not work. And on Karaf, I am still getting the same error

             

            Error executing command: Cannot add asset: Error importing : 'com.test.ToolsServicesOne',Error importing : 'com.test.ToolsServicesTwo',

             

            The fact that, the code is working in JUnit and not on Karaf, makes me wonder whether its a ClassLoader issue. Is there any way where I can specify the different class-loader while creating the KieSession?

             

            Also, is my way of using Service Task correct (I am just assigning a simple pojo - such as com.test.ToolsServicesOne as the service class implementation) ?

            • 3. Re: Running an externalized bmpn2 process definition file on Karaf.
              sanbhat

              Since Karaf is an OSGI environment, and a specific JBPM bundle is doing the work of compiling/building my bpmn2 file, the bundle is required to do explicit "import" of the classes which I am asking it to load (com.test.TaskServicesOne...)

               

              What I mean by import is, having <Import-Package> declaration in MANIFEST.MF file of the bundle (using maven apache felix plugin). Since JBPM bundle's can't do this (they don't know / can't know my classes), this kind of service task doesn't work.

               

              Solution is to find workaround for service task attached to the pojo inside the client bundle. My approach was to create custom task nodes and attach custom WorkItemHandler implementations to them.