As we evaluate the Camunda product line for use in workflow, I’ve written a simple application to demonstrate to our infrastructure group. I’ve been able to build it and run it with an embedded engine as a Spring Boot application, but have been having problems running it with a shared engine (we are evaluating both options).
I am seeing the following error:
java.lang.ClassCastException: com.ncs.domain.BaseDomain$JaxbAccessorM_getId_setId_java_lang_String cannot be cast to spinjar.com.sun.xml.bind.v2.runtime.reflect.Accessor
In my Spring Boot application I do not use camunda-spin-dataformat-all; I use the two individual (json and xml) jars and it works fine. With the Camunda Tomcat distribution, I don’t see that as an option without making changes to the installation.
I am using a Spring REST controller to start a process instance by message. I set the process application context beforehand. All Camunda dependencies (version 7.12.0) are declared as provided in the pom. The “WorkflowRequest” object is defined in an external library over which I have very little control. The error occurs when I invoke startProcessInstanceByMessage. Any suggestions on how to work around this would be most appreciated.
Controller code:
package com.ncs.demo.workflow.multiinstance.thirteencell.web.controller;
import org.camunda.bpm.application.ProcessApplicationContext;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.variable.Variables;
import org.camunda.bpm.engine.variable.value.ObjectValue;
import org.camunda.spin.DataFormats;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.ncs.domain.enterprise.esb.workflow.request.WorkflowRequest;
@RestController
@RequestMapping(value = "/workflow")
public class MessageController {
private static Logger log = LoggerFactory.getLogger(MessageController.class);
@Autowired
private RuntimeService runtimeService;
@RequestMapping(value = "/{messageName}/**", method = RequestMethod.POST, consumes = MediaType.APPLICATION_XML_VALUE)
public void processRequest(@PathVariable("messageName") String messageName, @RequestBody WorkflowRequest request) {
log.debug("Sending message to " + messageName);
log.debug("Request id = " + request.getId());
try {
ProcessApplicationContext.setCurrentProcessApplication("workflow");
ObjectValue objectValue = Variables.objectValue(request).serializationDataFormat(DataFormats.XML_DATAFORMAT_NAME).create();
ProcessInstance processInstance = runtimeService.startProcessInstanceByMessage(messageName, request.getId(), Variables.putValue("workflowRequest", objectValue));
//ProcessInstance processInstance = runtimeService.startProcessInstanceByMessage(messageName, request.getId(), Variables.putValue("workflowRequest", request));
log.debug("Started processInstance " + processInstance.getProcessInstanceId());
} finally {
ProcessApplicationContext.clear();
}
}
}