Skip to content

Commit

Permalink
[incubator-kie-issues-1308] Exceptions in Service process (#3553)
Browse files Browse the repository at this point in the history
  • Loading branch information
elguardian authored Jun 21, 2024
1 parent 3585edf commit e1b6dcc
Show file tree
Hide file tree
Showing 15 changed files with 196 additions and 208 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
*/
public class LoggingTaskHandlerDecorator extends AbstractExceptionHandlingTaskHandler {

private static final Logger logger = LoggerFactory.getLogger(LoggingTaskHandlerDecorator.class);
private static Logger logger = LoggerFactory.getLogger(LoggingTaskHandlerDecorator.class);
private int loggedExceptionsLimit = 100;
private Queue<WorkItemExceptionInfo> exceptionInfoList = new ArrayDeque<>(loggedExceptionsLimit);

Expand Down Expand Up @@ -210,6 +210,10 @@ public synchronized void handleAbortException(Throwable cause, KogitoWorkItem wo
logMessage(false, workItem, cause);
}

public static void setLogger(Logger logger) {
LoggingTaskHandlerDecorator.logger = logger;
}

private void logMessage(boolean onExecute, KogitoWorkItem workItem, Throwable cause) {
String handlerMethodStem = "execut";
if (!onExecute) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ public final void trigger(KogitoNodeInstance from, String type) {

protected void captureError(Exception e) {
logger.error("capture error", e);
e.printStackTrace();
getProcessInstance().setErrorState(this, e);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.jbpm.bpmn2.services;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Interface1 {

Logger LOGGER = LoggerFactory.getLogger(Interface1.class);

public void operation1(String value) {
LOGGER.info("operation1 in interface1 = {}", value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</operation>
</interface>

<process processType="Private" isExecutable="true" id="ServiceProcess" name="Service Process" >
<process processType="Private" isExecutable="true" id="ServiceProcess" name="Service Process" tns:packageName="org.jbpm.bpmn2.service">

<!-- process variables -->
<property id="s" itemSubjectRef="_sItem"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</operation>
</interface>

<process processType="Private" isExecutable="true" id="ServiceProcess" name="Service Process" >
<process processType="Private" isExecutable="true" id="ServiceProcessWithCustomTransformation" tns:packageName="org.jbpm.bpmn2.service">

<!-- process variables -->
<property id="s" itemSubjectRef="_sItem"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@
~ under the License.
-->

<bpmn:definitions id="EAPK_CCE882F2_23D3_4e7e_80FE_6D8C0AF83CAA" targetNamespace="www.sparxsystems.com.au/bpmn20" xmlns:ssbp="www.sparxsystems.com.au/bpmn20" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" exporter="Enterprise Architect" exporterVersion="10.0.1004">
<bpmn:definitions id="EAPK_CCE882F2_23D3_4e7e_80FE_6D8C0AF83CAA"
targetNamespace="www.sparxsystems.com.au/bpmn20"
xmlns:ssbp="www.sparxsystems.com.au/bpmn20"
xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:drools="http://www.jboss.org/drools"
exporter="Enterprise Architect" exporterVersion="10.0.1004">

<bpmn:process id="EAID_DP000000_23D3_4e7e_80FE_6D8C0AF83CAA">
<bpmn:process id="ServiceTask" drools:packageName="org.jbpm.bpmn2.service">
<bpmn:startEvent id="EAID_010AED45_CEDD_4cba_9153_7ED25329D3E2" name="StartEvent1" isInterrupting="true" parallelMultiple="false">
<bpmn:outgoing>EAID_DE09F4BA_6B35_4699_8AC9_84819B916A98</bpmn:outgoing>
</bpmn:startEvent>
Expand Down Expand Up @@ -48,8 +57,8 @@
</bpmn:process>
<bpmn:itemDefinition id="EAID_691666AE_9DFF_4003_B94E_D40F037565C1" isCollection="false" structureRef="java.lang.String"/>
<bpmn:message id="EAID_137CB429_F782_4fee_8CC8_D57206264E3E" name="Message1" itemRef="EAID_691666AE_9DFF_4003_B94E_D40F037565C1"/>
<bpmn:interface id="EAID_B73BF5BB_A892_460d_B3BA_5D8873850689" name="Interface1">
<bpmn:operation id="EAID_6F76C1D0_E4CA_4b76_8A2F_9F7C33D2C90F" name="Operation1">
<bpmn:interface id="EAID_B73BF5BB_A892_460d_B3BA_5D8873850689" name="org.jbpm.bpmn2.services.Interface1">
<bpmn:operation id="EAID_6F76C1D0_E4CA_4b76_8A2F_9F7C33D2C90F" name="operation1">
<bpmn:inMessageRef>EAID_137CB429_F782_4fee_8CC8_D57206264E3E</bpmn:inMessageRef>
</bpmn:operation>
</bpmn:interface>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
<bpmn2:itemDefinition id="_sItem2" structureRef="java.lang.String"/>
<bpmn2:itemDefinition id="_2_InMessageType" structureRef="java.lang.String"/>
<bpmn2:message id="_2_InMessage" itemRef="_2_InMessageType" name="_2_InMessage"/>
<bpmn2:interface id="_2_ServiceInterface" name="justaname" implementationRef="SimpleService">
<bpmn2:operation id="_2_ServiceOperation" implementationRef="hello" name="hello">
<bpmn2:interface id="_2_ServiceInterface" name="justaname" implementationRef="org.jbpm.bpmn2.services.Interface1">
<bpmn2:operation id="_2_ServiceOperation" implementationRef="operation1" name="operation1">
<bpmn2:inMessageRef>_2_InMessage</bpmn2:inMessageRef>
</bpmn2:operation>
</bpmn2:interface>
<bpmn2:process id="org.jboss.qa.jbpm.CallWS" tns:version="1" tns:packageName="defaultPackage" tns:adHoc="false" name="CallWS" isExecutable="true" processType="Private">
<bpmn2:process id="ServiceTaskWebService" tns:version="1" tns:packageName="org.jbpm.bpmn2.service" tns:adHoc="false" name="CallWS" isExecutable="true" processType="Private">
<bpmn2:startEvent id="StartEvent_1" name="Start">
<bpmn2:outgoing>SequenceFlow_3</bpmn2:outgoing>
</bpmn2:startEvent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</operation>
</interface>

<process processType="Private" isExecutable="true" id="ServiceProcess" name="Service Process" >
<process processType="Private" isExecutable="true" id="ExceptionServiceProcessErrorSignalling" name="Service Process" tns:packageName="org.jbpm.bpmn2.service">

<!-- process variables -->
<property id="serviceInputItem" itemSubjectRef="_stringItem"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
</operation>
</interface>

<process processType="Private" isExecutable="true" id="ServiceProcess" name="Service Process" >
<process processType="Private" isExecutable="true" id="ExceptionServiceProcessSignalling"
tns:packageName="org.jbpm.bpmn2.subprocess"
name="Service Process" >

<!-- process variables -->
<property id="serviceInputItem" itemSubjectRef="_stringItem"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</operation>
</interface>

<process processType="Private" isExecutable="true" id="ServiceProcess" name="Service Process" >
<process processType="Private" isExecutable="true" id="ExceptionThrowingServiceProcess" tns:packageName="org.jbpm.bpmn2.subprocess" >

<!-- process variables -->
<property id="serviceInputItem" itemSubjectRef="_sItem"/>
Expand Down
90 changes: 32 additions & 58 deletions jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,23 @@
import org.jbpm.bpmn2.flow.XORSameTargetProcess;
import org.jbpm.bpmn2.handler.ReceiveTaskHandler;
import org.jbpm.bpmn2.handler.SendTaskHandler;
import org.jbpm.bpmn2.handler.ServiceTaskHandler;
import org.jbpm.bpmn2.objects.Account;
import org.jbpm.bpmn2.objects.Address;
import org.jbpm.bpmn2.objects.HelloService;
import org.jbpm.bpmn2.objects.Person;
import org.jbpm.bpmn2.objects.TestWorkItemHandler;
import org.jbpm.bpmn2.service.ServiceProcessModel;
import org.jbpm.bpmn2.service.ServiceProcessProcess;
import org.jbpm.bpmn2.service.ServiceProcessWithMvelCollectionTransformationModel;
import org.jbpm.bpmn2.service.ServiceProcessWithMvelCollectionTransformationProcess;
import org.jbpm.bpmn2.service.ServiceProcessWithMvelJaxbTransformationModel;
import org.jbpm.bpmn2.service.ServiceProcessWithMvelJaxbTransformationProcess;
import org.jbpm.bpmn2.service.ServiceProcessWithMvelTransformationModel;
import org.jbpm.bpmn2.service.ServiceProcessWithMvelTransformationProcess;
import org.jbpm.bpmn2.service.ServiceTaskModel;
import org.jbpm.bpmn2.service.ServiceTaskProcess;
import org.jbpm.bpmn2.service.ServiceTaskWebServiceModel;
import org.jbpm.bpmn2.service.ServiceTaskWebServiceProcess;
import org.jbpm.bpmn2.subprocess.AssignmentProcessModel;
import org.jbpm.bpmn2.subprocess.AssignmentProcessProcess;
import org.jbpm.bpmn2.subprocess.AssignmentSubProcessModel;
Expand Down Expand Up @@ -154,13 +159,14 @@
import org.kie.kogito.auth.SecurityPolicy;
import org.kie.kogito.handlers.HelloService_hello__2_Handler;
import org.kie.kogito.handlers.HelloService_validate__2_Handler;
import org.kie.kogito.handlers.Interface1_operation1_EAID_3344916D_2BAC_4ab6_92D4_F739156D0933_Handler;
import org.kie.kogito.handlers.Interface1_operation1_ServiceTask_2_Handler;
import org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener;
import org.kie.kogito.internal.process.runtime.KogitoNode;
import org.kie.kogito.internal.process.runtime.KogitoNodeInstance;
import org.kie.kogito.internal.process.runtime.KogitoProcessInstance;
import org.kie.kogito.internal.process.runtime.KogitoProcessRuntime;
import org.kie.kogito.internal.process.runtime.KogitoWorkItem;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemManager;
import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance;
import org.kie.kogito.process.ProcessInstance;
import org.kie.kogito.process.workitems.InternalKogitoWorkItem;
Expand Down Expand Up @@ -811,63 +817,32 @@ public void testAdHocProcessDynamicSubProcess() throws Exception {

@Test
public void testServiceTask() throws Exception {
kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcess.bpmn2");

kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task",
new ServiceTaskHandler());
Map<String, Object> params = new HashMap<>();
params.put("s", "john");
KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime
.startProcess("ServiceProcess", params);
assertProcessInstanceFinished(processInstance, kruntime);
assertThat(processInstance.getVariable("s")).isEqualTo("Hello john!");
}

@Test
public void testServiceTaskWithAccessToWorkItemInfo() throws Exception {
kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcess.bpmn2");
Application app = ProcessTestHelper.newApplication();
ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.objects.HelloService_hello__2_Handler", new HelloService_hello__2_Handler());
org.kie.kogito.process.Process<ServiceProcessModel> definition = ServiceProcessProcess.newProcess(app);

kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task",
new ServiceTaskHandler() {
ServiceProcessModel model = definition.createModel();
model.setS("john");
org.kie.kogito.process.ProcessInstance<ServiceProcessModel> instance = definition.createInstance(model);
instance.start();

@Override
public void executeWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem workItem, KogitoWorkItemManager manager) {
assertThat(workItem.getProcessInstance()).isNotNull();
assertThat(workItem.getNodeInstance()).isNotNull();
super.executeWorkItem(workItem, manager);
}
assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED);
assertThat(instance.variables().getS()).isEqualTo("Hello john!");

});
Map<String, Object> params = new HashMap<>();
params.put("s", "john");
KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime.startProcess("ServiceProcess", params);
assertProcessInstanceFinished(processInstance, kruntime);
assertThat(processInstance.getVariable("s")).isEqualTo("Hello john!");
}

@Test
public void testServiceTaskNoInterfaceName() throws Exception {
kruntime = createKogitoProcessRuntime("BPMN2-ServiceTask-web-service.bpmn2");
Application app = ProcessTestHelper.newApplication();
ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.services.Interface1_operation1_ServiceTask_2_Handler", new Interface1_operation1_ServiceTask_2_Handler());
org.kie.kogito.process.Process<ServiceTaskWebServiceModel> definition = ServiceTaskWebServiceProcess.newProcess(app);

kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task",
new SystemOutWorkItemHandler() {
ServiceTaskWebServiceModel model = definition.createModel();
org.kie.kogito.process.ProcessInstance<ServiceTaskWebServiceModel> instance = definition.createInstance(model);
instance.start();

@Override
public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {
assertThat(workItem.getParameter("Interface")).isEqualTo("SimpleService");
assertThat(workItem.getParameter("Operation")).isEqualTo("hello");
assertThat(workItem.getParameter("ParameterType")).isEqualTo("java.lang.String");
assertThat(workItem.getParameter("implementation")).isEqualTo("##WebService");
assertThat(workItem.getParameter("operationImplementationRef")).isEqualTo("hello");
assertThat(workItem.getParameter("interfaceImplementationRef")).isEqualTo("SimpleService");
super.executeWorkItem(workItem, manager);
}
assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED);

});
Map<String, Object> params = new HashMap<>();
KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime
.startProcess("org.jboss.qa.jbpm.CallWS", params);
assertProcessInstanceFinished(processInstance, kruntime);
}

@Test
Expand Down Expand Up @@ -1131,17 +1106,16 @@ public void testInvalidServiceTask() {
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> createKogitoProcessRuntime("BPMN2-InvalidServiceProcess.bpmn2"));
}

@Test // JBPM-3951
@Test
public void testServiceTaskInterface() throws Exception {
kruntime = createKogitoProcessRuntime("BPMN2-ServiceTask.bpmn2");

kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", new SystemOutWorkItemHandler());
Map<String, Object> params = new HashMap<>();

KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime
.startProcess("EAID_DP000000_23D3_4e7e_80FE_6D8C0AF83CAA", params);
assertProcessInstanceFinished(processInstance, kruntime);
Application app = ProcessTestHelper.newApplication();
Interface1_operation1_EAID_3344916D_2BAC_4ab6_92D4_F739156D0933_Handler handler = new Interface1_operation1_EAID_3344916D_2BAC_4ab6_92D4_F739156D0933_Handler();
ProcessTestHelper.registerHandler(app, handler.getName(), handler);
org.kie.kogito.process.Process<ServiceTaskModel> definition = ServiceTaskProcess.newProcess(app);
org.kie.kogito.process.ProcessInstance<ServiceTaskModel> instance = definition.createInstance(definition.createModel());
instance.start();

assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED);
}

@SuppressWarnings("unchecked")
Expand Down
Loading

0 comments on commit e1b6dcc

Please sign in to comment.