Use camunda rest services using spring boot

hi, I added camunda to my spring boot project and I tested whether it is working by using

http://localhost:8080/rest/engine

and that gives me “name”: “default” which means that works fine.

Now i tried to start my BPM by calling this URL inside my spring app (I added my BPM to my camunda cockpit before starting the spring boot application).
http://localhost:8080/engine-rest/process-definition/key/finex-CA/start
But it gives me an error with the status code of 404.

What may be the problem?

the end point is wrong… use:
http://localhost:8080/rest/process-definition/key/finex-CA/start

this works, thank you. But it gives me this error when i use this url -> http://localhost:8080/rest/process-definition/key/finex-CA/start

No matching process definition with key: finex-CA and no tenant-id

But when I start camunda using camunda starter script and i make a post call to this url -> http://localhost:8080/engine-rest/process-definition/key/finex-CA/start
And this start my BPM.

I can see that these URLs are different little bit. But i use the same process definition key which is finex-CA. I don’t provide a tenant id in here. but it starts the BPM.

Hi dushan_chain

Based on the error I think your deployment was not successful. Please check the Deployment details via cockpit and the try to start.
Also Check whether executable property is clicked.
If same problem then you can share your BPMN.

there are no error logs manish_kumar. Where can i find that executable property?

Hi,

While modeling your BPMN there will be property Executable in modeler.
It will be default checked. Just check once for confirmation.

.

If you can share the bpmn.

1 Like

yea that is enabled manish_kumar.

Is your deployment succeded.

1 Like

this is what is did manish_kumar.

I created a BPM using camunda modeler and i started the camunda using camunda starter script and then i deployed the BPM via RESP API using postman. Then i started it using postman. I used this api -> http://localhost:8080/engine-rest/process-definition/key/finex-CA/start

My BPM started with this api. Then i closed camunda and created a spring boot application with camunda and i tried to start my previously uploaded BPM using the REST API inside the app. This is the url that i used for that -> http://localhost:8080/rest/process-definition/key/finex-CA/start

But it wont start and it gives me this error

No matching process definition with key: finex-CA and no tenant-id

Hi dushan_chain1,

As per your Error that is clear that your deployment was not Success.

Please find below ways to find whether your deployment is Success.

  1. Check the Spring boot log(Console) So that you can find deployment Id with Process Key.
  2. If you use “camunda-bpm-spring-boot-starter-webapp” in your pom.xml You can able to launch Camunda cockpit Application and so that you can check whether the deployment is Success. If Success and you can try testing the bpmn from the same application and then if all goes well trying using with Spring Boot.
    3.Did you add any properties in application.properties that restrict deployment.

Apart of all these please let me know what are the dependices you add in SpringBoot in respect of camunda.
To use Camunda Rest services you should add Camunda Rest Dependencies.
Please find below link:
https://docs.camunda.org/manual/7.8/user-guide/spring-boot-integration/

Thanks,
Manish

1 Like

hi manish_kumar,

I added this dependency in my pom file.
<dependency>
<groupId>org.camunda.bpm.springboot</groupId>
<artifactId>camunda-bpm-spring-boot-starter-rest</artifactId>
<version>3.2.0</version>
</dependency>

I didn’t deploy my BPM using my spring boot application. I deployed my BPM seperately using postman. Then i took that process definition key and i tried to start the BPM inside my spring boot application. (My process definition key is “factoring-finex-CA”) Then i got this error.

2020-03-04 15:29:26.939 WARN 10721 — [nio-8080-exec-3] ExceptionHandler : org.camunda.bpm.engine.rest.exception.RestException: No matching process definition with key: factoring-finex-CA and no tenant-id
at org.camunda.bpm.engine.rest.impl.ProcessDefinitionRestServiceImpl.getProcessDefinitionByKey(ProcessDefinitionRestServiceImpl.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Hi,

I am able to understand your problem.

Confirm me the steps are correct
1.You started Camunda-Starter Script.
2. Deployed Bpmn Via postman.
3. Started Spring Boot Application.
4. Used Restapi in Spring Boot application and it throws error.

Is these steps are correct?

1 Like
  1. Yes
  2. Yes
    — i stopped camunda and then i went for 3rd step ----
  3. Yes
  4. Yes

Do i need to keep camunda app opened when i start and use ma spring app ?

Okay.

I got the root cause. yes after 2nd step you need to close the camunda so that only you can able to start Spring app.

The reason is clear, When ever you start camunda Script an engine (Engine1) will start with some h2 DB. (Example:DB1)
So in the second step you can able to deploy the process and all the data will store in that h2 DB. (Example:DB1) with the help of (Engine1)

In the third step when you start spring boot again an camunda new engine (Engine2) will try to start. Since you Stopped Engine 1,Engine 2 is starting without Error.
But in these Case the Engine 2 is using some other H2 DB (DB2).

In fourth step you are using Engine2 with DB2 to start the process and it throws error.

Here the problem is not using Multiple engines but all the engines you are using should connect same DB. Since all your deployment stores in DB.

To validate these you check the below file in camunda folder
camunda-bpm-tomcat-7.12.0\server\apache-tomcat-9.0.24\conf\server.xml (You can find the h2 DB details that is going to start) and Spring Boot log where you can see h2 db details. you can find different DB details.

Thanks,
Manish.

1 Like

this is my h2 db details from camunda,

How can i add find the h2 db in my spring boot app?

you can see while starting spring boot application in console log.

I think it will change at the end instead of ‘process-engine’ it will be ‘test’ I guess.

Try these steps:
1.Start Spring boot application
2.Deploy BPMN with postman use same url deployed before
3.Now Try to run process.

It will work. Check and let me know

Thanks,
Manish.T

1 Like

Hey thank you for the reply, i did like you said, now It don’t give the previous error. Now it gives me this error saying Nullpointerexception

2020-03-05 10:25:41.230 ERROR 6517 — [nio-8080-exec-6] c.b.s.b.s.r.CamundaJerseyResourceConfig] : Servlet.service() for servlet [org.camunda.bpm.spring.boot.starter.rest.CamundaJerseyResourceConfig] in context with path [] threw exception [java.lang.NullPointerException] with root cause

java.lang.NullPointerException: null
at org.camunda.bpm.engine.rest.sub.repository.impl.ProcessDefinitionResourceImpl.startProcessInstanceAtActivities(ProcessDefinitionResourceImpl.java:157) ~[camunda-engine-rest-jaxrs2-7.10.0.jar:7.10.0]
at org.camunda.bpm.engine.rest.sub.repository.impl.ProcessDefinitionResourceImpl.startProcessInstance(ProcessDefinitionResourceImpl.java:123) ~[camunda-engine-rest-jaxrs2-7.10.0.jar:7.10.0]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_201]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_201]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_201]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_201]
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:76) ~[jersey-server-2.27.jar:na]

i found the error here, when i start the BPM using th eRESP API, i havent provide the relevant post data payload which is an empty json. Now that i have used it with post request, it worked fine. Gave me status code of 200.

1 Like

Hi @dushan_chain1,

This due to when you embedded the Caminda in a Spring Boot Application it will start a new Server for the process definition for this project. The previous depolyment is on the sandalone server so there are using different memories to strore the process definitions. That’s why you can’t able to run your previous deployed BPM on embedded camunda engine.

1 Like