This project is designed to simplify communication between a Java backend and the Operate API of Camunda Platform 8.
Add the dependency to your project:
<dependency> <groupId>io.camunda.spring</groupId> <artifactId>spring-boot-starter-camunda-operate</artifactId> <version>${version.operate-client}</version> </dependency>This client is compatible with the Camunda v2 API. To use it, please configure:
operate: client: profile: v2Configure a Camunda Operate client with simple authentication:
operate: client: profile: simpleTo adjust the (meaningful) default properties, you can also override them:
operate: client: profile: simple enabled: true base-url: http://localhost:8081 session-timeout: PT10M username: demo password: demoConfigure a Camunda Operate client with identity authentication:
operate: client: profile: oidc client-id: client-secret: scope: # optional resource: # optionalTo adjust the (meaningful) default properties, you can also override them:
operate: client: profile: oidc enabled: true base-url: http://localhost:8081 auth-url: http://localhost:18080/auth/realms/camunda-platform/protocol/openid-connect/token audience: operate-api client-id: client-secret: scope: # optional resource: # optional client-assertion-keystore-path: # optional client-assertion-keystore-password: # optional client-assertion-keystore-key-alias: # optional client-assertion-keystore-key-password: # optionalThe
operate.client.client-assertion-keystore-*properties are intended to be used forclient_assertionauthentication via oidc. If this is used, nooperate.client.client-secretneeds to be provided.
Configure a Camunda Operate client for Saas:
operate: client: profile: saas region: cluster-id: client-id: client-secret:To adjust the (meaningful) default properties, you can also override them:
operate: client: profile: saas enabled: true base-url: https://${operate.client.region}.operate.camunda.io/${operate.client.cluster-id} auth-url: https://login.cloud.camunda.io/oauth/token audience: operate.camunda.io region: cluster-id: client-id: client-secret:All configuration properties can also be set via environment variables using Spring Boot's standard naming convention. For example:
operate.client.resource→OPERATE_CLIENT_RESOURCEoperate.client.client-id→OPERATE_CLIENT_CLIENT_IDoperate.client.client-secret→OPERATE_CLIENT_CLIENT_SECRET
Add the dependency to your project:
<dependency> <groupId>io.camunda.spring</groupId> <artifactId>java-client-operate</artifactId> <version>${version.operate-client}</version> </dependency>Build a Camunda Operate client with simple authentication:
// properties you need to provide String username = "demo"; String password = "demo"; URL operateUrl = URI.create("http://localhost:8081").toURL(); // bootstrapping SimpleCredential credentials = new SimpleCredential(username, password, operateUrl, Duration.ofMinutes(10)); SimpleAuthentication authentication = new SimpleAuthentication(credentials); ObjectMapper objectMapper = new ObjectMapper(); CamundaOperateClientConfiguration configuration = new CamundaOperateClientConfiguration( authentication, operateUrl, objectMapper, HttpClients.createDefault()); CamundaOperateClient client = new CamundaOperateClientV1(configuration);Build a Camunda Operate client with identity authentication:
// properties you need to provide String clientId = ""; String clientSecret = ""; String audience = "operate-api"; String scope = ""; // can be omitted if not required URL operateUrl = URI.create("http://localhost:8081").toURL(); URL authUrl = URI.create( "http://localhost:18080/auth/realms/camunda-platform/protocol/openid-connect/token") .toURL(); // bootstrapping JwtCredential credentials = new JwtCredential(clientId, clientSecret, audience, authUrl, scope); ObjectMapper objectMapper = new ObjectMapper(); JwtAuthentication authentication = new JwtAuthentication(credentials); CamundaOperateClientConfiguration configuration = new CamundaOperateClientConfiguration( authentication, operateUrl, objectMapper, HttpClients.createDefault()); CamundaOperateClient client = new CamundaOperateClientV1(configuration);Note: The
JwtCredentialconstructor also supports an optionalresourceparameter. If you need to specify a resource in your OAuth2 token requests, you can use the extended constructor that includes the resource parameter.
Build a Camunda Operate client for Saas:
// properties you need to provide String region = ""; String clusterId = ""; String clientId = ""; String clientSecret = ""; // bootstrapping URL operateUrl = URI.create("https://" + region + ".operate.camunda.io/" + clusterId).toURL(); URL authUrl = URI.create("https://login.cloud.camunda.io/oauth/token").toURL(); JwtCredential credentials = new JwtCredential(clientId, clientSecret, "operate.camunda.io", authUrl, null); ObjectMapper objectMapper = new ObjectMapper(); JwtAuthentication authentication = new JwtAuthentication(credentials); CamundaOperateClientConfiguration configuration = new CamundaOperateClientConfiguration( authentication, operateUrl, objectMapper, HttpClients.createDefault()); CamundaOperateClient client = new CamundaOperateClientV1(configuration);When you search objects, you can get results as List or as SearchResult. The SearchResult gives you a sortValues that you can use to paginate your results :
SearchQuery query = SearchQuery.builder().filter(someFilter).sort(new Sort("name", SortOrder.ASC)).size(20).searchAfter(previousResult.getSortValues()).build();//Get a process definition by its key ProcessDefinition def = client.getProcessDefinition(1L); //Search process definitions ProcessDefinitionFilter processDefinitionFilter = ProcessDefinitionFilter.builder().name("Customer Onboarding").build(); SearchQuery<ProcessDefinition> procDefQuery = SearchQuery.<ProcessDefinition>builder().filter(processDefinitionFilter).size(20).sort(new Sort("version", SortOrder.ASC)).build(); List<ProcessDefinition> list = client.searchProcessDefinitions(procDefQuery); SearchResult<ProcessDefinition> result = client.searchProcessDefinitionResults(procDefQuery);//search process instances based on filters ProcessInstanceFilter instanceFilter = ProcessInstanceFilter.builder().bpmnProcessId("customer_onboarding_en").startDate(OperateDate.filter(new Date(), DateFilterRange.MONTH)).build(); SearchQuery<ProcessInstance> instanceQuery = SearchQuery.<ProcessInstance>builder().filter(instanceFilter).size(20).sort(new Sort("state", SortOrder.ASC)).build(); List<ProcessInstance> list = client.searchProcessInstances(instanceQuery); SearchResult<ProcessInstance> result = client.searchProcessInstanceResults(instanceQuery); //get a process instance by its key ProcessInstance instance = client.getProcessInstance(instances.get(0).getKey());A similar library is available for the Tasklist API of Camunda Platform 8 here: camunda-tasklist-client-java