Search in sources :

Example 1 with MismatchingMessageCorrelationException

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);
}
Also used : HashMap(java.util.HashMap) RestException(org.camunda.bpm.engine.rest.exception.RestException) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.containsString(org.hamcrest.Matchers.containsString) MismatchingMessageCorrelationException(org.camunda.bpm.engine.MismatchingMessageCorrelationException) Test(org.junit.Test)

Example 2 with MismatchingMessageCorrelationException

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);
}
Also used : CorrelationHandler(org.camunda.bpm.engine.impl.runtime.CorrelationHandler) CorrelationSet(org.camunda.bpm.engine.impl.runtime.CorrelationSet) CorrelationHandlerResult(org.camunda.bpm.engine.impl.runtime.CorrelationHandlerResult) MismatchingMessageCorrelationException(org.camunda.bpm.engine.MismatchingMessageCorrelationException) MismatchingMessageCorrelationException(org.camunda.bpm.engine.MismatchingMessageCorrelationException)

Example 3 with MismatchingMessageCorrelationException

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);
}
Also used : MessageCorrelationResultDto(org.camunda.bpm.engine.rest.dto.message.MessageCorrelationResultDto) ArrayList(java.util.ArrayList) RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) MessageCorrelationBuilder(org.camunda.bpm.engine.runtime.MessageCorrelationBuilder) MessageCorrelationResult(org.camunda.bpm.engine.runtime.MessageCorrelationResult) MismatchingMessageCorrelationException(org.camunda.bpm.engine.MismatchingMessageCorrelationException)

Example 4 with MismatchingMessageCorrelationException

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;
    }
}
Also used : CorrelationHandler(org.camunda.bpm.engine.impl.runtime.CorrelationHandler) CorrelationSet(org.camunda.bpm.engine.impl.runtime.CorrelationSet) CorrelationHandlerResult(org.camunda.bpm.engine.impl.runtime.CorrelationHandlerResult) List(java.util.List) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) MismatchingMessageCorrelationException(org.camunda.bpm.engine.MismatchingMessageCorrelationException) MismatchingMessageCorrelationException(org.camunda.bpm.engine.MismatchingMessageCorrelationException)

Example 5 with MismatchingMessageCorrelationException

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);
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) MismatchingMessageCorrelationException(org.camunda.bpm.engine.MismatchingMessageCorrelationException) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

MismatchingMessageCorrelationException (org.camunda.bpm.engine.MismatchingMessageCorrelationException)7 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)3 Test (org.junit.Test)3 CorrelationHandler (org.camunda.bpm.engine.impl.runtime.CorrelationHandler)2 CorrelationHandlerResult (org.camunda.bpm.engine.impl.runtime.CorrelationHandlerResult)2 CorrelationSet (org.camunda.bpm.engine.impl.runtime.CorrelationSet)2 RestException (org.camunda.bpm.engine.rest.exception.RestException)2 Deployment (org.camunda.bpm.engine.test.Deployment)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)1 MessageCorrelationResultDto (org.camunda.bpm.engine.rest.dto.message.MessageCorrelationResultDto)1 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)1 EventSubscription (org.camunda.bpm.engine.runtime.EventSubscription)1 Execution (org.camunda.bpm.engine.runtime.Execution)1 MessageCorrelationBuilder (org.camunda.bpm.engine.runtime.MessageCorrelationBuilder)1 MessageCorrelationResult (org.camunda.bpm.engine.runtime.MessageCorrelationResult)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.anyString (org.mockito.Matchers.anyString)1