Search in sources :

Example 16 with KieServicesException

use of org.kie.server.api.exception.KieServicesException in project droolsjbpm-integration by kiegroup.

the class AbstractKieServicesClientImpl method executeJmsCommand.

protected ServiceResponsesList executeJmsCommand(CommandScript command, String classType, String targetCapability, String containerId) {
    ConnectionFactory factory = config.getConnectionFactory();
    Queue sendQueue = config.getRequestQueue();
    Queue responseQueue = config.getResponseQueue();
    Connection connection = null;
    Session session = null;
    ServiceResponsesList cmdResponse = null;
    String corrId = UUID.randomUUID().toString();
    String selector = "JMSCorrelationID = '" + corrId + "'";
    try {
        // setup
        MessageProducer producer;
        try {
            if (config.getPassword() != null) {
                connection = factory.createConnection(config.getUserName(), config.getPassword());
            } else {
                connection = factory.createConnection();
            }
            session = connection.createSession(config.isJmsTransactional(), Session.AUTO_ACKNOWLEDGE);
            producer = session.createProducer(sendQueue);
            connection.start();
        } catch (JMSException jmse) {
            throw new KieServicesException("Unable to setup a JMS connection.", jmse);
        }
        // Create msg
        TextMessage textMsg;
        try {
            // serialize request
            String xmlStr = marshaller.marshall(command);
            logger.debug("Message content to be sent '{}'", xmlStr);
            textMsg = session.createTextMessage(xmlStr);
            // set properties
            // 1. corr id
            textMsg.setJMSCorrelationID(corrId);
            // 2. serialization info
            textMsg.setIntProperty(JMSConstants.SERIALIZATION_FORMAT_PROPERTY_NAME, config.getMarshallingFormat().getId());
            textMsg.setIntProperty(JMSConstants.INTERACTION_PATTERN_PROPERTY_NAME, responseHandler.getInteractionPattern());
            if (classType != null) {
                textMsg.setStringProperty(JMSConstants.CLASS_TYPE_PROPERTY_NAME, classType);
            }
            if (targetCapability != null) {
                textMsg.setStringProperty(JMSConstants.TARGET_CAPABILITY_PROPERTY_NAME, targetCapability);
            }
            textMsg.setStringProperty(JMSConstants.USER_PROPERTY_NAME, config.getUserName());
            textMsg.setStringProperty(JMSConstants.PASSWRD_PROPERTY_NAME, config.getPassword());
            if (containerId != null) {
                textMsg.setStringProperty(JMSConstants.CONTAINER_ID_PROPERTY_NAME, containerId);
            }
            if (owner.getConversationId() != null) {
                textMsg.setStringProperty(JMSConstants.CONVERSATION_ID_PROPERTY_NAME, owner.getConversationId());
            }
            if (config.getHeaders() != null) {
                for (Map.Entry<String, String> header : config.getHeaders().entrySet()) {
                    logger.debug("Adding additional property {} value {}", header.getKey(), header.getValue());
                    textMsg.setStringProperty(header.getKey(), header.getValue());
                }
            }
            // send
            producer.send(textMsg);
        } catch (JMSException jmse) {
            throw new KieServicesException("Unable to send a JMS message.", jmse);
        } finally {
            if (producer != null) {
                try {
                    producer.close();
                } catch (JMSException jmse) {
                    logger.warn("Unable to close producer!", jmse);
                }
            }
        }
        // receive
        cmdResponse = responseHandler.handleResponse(selector, connection, session, responseQueue, config, marshaller, owner);
        return cmdResponse;
    } finally {
        responseHandler.dispose(connection, session);
    }
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) ConnectionFactory(javax.jms.ConnectionFactory) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) HashMap(java.util.HashMap) Map(java.util.Map) KieServicesException(org.kie.server.api.exception.KieServicesException) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 17 with KieServicesException

use of org.kie.server.api.exception.KieServicesException in project droolsjbpm-integration by kiegroup.

