Search code examples
spring-bootrestcamunda

Custom REST Endpoint in Camunda


I am trying to create a custom REST API in Camunda. My Camunda application is standalone and I want to create a custom REST API to complete task and send response.

I created a separate REST Project to create an endpoint which an external application can call and complete a task and get response back.

https://github.com/harish2610/camunda-custom-rest/tree/master/camunda_rest_endpoint/src/main/java/com/camunda/custom/rest/endpoint

When I run this project, I get the following error .

Field engine in com.camunda.custom.rest.endpoint.service.TaskCompletionService required a bean of type 'org.camunda.bpm.engine.ProcessEngine' that could not be found.

I have another project where I have Camunda standalone application and I want my custom REST endpoint to act on the task of the workflow defined under this project:

https://github.com/harish2610/camunda-custom-rest/tree/master/my-project/src/main/java/com/example/workflow

My REST endpoint should look like this :

http://localhost:8088/engine-rest/api/completeTask

My questions are :

  1. Is it achievable to build a custom REST API endpoint in Camunda ?
  2. If so, How do I integrate my REST project and Camunda project together, so that they work together and give a response.

Please let me know what am I doing wrong in my approach ? Or is there any better approach to create a custom rest endpoint in Camunda ?

This is how I am trying to trigger the API from postman.

enter image description here

Thanks


Solution

  • A) The custom rest API needs to make use of the process engine. It can only do so if it is running in the same Spring context as the process engine. Currently you have two complete separate Spring Boot projects. You can fix this in different ways.

    B) Camunda and Spring use different frameworks to expose REST services. Camunda uses a standard JAX-RS implementation, so it can also work without Spring. Spring uses its own implementation provided by Spring MVC (see Difference between JAX-RS and Spring Rest)
    engine-rest is the context under which the process engine exposes its JAX-RS based REST api. You cannot mix Spring endpoints under the same context.

    • either use Spring, but expose the api under a separate context
    • or make your REST service use the JAX-RS (Jersey) implementation sued by Camunda.

    In this example I am using a Maven multi-module project and extending the Camunda JAX-RS REST api with a custom service https://github.com/rob2universe/camunda-custom-rest-endpoint/tree/main

    However, if you are writing a custom Facade, you may not plan to expose the Camunda REST API to clients at all. IN that case it would be better to keep your custom services under a separate context, so you can only expose that context and not allow access to the Camunda REST API from outside.