use of org.camunda.bpm.engine.MismatchingMessageCorrelationException in project camunda-bpm-platform by camunda.
the class MessageRestServiceTest method testMismatchingCorrelation.
@Test
public void testMismatchingCorrelation() {
String messageName = "aMessage";
doThrow(new MismatchingMessageCorrelationException(messageName, "Expected exception: cannot correlate")).when(messageCorrelationBuilderMock).correlateWithResult();
Map<String, Object> messageParameters = new HashMap<String, Object>();
messageParameters.put("messageName", messageName);
given().contentType(POST_JSON_CONTENT_TYPE).body(messageParameters).then().expect().statusCode(Status.BAD_REQUEST.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(RestException.class.getSimpleName())).body("message", containsString("Expected exception: cannot correlate")).when().post(MESSAGE_URL);
}
use of org.camunda.bpm.engine.MismatchingMessageCorrelationException in project camunda-bpm-platform by camunda.
the class CorrelateMessageCmd method execute.
public MessageCorrelationResult execute(final CommandContext commandContext) {
ensureAtLeastOneNotNull("At least one of the following correlation criteria has to be present: " + "messageName, businessKey, correlationKeys, processInstanceId", messageName, builder.getBusinessKey(), builder.getCorrelationProcessInstanceVariables(), builder.getProcessInstanceId());
final CorrelationHandler correlationHandler = Context.getProcessEngineConfiguration().getCorrelationHandler();
final CorrelationSet correlationSet = new CorrelationSet(builder);
CorrelationHandlerResult correlationResult = commandContext.runWithoutAuthorization(new Callable<CorrelationHandlerResult>() {
public CorrelationHandlerResult call() throws Exception {
return correlationHandler.correlateMessage(commandContext, messageName, correlationSet);
}
});
if (correlationResult == null) {
throw new MismatchingMessageCorrelationException(messageName, "No process definition or execution matches the parameters");
}
// check authorization
checkAuthorization(correlationResult);
return createMessageCorrelationResult(commandContext, correlationResult);
}
use of org.camunda.bpm.engine.MismatchingMessageCorrelationException in project camunda-bpm-platform by camunda.
the class MessageRestServiceImpl method deliverMessage.
@Override
public Response deliverMessage(CorrelationMessageDto messageDto) {
if (messageDto.getMessageName() == null) {
throw new InvalidRequestException(Status.BAD_REQUEST, "No message name supplied");
}
if (messageDto.getTenantId() != null && messageDto.isWithoutTenantId()) {
throw new InvalidRequestException(Status.BAD_REQUEST, "Parameter 'tenantId' cannot be used together with parameter 'withoutTenantId'.");
}
List<MessageCorrelationResultDto> resultDtos = new ArrayList<MessageCorrelationResultDto>();
try {
MessageCorrelationBuilder correlation = createMessageCorrelationBuilder(messageDto);
if (!messageDto.isAll()) {
MessageCorrelationResult result = correlation.correlateWithResult();
resultDtos.add(MessageCorrelationResultDto.fromMessageCorrelationResult(result));
} else {
List<MessageCorrelationResult> results = correlation.correlateAllWithResult();
for (MessageCorrelationResult result : results) {
resultDtos.add(MessageCorrelationResultDto.fromMessageCorrelationResult(result));
}
}
} catch (RestException e) {
String errorMessage = String.format("Cannot deliver message: %s", e.getMessage());
throw new InvalidRequestException(e.getStatus(), e, errorMessage);
} catch (MismatchingMessageCorrelationException e) {
throw new RestException(Status.BAD_REQUEST, e);
}
return createResponse(resultDtos, messageDto);
}
use of org.camunda.bpm.engine.MismatchingMessageCorrelationException in project camunda-bpm-platform by camunda.
the class CorrelateStartMessageCmd method execute.
public ProcessInstance execute(final CommandContext commandContext) {
ensureNotNull("messageName", messageName);
final CorrelationHandler correlationHandler = Context.getProcessEngineConfiguration().getCorrelationHandler();
final CorrelationSet correlationSet = new CorrelationSet(builder);
List<CorrelationHandlerResult> correlationResults = commandContext.runWithoutAuthorization(new Callable<List<CorrelationHandlerResult>>() {
public List<CorrelationHandlerResult> call() throws Exception {
return correlationHandler.correlateStartMessages(commandContext, messageName, correlationSet);
}
});
if (correlationResults.isEmpty()) {
throw new MismatchingMessageCorrelationException(messageName, "No process definition matches the parameters");
} else if (correlationResults.size() > 1) {
throw LOG.exceptionCorrelateMessageToSingleProcessDefinition(messageName, correlationResults.size(), correlationSet);
} else {
CorrelationHandlerResult correlationResult = correlationResults.get(0);
checkAuthorization(correlationResult);
ProcessInstance processInstance = instantiateProcess(commandContext, correlationResult);
return processInstance;
}
}
use of org.camunda.bpm.engine.MismatchingMessageCorrelationException in project camunda-bpm-platform by camunda.
the class MessageCorrelationTest method testCorrelationByProcessInstanceId.
@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/MessageCorrelationTest.testCatchingMessageEventCorrelation.bpmn20.xml")
@Test
public void testCorrelationByProcessInstanceId() {
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("process");
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("process");
// correlation with only the name is ambiguous:
try {
runtimeService.createMessageCorrelation("aMessageName").correlate();
fail("Expect an Exception");
} catch (MismatchingMessageCorrelationException e) {
testRule.assertTextPresent("Cannot correlate message", e.getMessage());
}
// use process instance id as well
runtimeService.createMessageCorrelation("newInvoiceMessage").processInstanceId(processInstance1.getId()).correlate();
Execution correlatedExecution = runtimeService.createExecutionQuery().activityId("task").processInstanceId(processInstance1.getId()).singleResult();
assertNotNull(correlatedExecution);
Execution uncorrelatedExecution = runtimeService.createExecutionQuery().activityId("task").processInstanceId(processInstance2.getId()).singleResult();
assertNull(uncorrelatedExecution);
runtimeService.deleteProcessInstance(processInstance1.getId(), null);
}
Aggregations