Getting java.lang.ClassNotFoundException when using Spin in JavaDelegate executing from ServiceTask


#1

Hi,
I want to execute a rest-call in a JavaDelegate and parse the Json-Response with Spin and set some ProcessVaraibles.
The current solution to do that with a built-in connector and parsing/setting with JAvaScript is working fine, but no option any longer.

The Rest-Call is no problem and working perfectly, but since i added the dependencies for Spin the hole thing crushes at the execution with a “java.lang.ClassNotFoundException”.
I stumble around an found several solutions (adding “scope provided”), but none of them worked for me.

The process starting correct and waiting at “Wait”, but crushes at “Call Action”.

Thanks for help!


pom.xml:

<dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.camunda.bpm</groupId>
        <artifactId>camunda-bom</artifactId>
        <version>7.7.0</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>  
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>org.camunda.bpm</groupId>
      <artifactId>camunda-engine</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.0.1</version>
      <scope>provided</scope>
    </dependency>
	<dependency>
	  <groupId>com.sun.jersey</groupId>
	  <artifactId>jersey-client</artifactId>
	  <version>1.8</version>
	</dependency>
    <dependency>
	   <groupId>org.camunda.bpm</groupId>
	   <artifactId>camunda-engine-plugin-spin</artifactId>
	   <version>7.7.0</version>
	   <scope>provided</scope>
	</dependency>
<!-- 	<dependency> -->
<!--     		<groupId>org.camunda.spin</groupId> -->
<!--     		<artifactId>camunda-spin-core</artifactId> -->
<!-- 	</dependency> -->
<!-- 	<dependency> -->
<!-- 	  <groupId>org.camunda.spin</groupId> -->
<!-- 	  <artifactId>camunda-spin-dataformat-all</artifactId> -->
<!--       <scope>provided</scope> -->
<!-- 	</dependency> -->

  </dependencies>

JavaDelegate:

public void execute(DelegateExecution execution) throws Exception {
	
	String root  = "https://jsonplaceholder.typicode.com";
	String url = root + "/posts/1";

	String payload = (String) execution.getVariable("actioncall");
	
	Client client = Client.create();

	WebResource webResource = client
	   .resource(url);

	ClientResponse response = webResource.accept("application/json")
               .get(ClientResponse.class);
    
    String resp = response.getEntity(String.class);
    
    execution.setVariable("response", resp);
    
    SpinJsonNode json = JSON(resp);
	for(String fieldname : json.fieldNames())
	{
		Object value = json.prop(fieldname).value();
		
		execution.setVariable(fieldname, value);
	}
	
}

TestJavascriptRestCall.bpmn (4.8 KB)


#2

Hi @firle,

  1. Please post the entire exception stacktrace
  2. Which Camunda version do you use?
  3. Which application server do you use?

Best regards,
Thorben


#3

Hi,
i managed to get it working. The Problem was a wrong annotation in the ServletProcessApplication and processes.xml. This is the only point I figured out, where the problem was. Now everything is working like a charm. For that took the example and changed the names until I had everything I desire. If you rename something wrong or don’t apply the needed pattern the process crushes with this Exception.

greets
Ephraim


#4

Just a heads-up that SPIN may still be using a different version of Jackson than your top-level application. That issue hung me up for awhile with the “class not found” (or something similar).

Noting that I needed SPIN functionality only for integration into Camunda’s web-UI features - specifically for representing process variable lists (etc.).

One comment on

execution.setVariable(fieldname, value)

The process token (process instance), depending on how many new process variables we’re looking at, may get a little unwieldy. So, why not simply store a discrete part of the resp as its own JSON object which SPIN should be able to manage - and provide drill-down notation with built-in web-UI display capabilities.


#5

We want to have native-acess to process-variables replied by the Server. Therefor we analyse which variables are called during the process and return them if needed. Setting the variables is done by this class.

i did not use the suggested Spin-dependency, but

    <dependency>
        <groupId>org.camunda.bpm</groupId>
    	<artifactId>camunda-engine-plugin-spin</artifactId>
    	<scope>provided</scope>
    </dependency>

now everything works well.