SequenceFlow Exception at Java

Hello, I’m trying to get source and target FlowNodes in my xml and using

byteArrayInputStream = new ByteArrayInputStream(input.getXml().getBytes(UTF8));
BpmnModelInstance modelInstance = Bpmn.readModelFromStream(byteArrayInputStream);

SequenceFlow sequenceFlow = modelInstance.getModelElementById("Task_12yh8ez");

FlowNode source = sequenceFlow.getSource();
FlowNode target = sequenceFlow.getTarget();

this method getting exception;
CustomizedResponseEntityExceptionHandler : Exception Message: class org.camunda.bpm.model.bpmn.impl.instance.ServiceTaskImpl cannot be cast to class org.camunda.bpm.model.bpmn.instance.SequenceFlow (org.camunda.bpm.model.bpmn.impl.instance.ServiceTaskImpl and org.camunda.bpm.model.bpmn.instance.SequenceFlow are in unnamed module of loader ‘app’)

My gradle configuration;
org.camunda.bpm.springboot:camunda-bpm-spring-boot-starter:3.3.1 org.camunda.bpm.springboot:camunda-bpm-spring-boot-starter-webapp:3.3.1
org.camunda.bpm.springboot:camunda-bpm-spring-boot-starter-rest:3.3.1

My Xml;
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn=“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” id=“Definitions_1oqflw4” targetNamespace=“http://bpmn.io/schema/bpmn” exporter=“Camunda Modeler” exporterVersion=“2.2.4”>
<bpmn:process id=“ali” name=“veli”>
<bpmn:userTask id=“Task_0d5qo6i” name=“userTask”>
bpmn:outgoingSequenceFlow_092robg</bpmn:outgoing>
</bpmn:userTask>
<bpmn:businessRuleTask id=“Task_1neom7v” name=“businesssTask”>
bpmn:incomingSequenceFlow_0nwxzxk</bpmn:incoming>
</bpmn:businessRuleTask>
<bpmn:serviceTask id=“Task_12yh8ez” name=“servicetsak”>
bpmn:incomingSequenceFlow_092robg</bpmn:incoming>
bpmn:outgoingSequenceFlow_0nwxzxk</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id=“SequenceFlow_092robg” sourceRef=“Task_0d5qo6i” targetRef=“Task_12yh8ez” />
<bpmn:sequenceFlow id=“SequenceFlow_0nwxzxk” sourceRef=“Task_12yh8ez” targetRef=“Task_1neom7v” />
</bpmn:process>
<bpmndi:BPMNDiagram id=“BPMNDiagram_1”>
<bpmndi:BPMNPlane id=“BPMNPlane_1” bpmnElement=“ali”>
<bpmndi:BPMNShape id=“UserTask_02t5zlj_di” bpmnElement=“Task_0d5qo6i”>
<dc:Bounds x=“156” y=“205” width=“100” height=“80” />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id=“BusinessRuleTask_1ekkayc_di” bpmnElement=“Task_1neom7v”>
<dc:Bounds x=“548” y=“205” width=“100” height=“80” />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id=“ServiceTask_09y01s5_di” bpmnElement=“Task_12yh8ez”>
<dc:Bounds x=“354” y=“205” width=“100” height=“80” />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id=“SequenceFlow_092robg_di” bpmnElement=“SequenceFlow_092robg”>
<di:waypoint x=“256” y=“245” />
<di:waypoint x=“354” y=“245” />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id=“SequenceFlow_0nwxzxk_di” bpmnElement=“SequenceFlow_0nwxzxk”>
<di:waypoint x=“454” y=“245” />
<di:waypoint x=“548” y=“245” />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

What should I do?

Anyone? :frowning:

Hi @CanBASCI

in this line:

SequenceFlow sequenceFlow = modelInstance.getModelElementById(“Task_12yh8ez”);

you have on the right side an element of a ServiceTask and you try to cast it to an element of a SequenceFlow on the left side. This does not work.
If you want to work with the SequenceFlows you should search for the IDs of these SequenceFlows .

For example the SequenceFlows of your task with the id Task_12yh8ez are:
Incoming SequenceFlow: SequenceFlow_092robg
Outgoing SequenceFlow: SequenceFlow_0nwxzxk

Regards
Michael

1 Like