the class RuntimeDataServiceIntegrationTest method testFindTaskEventsSortedByType.

@Test
public void testFindTaskEventsSortedByType() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("stringData", "waiting for signal");
    parameters.put("personData", createPersonInstance(USER_JOHN));
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK, parameters);
    try {
        List<TaskSummary> tasks = taskClient.findTasksByStatusByProcessInstanceId(processInstanceId, null, 0, 10);
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        TaskSummary taskInstance = tasks.get(0);
        // now let's start it
        taskClient.startTask(CONTAINER_ID, taskInstance.getId(), USER_YODA);
        // now let's stop it
        taskClient.stopTask(CONTAINER_ID, taskInstance.getId(), USER_YODA);
        // test paging of the result
        List<TaskEventInstance> events = taskClient.findTaskEvents(taskInstance.getId(), 0, 4, SORT_BY_TASK_EVENTS_TYPE, true);
        assertNotNull(events);
        assertEquals(4, events.size());
        TaskEventInstance event = events.get(0);
        assertNotNull(event);
        assertEquals(taskInstance.getId(), event.getTaskId());
        assertEquals(TaskEvent.TaskEventType.ACTIVATED.toString(), event.getType());
        event = events.get(1);
        assertNotNull(event);
        assertEquals(taskInstance.getId(), event.getTaskId());
        assertEquals(TaskEvent.TaskEventType.ADDED.toString(), event.getType());
        event = events.get(2);
        assertNotNull(event);
        assertEquals(taskInstance.getId(), event.getTaskId());
        assertEquals(TaskEvent.TaskEventType.STARTED.toString(), event.getType());
        event = events.get(3);
        assertNotNull(event);
        assertEquals(taskInstance.getId(), event.getTaskId());
        assertEquals(TaskEvent.TaskEventType.STOPPED.toString(), event.getType());
        try {
            events = taskClient.findTaskEvents(taskInstance.getId(), 2, 3, SORT_BY_TASK_EVENTS_TYPE, true);
            KieServerAssert.assertNullOrEmpty("Task events list is not empty.", events);
        } catch (KieServicesException ee) {
            if (configuration.isRest()) {
                KieServerAssert.assertResultContainsString(ee.getMessage(), "Could not find task instance with id " + taskInstance.getId());
                KieServicesHttpException httpEx = (KieServicesHttpException) ee;
                assertEquals(Integer.valueOf(404), httpEx.getHttpCode());
            } else {
                assertTrue(ee.getMessage().contains("No task found with id " + taskInstance.getId()));
            }
        }
        events = taskClient.findTaskEvents(taskInstance.getId(), 0, 10, SORT_BY_TASK_EVENTS_TYPE, false);
        assertNotNull(events);
        assertEquals(4, events.size());
        event = events.get(0);
        assertNotNull(event);
        assertEquals(taskInstance.getId(), event.getTaskId());
        assertEquals(TaskEvent.TaskEventType.STOPPED.toString(), event.getType());
        event = events.get(1);
        assertNotNull(event);
        assertEquals(taskInstance.getId(), event.getTaskId());
        assertEquals(TaskEvent.TaskEventType.STARTED.toString(), event.getType());
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
    }
}
Also used : KieServicesHttpException(org.kie.server.api.exception.KieServicesHttpException) HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) KieServicesException(org.kie.server.api.exception.KieServicesException) TaskEventInstance(org.kie.server.api.model.instance.TaskEventInstance) Test(org.junit.Test)

Example 18 with KieServicesException

use of org.kie.server.api.exception.KieServicesException in project droolsjbpm-integration by kiegroup.

the class QueryDataServiceIntegrationTest method testInvalidQuery.

