Integrating camunda REST API in my spring boot application and access all functionalities from my application


#1

Hi all, I’m new to camunda and I want to integrate camunda REST API in my own spring boot application. Below the details of my application properties file:

#Security properties
security.basic.enabled=false

server.port=8081

server.context-path=/api

#Database
db.driver: com.mysql.jdbc.Driver
db.url: jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=UTF-8
db.username: root
db.password: root

#Hibernate
hibernate.dialect: org.hibernate.dialect.MySQL5Dialect
hibernate.show_sql: true
hibernate.hbm2ddl.auto: update

#camunda configuration
camunda.bpm.history-level=audit
camunda.bpm.process-engine-name=CamundaProcessEngineConfiguration
camunda.bpm.jpa.enabled=true

Here is my build.gradle dependency:

compile group: ‘org.camunda.bpm’, name: ‘camunda-engine’, version: ‘7.6.0’
compile group: ‘org.camunda.bpm’, name: ‘camunda-engine-spring’, version: ‘7.6.0’
compile group: ‘org.camunda.bpm’, name: ‘camunda-engine-rest’, version: ‘7.6.0’
compile group: ‘org.jboss.resteasy’, name: ‘resteasy-jaxrs’, version: ‘3.1.2.Final’
compile group: ‘org.camunda.bpm.extension.springboot’, name: ‘camunda-bpm-spring-boot-starter-rest’, version: ‘2.0.0’

How can I implement camunda REST API and how I access it from postman.


#2

Do you use the camunda spring boot starter? If so, you should be able to activate rest by just adding the camunda-bpm-starter-rest dependency to your project.


#3

@jangalinski thanks for your reply. Deleted other dependencies. And run as springboot application now I don’t know how to access the camunda REST API via postman. I tried http://localhost:8081/api/engine is that correct?


#4

try http://localhost:8081/rest/engine


#5

thanks it’s working. can you tell me how to add process engine in spring boot.


#6

I would suggest you start by reading the documentation and exploring some of the examples …


#7

yeah now only seeing your examples thanks.


#8

Hi all, how Rest API can be extended?
I need to add additional endpoints to existing resource interfaces and/or override already implemented ones

Thanks in advance!


#9

You can find a lot of useful information in this topic: How to add custom Rest Endpoints to Shared Engine?


#10

I’m sorry but it wasn’t useful

I solved in this way:

Using camunda-bpm-spring-boot-starter-rest it will set up a default Rest API service
which you can’t change, so you don’t need to define it but just provide your CamundaJerseyResourceConfig and CamundaBpmRestJerseyAutoConfiguration as new Rest API service implementation extending the default class

Following an example:
CamundaBpmRestJerseyAutoConfiguration

@AutoConfigureBefore({JerseyAutoConfiguration.class})
@AutoConfigureAfter({CamundaBpmAutoConfiguration.class})
public class CamundaBpmRestJerseyAutoConfiguration
{
  @Bean
  @ConditionalOnMissingBean({CamundaJerseyResourceConfig.class})
  public CamundaJerseyResourceConfig createRestConfig()
  {
    return new CamundaJerseyResourceConfig();
  }
}

CamundaJerseyResourceConfig:

@Component
@ApplicationPath("/rest")
public class CamundaJerseyResourceConfig extends ResourceConfig implements InitializingBean {
	private static final Logger log = LoggerFactory.getLogger(CamundaJerseyResourceConfig.class);

	public void afterPropertiesSet() throws Exception {
		registerCamundaRestResources();
		registerAdditionalResources();
	}

	protected void registerCamundaRestResources() {
		log.info("Configuring camunda rest api.");
		registerClasses(NamedProcessEngineRestServiceImpl.class);
		registerClasses(CustomProcessEngineRestServiceImpl.class);

		// registerClasses(CamundaRestResources.getResourceClasses());
		registerClasses(CamundaRestResources.getConfigurationClasses());
		register(JacksonFeature.class);

		log.info("Finished configuring camunda rest api.");
	}

	protected void registerAdditionalResources() {
	}
}

As you can see I registered a CustomProcessEngineRestServiceImpl class as my new Rest API service implementation just overriding DefaultProcessEngineRestServiceImpl and registering your custom Rest service implementation (e.g TaskRestService)

For example I extended the TaskRestService with this steps:

  1. Extend TaskResourceImpl as CustomTaskRestServiceImpl to override a specific method (eg. claim, complete) or adding a new endpoint method

  2. Register your custom TaskRestService implementation subclassing DefaultProcessEngineRestServiceImpl as custom Rest API service

    public class CustomProcessEngineRestServiceImpl extends DefaultProcessEngineRestServiceImpl {
    
     @Path(TaskRestService.PATH)
     public TaskRestService getTaskRestService() {
     	CustomTaskRestServiceImpl subResource = new CustomTaskRestServiceImpl (null, getObjectMapper());
     	return subResource;
     }
    

    }

I hope was helpful :wink:
Best regards
Antonio


#11

I also included

org.camunda.bpm.extension camunda-bpm-spring-boot-starter-rest 1.3.0

But getting this error – class path resource [org/camunda/bpm/engine/spring/SpringProcessEngineServicesConfiguration.class] cannot be opened because it does not exist


#12

You have to carefully check which camunda, which spring boot and which camunda-bpm-starter version you are using.
Due to rapidly changing spring boot infrastructure, some strict constraints apply.

Find the matrix here: https://docs.camunda.org/manual/latest/user-guide/spring-boot-integration/version-compatibility/