Internal Server Error: The process could not be started - Engine hangs when trying to to a HTTP GET in a Delegate


#1

Dear Camunda Community,

First, thanks for the great documentation and adviceyou guys provide through this forum. It already got me pretty far - but now I am stucked.

My Environment and what i am trying to achieve:
I am using the prepackaged camunda on Tomcat and an eclipse environment.

I am trying to get the following bpmn up and running:

On process start, two parameters are provided via a form in entry node “Data received”. Then, in check Input, I would like to trigger a Java Delegate - so I specified a Java implementation with Java Class: org.exampleDemo.core.CheckWebsiteDelegate - in the bpmn file.

The delegate wants to do an GET HTTP request to the following API: http://api.icndb.com/jokes/random

I am using the code below:

package org.exampleDemo.core;

import java.util.logging.Logger;

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.camunda.connect.Connectors;
import org.camunda.connect.httpclient.HttpConnector;
import org.camunda.connect.httpclient.HttpResponse;

public class CheckWebsiteDelegate implements JavaDelegate {

	private final static Logger LOGGER = Logger.getLogger("mylogger");
	
	public void execute(DelegateExecution execution) throws Exception {
		   LOGGER.info("Processing request.");
		   LOGGER.info("Website : '" + execution.getVariable("user_existingUrl"));		   
		   LOGGER.info("email : '" + execution.getVariable("user_contactEmail"));	
		   
		  HttpConnector http = Connectors.getConnector(HttpConnector.ID);
		   HttpResponse response = http.createRequest()
		   .get() 
		   .url("http://api.icndb.com/jokes/random")
		   .execute();

		   if(response.getStatusCode() == 200) {
			   LOGGER.info("Random Chuck Norris joke: " + response.getResponse());
		   }
		   else {
			   LOGGER.info("failure, return code was: " + response.getStatusCode());
		   }
		   
	}
}

The following error occurs:
I start a new process from the task list, then enter my information into two fields, once I click submit I get “Internal server” error:

My debugging so far:

  • Check debug logs of Tomcat server. I could not find any strange behavior here. It seem that the java code excutes until the line
    HttpConnector http = Connectors.getConnector(HttpConnector.ID);
    (because I see debug output until then).
    catalina.2017-08-10_part.log (25.3 KB)

  • I cross-checked my POM file against the Camunda getting starting guide and some of the examples at github, that seems ok for me. Can anyone spot a problem here? pom.xml (2.1 KB)

  • Use a vanilla processes.xml file
    processes.xml (473 Bytes)

  • My bpmn file: spectra.bpmn (4.6 KB)

  • I tried to close all firewalls and antivirus programs on my computer and tried on a completely different machine, and I got the same error.

The only error I get form time to time when I am building the project (I think that is not the problem because when I set compiler compliance level to 1.8, then do a maven update project, and then do a maven install I get a .war file that i can deploy.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project spectra-camunda: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR] -> [Help 1]

Do you have any ideas why this is failing or what I could do to get to the root of this issue? Right now I just get the “Internal Server Error” but no better read about where it fails.

Thank you so much,
P


#2

Dear camunda community,

I was researching on my own on this problem today. After reading all the docs, i am not sure if the way I outlined above is actually a good practise.

Is it actually good practice to do a HTTP API cann in an own java delgate class, or is it recommended to use the classless connectors that we can specify in the modeler only? (I wonder for the latter, how do I handle retries, etc. if the remote server is either slow or down?)

  HttpConnector http = Connectors.getConnector(HttpConnector.ID);
		   HttpResponse response = http.createRequest()
		   .get() 
		   .url("http://api.icndb.com/jokes/random")
		   .execute();

I hope someone can help me on this one…

Thanks,
P


#3

Hi @panda,

if you can build the JavaDelegate in Java, I would recommend to code the http call here, because it’s easier to mock in unit tests and to control in different integration test scenarios.

Hope this helps, Ingo


#4

Dear Ingo,

Thank you for your answer. This is also what my feeling tells me, also on handling retry schemas etc. it would make much more sense to do the API call in the JavaDelegate.

This is, however, exactly what I tried to do in my first post. I tried to do this with the CheckWebsiteDelegate that I posted. However that gives me that error “Internal Server Error” that I reported above.

Does anyone have a working example to do an API call in a Java Delegate that I can compare mz solution to?

Thank you so much and have a great day everyone,
P


#5

Hi @panda,

test the service you want to call with a Rest client like Postman to inspect the headers and the result, first.

From my experience the headers are important as well.

And to check the process, add a async before wait state to your service call. https://docs.camunda.org/manual/7.7/user-guide/process-engine/transactions-in-processes Then you can inspect the result in cockpit: https://docs.camunda.org/manual/7.7/webapps/cockpit/bpmn/failed-jobs/

Hope this helps,

Ingo