@Test
public void testInvalidQuery() {
    QueryDefinition query = new QueryDefinition();
    query.setName("invalidQuery");
    query.setSource(System.getProperty("org.kie.server.persistence.ds", "jdbc/jbpm-ds"));
    query.setExpression("this is an invalid query");
    query.setTarget("CUSTOM");
    try {
        assertClientException(() -> queryClient.registerQuery(query), 500, "Can't get metadata on specified data set: invalidQuery");
        assertClientException(() -> queryClient.getQuery(query.getName()), 404, "Could not find query definition with name \"" + query.getName() + "\"", "Query invalidQuery not found");
    } catch (Throwable e) {
        try {
            queryClient.unregisterQuery(query.getName());
        } catch (KieServicesException ex) {
        // expected in case the query wasn't registered
        }
        throw e;
    }
}
Also used : QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) KieServicesException(org.kie.server.api.exception.KieServicesException) Test(org.junit.Test)

Example 19 with KieServicesException

use of org.kie.server.api.exception.KieServicesException in project droolsjbpm-integration by kiegroup.

the class QueryDataServiceIntegrationTest method testErrorHandlingFailedToSignal.

@Test
public void testErrorHandlingFailedToSignal() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("nullAccepted", false);
    QueryDefinition query = createErrorsQueryDefinition();
    Long processInstanceId = null;
    try {
        queryClient.registerQuery(query);
        processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_SIGNAL_PROCESS, parameters);
        List<ExecutionErrorInstance> errors = processAdminClient.getErrorsByProcessInstance(CONTAINER_ID, processInstanceId, false, 0, 10);
        assertNotNull(errors);
        assertEquals(0, errors.size());
        try {
            processClient.signalProcessInstance(CONTAINER_ID, processInstanceId, "Signal1", null);
            fail("Process instance signal should fail as it provides null as event");
        } catch (KieServicesException e) {
        // expected
        }
        errors = queryClient.query(query.getName(), QueryServicesClient.QUERY_MAP_ERROR, 0, 10, ExecutionErrorInstance.class);
        errors = filterErrorsByProcessInstanceId(errors, processInstanceId);
        assertNotNull(errors);
        assertEquals(1, errors.size());
        ExecutionErrorInstance errorInstance = errors.get(0);
        assertNotNull(errorInstance.getErrorId());
        assertNull(errorInstance.getError());
        assertNotNull(errorInstance.getProcessInstanceId());
        assertNotNull(errorInstance.getActivityId());
        assertNotNull(errorInstance.getErrorDate());
        assertEquals(CONTAINER_ID, errorInstance.getContainerId());
        assertEquals(PROCESS_ID_SIGNAL_PROCESS, errorInstance.getProcessId());
        assertEquals("Signal 1 data", errorInstance.getActivityName());
        assertFalse(errorInstance.isAcknowledged());
        assertNull(errorInstance.getAcknowledgedAt());
        assertNull(errorInstance.getAcknowledgedBy());
        errors = processAdminClient.getErrorsByProcessInstanceAndNode(CONTAINER_ID, processInstanceId, "Signal 1 data", false, 0, 10);
        assertNotNull(errors);
        assertEquals(1, errors.size());
        ExecutionErrorInstance errorInstance2 = errors.get(0);
        assertEquals(errorInstance.getErrorId(), errorInstance2.getErrorId());
        processAdminClient.acknowledgeError(CONTAINER_ID, errorInstance.getErrorId());
        errors = processAdminClient.getErrorsByProcessInstance(CONTAINER_ID, processInstanceId, false, 0, 10);
        assertNotNull(errors);
        assertEquals(0, errors.size());
        errorInstance = processAdminClient.getError(CONTAINER_ID, errorInstance.getErrorId());
        assertNotNull(errorInstance);
        assertNotNull(errorInstance.getErrorId());
        assertTrue(errorInstance.isAcknowledged());
        assertNotNull(errorInstance.getAcknowledgedAt());
        assertEquals(USER_YODA, errorInstance.getAcknowledgedBy());
    } catch (Exception e) {
        logger.error("Unexpected error", e);
        fail(e.getMessage());
    } finally {
        queryClient.unregisterQuery(query.getName());
        if (processInstanceId != null) {
            processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        }
    }
}
Also used : QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) HashMap(java.util.HashMap) KieServicesException(org.kie.server.api.exception.KieServicesException) KieServicesException(org.kie.server.api.exception.KieServicesException) ExecutionErrorInstance(org.kie.server.api.model.admin.ExecutionErrorInstance) Test(org.junit.Test)

