Hi,
I want to send rest messages from a separate webapplication to camunda via http://localhost:8080/engine-rest/message ).
At the camunda side I have an message intermediate catch event.
I first tried it with postman with the following code and it works.
Now I try it from my webapplication.
public void sendToProcessTool(Thesis thesis) {
try {
String url = "http://localhost:8080/engine-rest/message";
Client restclient = ClientBuilder.newClient();
WebTarget target = restclient.target(url);
MessageDTO messageDTO = new MessageDTO();
messageDTO.businessKey = entity.getProcessInstanceId();
messageDTO.messageName = "permissionCheckedSecretariat_WS";
ProcessVariables processVariables = new ProcessVariables();
processVariables.secPermissionResult = PermissionResult.APPROVED;
messageDTO.processVariables = processVariables;
Entity e = Entity.json(messageDTO);
Response response = target.request().post(Entity.json(messageDTO));
String responseString = response.readEntity(String.class);
response.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
…
class MessageDTO {
String messageName;
String businessKey;
public String getMessageName() {
return messageName;
}
public void setMessageName(String messageName) {
this.messageName = messageName;
}
public String getBusinessKey() {
return businessKey;
}
public void setBusinessKey(String businessKey) {
this.businessKey = businessKey;
}
public ProcessVariables getProcessVariables() {
return processVariables;
}
public void setProcessVariables(ProcessVariables processVariables) {
this.processVariables = processVariables;
}
ProcessVariables processVariables;
}
class ProcessVariables {
PermissionResult secPermissionResult;
public PermissionResult getSecPermissionResult() {
return secPermissionResult;
}
public void setSecPermissionResult(PermissionResult secPermissionResult) {
this.secPermissionResult = secPermissionResult;
}
}
But then I get a “Bad Request”:
InboundJaxrsResponse{context=ClientResponse{method=POST, uri=http://localhost:8080/engine-rest/message, status=400, reason=Bad Request}}
Here are my variables:
I cant see any errors. Do you have any ideas?
Thank you a lot,
Nicole
Hi @NickiMueller ,
It looks like you are using Java language so I suggest you use the Camunda Engine REST Client which makes life much easier
Add the below dependency to your web app
<dependency>
<groupId>org.camunda.community</groupId>
<artifactId>camunda-engine-rest-client-openapi-java</artifactId>
<version>7.17.0</version>
</dependency>
Kindly find below an example of message correlation
ApiClient client;
MessageApi messageApi;
CorrelationMessageDto correlationMsgDto;
VariableValueDto variableValue;
Map < String, VariableValueDto > colVariables;
try {
client = new ApiClient();
// messageApi
messageApi = new MessageApi(client);
correlationMsgDto = new CorrelationMessageDto();
correlationMsgDto.businessKey("001");
correlationMsgDto.messageName("final-approval-msg");
colVariables = new HashMap < String,
VariableValueDto > ();
variableValue = new VariableValueDto();
variableValue.setValue(true);
colVariables.put("approved", variableValue);
correlationMsgDto.setProcessVariables(colVariables);
messageApi.deliverMessage(correlationMsgDto);
} catch (Exception e) {
System.out.print("e: " + e.getMessage());
}
2 Likes
Hi @hassang ,
thank you for the client. I solved my problem in another way, but I think I will try this client anyway.
Regards, Nicole
If there is a need to specify a different base path than the default one “http://localhost:8080/engine-rest ” then you can do as follow
new ApiClient().setBasePath("http://localhost:8080/engine-rest")
1 Like
hassang:
approved
Hi @hassang ,
I tested the client and it works with my webapplication. But I have one question.
In my versions before, I sent a REST-Call via Postman and with this request I set processVariables like:
{
"messageName" : "permissionCheckedSecretariat_WS",
"businessKey" : "28162903-d1d6-11ec-a8e9-a434d96233af",
"processVariables" : {
"secPermissionResult" : {"value" : "approved"}
}
So in my EJB thats corrensponds to my camunda application I had access to the processVariables via “delegateExecution”-Object like this:
public boolean isSecPermissionResultApprovedFromMessage (DelegateExecution delegateExecution) {
Map<String, Object> variables = delegateExecution.getVariables();
secPermissionResult =(String) variables.get("secPermissionResult");
if(secPermissionResult.equals("approved")) {
return true;
}
else return false;
}
How can I now set variables in the delegateExecution Object with the REST-Client? I tried the following but that does not work.
client = new ApiClient();
// messageApi
messageApi = new MessageApi(client);
correlationMsgDto = new CorrelationMessageDto();
correlationMsgDto.businessKey("xyz");
correlationMsgDto.messageName("permissionCheckedSecretariat_WS");
colVariables = new HashMap<String, VariableValueDto>();
variableValue = new VariableValueDto();
variableValue.setType("string");
variableValue.setValue("denied");
colVariables.put("secPermissionResult", variableValue);
correlationMsgDto.setProcessVariables(colVariables);
Another way would be to read out the colVariables-Object in my ejb, but I do not know how to do this.
Thank you a lot for your help,
Nicole
Hi @NickiMueller ,
Did you check from Cockpit whether the variable has been created or not?
I believe it should be created once deliverMessage
method gets called.