Starting process by Spring Boot Rest Client causing error 400

Hi @WGie welcome to the community.

Are you using a tomcat distro?
Also - are you able to reach the rest api through the browser?
If you make this call http://localhost:8080/engine-rest/engine you should get
[{"name":"default"}] back.

Hi @Niall, yes I am using tomcat distro. And I am able to reach the rest api through the browser- I made this call and get [{"name":"default"}] back.

Are you able to make the call successfully using postman or another rest client?

Yes I can, via Postman when I made POST call with the same url which is in the java code and empty json I get status ok 200

@WGie, check whether are you querying for process definitions with processDefinitionKey by using processDefinitionName or processDefinitionId.

Both (name and id) are WatchMunster. I also tried with /process-definition/WatchMunster/start and received the same error.
Edit. Sorry I’m wrong id is different but I tried it also and always the same result. I’m not sure, maybe I should set something in headers? But I tried few options and no changes :frowning:

I added my project to github maybe I have something wrong in my configuration :frowning:
Here is link: https://github.com/WojciechGie/ClaimBPMS
Thanks in advance for help

@WGie are you deploying in tomcat?

Yes I am deploying in tomcat.

@WGie, You need to fix the issues in your project, its not been properly setup.

  • If you are deploying tomcat server, why does your controller class implements command line runner? You can run as java application itself.

  • To deploy in tomcat, .war file should be generated when you run mvn clean install, but its not working.

I’m sorry, I misunderstood you, I’m running my project as a java application. (I have camunda tomcat distro). And when I run my application I get the error 400.

Can you provide more details about the command how you run the application with tomcat distro?

I have been downloaded camunda community. And I simply start it via bat file- I have an access in i.e. browser in url: http://localhost:8080/camunda, and then I start my project in Intelij as java application. If I good understand, in start it’s call the camunda for start the process. And I always have an exception: (IllegalStateException: Failed to execute CommandLineRunner)

	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:798) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:779) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at pl.wgie.ClaimBPMS.ClaimBpmsApplication.main(ClaimBpmsApplication.java:13) [classes/:na]
Caused by: org.springframework.web.client.HttpClientErrorException$BadRequest: 400 : [{"type":"InvalidRequestException","message":""}]
	at org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:101) ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:170) ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:112) ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63) ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:782) ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:740) ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:674) ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:583) ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at pl.wgie.ClaimBPMS.rest.CamundaRestController.callRestService(CamundaRestController.java:27) ~[classes/:na]
	at pl.wgie.ClaimBPMS.rest.CamundaRestController.run(CamundaRestController.java:33) ~[classes/:na]
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:795) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	... 5 common frames omitted ```

@aravindhrs, You are right, it was something wrong with my code I removed command line runner and change the code a little bit and it works. Thank you for help.

Hi @Niall, I have same type of issue when calling camunda services with REST API. The data sent with the body is not getting picked (Ex: to start a message-event we need to send the correlationKey and etc…).

I can send data with postman, unable to do the same with REST calls. My setup is
remote camunda engine,
rest api just to send the calls that we send with postman

Can you show in detail the call your making and the results you’re getting in the engine?

and I tried different implementations but non did worked.

URI : http://localhost:8080/engine-rest/message

	public void sendPayment(Payment payment) {

	try {

		HttpHeaders headers = new HttpHeaders();

		headers.set("Content-Type", "application/json");

		MessageBody b = new MessageBody("bizcare_pay_notification", "key-PR-5555",
				new CorrelationKeys("bizcare_pay_notification"), payment);

		ObjectMapper obj = new ObjectMapper();
		String json = obj.writeValueAsString(b);

		final String uri = CAMUNDA_ENGINE + "/message";
		RestTemplate restTemplate = new RestTemplate();

		HttpEntity<String> entity = new HttpEntity<>(json, headers);
		System.out.println(entity.getHeaders());
		System.out.println(entity.getBody());

		ResponseEntity<JsonNode> sth = restTemplate.postForEntity(uri, entity, JsonNode.class);
		System.out.println(sth);

	} catch (Exception e) {
		logger.error("Error occured " + e.getMessage());
	}
}

with postman, i get 204
but with rest, i get “400 : [{“type”:“InvalidRequestException”,“message”:”"}]"

Is there any doc that i can refer related this?