Example 20 with KieServicesException

use of org.kie.server.api.exception.KieServicesException in project droolsjbpm-integration by kiegroup.

the class ProcessInstanceAdminServiceIntegrationTest method testErrorHandlingFailedToStart.

@Test
public void testErrorHandlingFailedToStart() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("timer", "invalid value");
    try {
        processClient.startProcess(CONTAINER_ID, PROCESS_ID_TIMER, parameters);
        fail("Process instance should fail as it has invalid timer expression");
    } catch (KieServicesException e) {
    // expected as the variable to configure timer duration is invalid
    }
    List<ExecutionErrorInstance> errors = processAdminClient.getErrors(CONTAINER_ID, false, 0, 10);
    errors = filterErrorsByProcessId(errors, PROCESS_ID_TIMER);
    assertNotNull(errors);
    assertEquals(1, errors.size());
    ExecutionErrorInstance errorInstance = errors.get(0);
    assertNotNull(errorInstance.getErrorId());
    assertNull(errorInstance.getError());
    assertNotNull(errorInstance.getProcessInstanceId());
    assertNotNull(errorInstance.getActivityId());
    assertNotNull(errorInstance.getErrorDate());
    assertEquals(CONTAINER_ID, errorInstance.getContainerId());
    assertEquals(PROCESS_ID_TIMER, errorInstance.getProcessId());
    assertEquals("timer", errorInstance.getActivityName());
    assertFalse(errorInstance.isAcknowledged());
    assertNull(errorInstance.getAcknowledgedAt());
    assertNull(errorInstance.getAcknowledgedBy());
    processAdminClient.acknowledgeError(CONTAINER_ID, errorInstance.getErrorId());
    errors = processAdminClient.getErrors(CONTAINER_ID, false, 0, 10);
    errors = filterErrorsByProcessId(errors, PROCESS_ID_TIMER);
    assertNotNull(errors);
    assertEquals(0, errors.size());
    errorInstance = processAdminClient.getError(CONTAINER_ID, errorInstance.getErrorId());
    assertNotNull(errorInstance);
    assertNotNull(errorInstance.getErrorId());
    assertTrue(errorInstance.isAcknowledged());
    assertNotNull(errorInstance.getAcknowledgedAt());
    assertEquals(USER_YODA, errorInstance.getAcknowledgedBy());
}
Also used : HashMap(java.util.HashMap) KieServicesException(org.kie.server.api.exception.KieServicesException) ExecutionErrorInstance(org.kie.server.api.model.admin.ExecutionErrorInstance) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Aggregations

KieServicesException (org.kie.server.api.exception.KieServicesException)28 Test (org.junit.Test)19 HashMap (java.util.HashMap)14 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)9 TaskSummary (org.kie.server.api.model.instance.TaskSummary)8 ArrayList (java.util.ArrayList)6 ExecutionErrorInstance (org.kie.server.api.model.admin.ExecutionErrorInstance)5 MigrationReportInstance (org.kie.server.api.model.admin.MigrationReportInstance)4 Map (java.util.Map)3 JMSException (javax.jms.JMSException)3 KieServicesHttpException (org.kie.server.api.exception.KieServicesHttpException)3 ServiceResponse (org.kie.server.api.model.ServiceResponse)3 ServiceResponsesList (org.kie.server.api.model.ServiceResponsesList)3 MessageConsumer (javax.jms.MessageConsumer)2 TextMessage (javax.jms.TextMessage)2 Category (org.junit.experimental.categories.Category)2 QueryDefinition (org.kie.server.api.model.definition.QueryDefinition)2 DocumentInstance (org.kie.server.api.model.instance.DocumentInstance)2 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)2 SolverInstance (org.kie.server.api.model.instance.SolverInstance)2