Search in sources :

Example 1 with KieServicesException

use of org.kie.server.api.exception.KieServicesException in project kie-wb-common by kiegroup.

the class DefaultWorkbenchErrorCallback method processQueue.

public void processQueue() {
    Throwable throwable = queue.peek();
    if (throwable == null) {
        return;
    }
    if (isServerOfflineException(throwable)) {
        final YesNoCancelPopup result = YesNoCancelPopup.newYesNoCancelPopup(DefaultWorkbenchConstants.INSTANCE.DisconnectedFromServer(), DefaultWorkbenchConstants.INSTANCE.CouldNotConnectToServer(), Window.Location::reload, null, this::dequeue);
        result.clearScrollHeight();
        result.show();
        return;
    }
    if (isInvalidBusContentException(throwable)) {
        final YesNoCancelPopup result = YesNoCancelPopup.newYesNoCancelPopup(DefaultWorkbenchConstants.INSTANCE.SessionTimeout(), DefaultWorkbenchConstants.INSTANCE.InvalidBusResponseProbablySessionTimeout(), Window.Location::reload, null, this::dequeue);
        result.clearScrollHeight();
        result.show();
        return;
    }
    if (isKieServerForbiddenException(throwable)) {
        ErrorPopup.showMessage(DefaultWorkbenchConstants.INSTANCE.KieServerError403(), () -> {
        }, this::dequeue);
        return;
    }
    if (isKieServerUnauthorizedException(throwable)) {
        ErrorPopup.showMessage(DefaultWorkbenchConstants.INSTANCE.KieServerError401(), () -> {
        }, this::dequeue);
        return;
    }
    if (throwable instanceof DataSetLookupException) {
        DataSetLookupException ex = (DataSetLookupException) throwable;
        ErrorPopup.showMessage(CommonConstants.INSTANCE.ExceptionGeneric0(ex.getCause() == null ? ex.getMessage() : ex.getCause().getMessage()), () -> {
        }, this::dequeue);
        return;
    }
    if (throwable instanceof KieServicesHttpException) {
        KieServicesHttpException ex = (KieServicesHttpException) throwable;
        ErrorPopup.showMessage(CommonConstants.INSTANCE.ExceptionGeneric0(ex.getExceptionMessage()), () -> {
        }, this::dequeue);
        return;
    }
    if (throwable instanceof KieServicesException) {
        KieServicesException ex = (KieServicesException) throwable;
        ErrorPopup.showMessage(CommonConstants.INSTANCE.ExceptionGeneric0(ex.getCause() == null ? ex.getMessage() : ex.getCause().getMessage()), () -> {
        }, this::dequeue);
        return;
    }
    handleGenericError(throwable);
}
Also used : KieServicesHttpException(org.kie.server.api.exception.KieServicesHttpException) DataSetLookupException(org.dashbuilder.dataset.exception.DataSetLookupException) YesNoCancelPopup(org.uberfire.ext.widgets.common.client.common.popups.YesNoCancelPopup) KieServicesException(org.kie.server.api.exception.KieServicesException)

Example 2 with KieServicesException

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

the class RemoteBusinessRuleTaskHandler method executeWorkItem.

@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
    Map<String, Object> parameters = new HashMap<>(workItem.getParameters());
    String containerId = (String) parameters.remove("ContainerId");
    if (containerId == null || containerId.isEmpty()) {
        throw new IllegalArgumentException("Container ID is required for remote BusinessRuleTask");
    }
    String language = (String) parameters.remove("Language");
    if (language == null) {
        language = DRL_LANG;
    }
    String kieSessionName = (String) parameters.remove("KieSessionName");
    // remove engine specific parameters
    parameters.remove("TaskName");
    parameters.remove("KieSessionType");
    Map<String, Object> results = new HashMap<>();
    logger.debug("Facts to be inserted into working memory {}", parameters);
    if (DRL_LANG.equalsIgnoreCase(language)) {
        RuleServicesClient ruleClient = client.getServicesClient(RuleServicesClient.class);
        List<Command<?>> commands = new ArrayList<Command<?>>();
        BatchExecutionCommand executionCommand = commandsFactory.newBatchExecution(commands, kieSessionName);
        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
            String inputKey = workItem.getId() + "_" + entry.getKey();
            commands.add(commandsFactory.newInsert(entry.getValue(), inputKey, true, null));
        }
        commands.add(commandsFactory.newFireAllRules("Fired"));
        ServiceResponse<ExecutionResults> reply = ruleClient.executeCommandsWithResults(containerId, executionCommand);
        if (ServiceResponse.ResponseType.FAILURE.equals(reply.getType())) {
            throw new KieServicesException(reply.getMsg());
        }
        ExecutionResults executionResults = reply.getResult();
        logger.debug("{} rules fired", executionResults.getValue("Fired"));
        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
            String inputKey = workItem.getId() + "_" + entry.getKey();
            String key = entry.getKey().replaceAll(workItem.getId() + "_", "");
            results.put(key, executionResults.getValue(inputKey));
        }
    } else if (DMN_LANG.equalsIgnoreCase(language)) {
        String namespace = (String) parameters.remove("Namespace");
        String model = (String) parameters.remove("Model");
        String decision = (String) parameters.remove("Decision");
        DMNServicesClient dmnClient = client.getServicesClient(DMNServicesClient.class);
        DMNContext dmnContext = dmnClient.newContext();
        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
            dmnContext.set(entry.getKey(), entry.getValue());
        }
        ServiceResponse<DMNResult> evaluationResult = null;
        if (decision != null) {
            evaluationResult = dmnClient.evaluateDecisionByName(containerId, namespace, model, decision, dmnContext);
        } else {
            evaluationResult = dmnClient.evaluateAll(containerId, namespace, model, dmnContext);
        }
        DMNResult dmnResult = evaluationResult.getResult();
        results.putAll(dmnResult.getContext().getAll());
    } else {
        throw new IllegalArgumentException("Not supported language type " + language);
    }
    logger.debug("Facts retrieved from working memory {}", results);
    workItemManager.completeWorkItem(workItem.getId(), results);
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNServicesClient(org.kie.server.client.DMNServicesClient) HashMap(java.util.HashMap) ExecutionResults(org.kie.api.runtime.ExecutionResults) ArrayList(java.util.ArrayList) DMNContext(org.kie.dmn.api.core.DMNContext) RuleServicesClient(org.kie.server.client.RuleServicesClient) ServiceResponse(org.kie.server.api.model.ServiceResponse) Command(org.kie.api.command.Command) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) HashMap(java.util.HashMap) Map(java.util.Map) KieServicesException(org.kie.server.api.exception.KieServicesException)

Example 3 with KieServicesException

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

the class AsyncResponseHandler method handleResponse.

@Override
public ServiceResponsesList handleResponse(String selector, Connection connection, Session session, Queue responseQueue, KieServicesConfiguration config, Marshaller marshaller, KieServicesClient owner) {
    if (callback == null) {
        throw new IllegalStateException("There is no callback defined, can't continue...");
    }
    MessageConsumer consumer = null;
    try {
        consumer = session.createConsumer(responseQueue, selector);
        consumer.setMessageListener(new AsyncMessageListener(connection, session, selector, consumer, marshaller, owner));
        logger.debug("Message listener for async message retrieval successfully registered on consumer {}", consumer);
    } catch (JMSException jmse) {
        throw new KieServicesException("Unable to retrieve JMS response from queue " + responseQueue + " with selector " + selector, jmse);
    }
    ServiceResponse messageSentResponse = new ServiceResponse(ServiceResponse.ResponseType.NO_RESPONSE, "Message sent");
    return new ServiceResponsesList(Arrays.asList(messageSentResponse));
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) MessageConsumer(javax.jms.MessageConsumer) ServiceResponse(org.kie.server.api.model.ServiceResponse) JMSException(javax.jms.JMSException) KieServicesException(org.kie.server.api.exception.KieServicesException)

Example 4 with KieServicesException

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

the class RequestReplyResponseHandler method handleResponse.

@Override
public ServiceResponsesList handleResponse(String selector, Connection connection, Session session, Queue responseQueue, KieServicesConfiguration config, Marshaller marshaller, KieServicesClient owner) {
    MessageConsumer consumer = null;
    try {
        consumer = session.createConsumer(responseQueue, selector);
        Message response = consumer.receive(config.getTimeout());
        if (response == null) {
            logger.warn("Response is empty");
            // return actual instance to avoid null points on client side
            List<ServiceResponse<? extends Object>> responses = new ArrayList<ServiceResponse<? extends Object>>();
            responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, "Response is empty"));
            return new ServiceResponsesList(responses);
        }
        ((KieServicesClientImpl) owner).setConversationId(response.getStringProperty(JMSConstants.CONVERSATION_ID_PROPERTY_NAME));
        String responseStr = ((TextMessage) response).getText();
        logger.debug("Received response from server '{}'", responseStr);
        ServiceResponsesList cmdResponse = marshaller.unmarshall(responseStr, ServiceResponsesList.class);
        return cmdResponse;
    } catch (JMSException jmse) {
        throw new KieServicesException("Unable to retrieve JMS response from queue " + responseQueue + " with selector " + selector, jmse);
    } finally {
        if (consumer != null) {
            try {
                consumer.close();
            } catch (JMSException e) {
                logger.warn("Error when closing JMS consumer due to {}", e.getMessage());
            }
        }
    }
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) MessageConsumer(javax.jms.MessageConsumer) ServiceResponse(org.kie.server.api.model.ServiceResponse) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) ArrayList(java.util.ArrayList) KieServicesClientImpl(org.kie.server.client.impl.KieServicesClientImpl) JMSException(javax.jms.JMSException) TextMessage(javax.jms.TextMessage) KieServicesException(org.kie.server.api.exception.KieServicesException)

Example 5 with KieServicesException

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

the class TaskAssigningRuntimeKieServerExtension method init.

@Override
public void init(KieServerImpl kieServer, KieServerRegistry registry) {
    this.registry = registry;
    // JAXB and JSON required.
    registry.getExtraClasses().add(LocalDateTimeValue.class);
    KieServerExtension jbpmExtension = registry.getServerExtension(JbpmKieServerExtension.EXTENSION_NAME);
    if (jbpmExtension == null) {
        throw new KieServicesException(MISSING_REQUIRED_JBPM_EXTENSION_ERROR);
    }
    configureServices(kieServer, registry);
    services.add(taskAssigningRuntimeServiceBase);
    try {
        registerQueries();
    } catch (Exception e) {
        throw new KieServicesException(String.format(QUERIES_INITIALIZATION_ERROR, e.getMessage()), e);
    }
    initialized = true;
}
Also used : JbpmKieServerExtension(org.kie.server.services.jbpm.JbpmKieServerExtension) KieServerExtension(org.kie.server.services.api.KieServerExtension) KieServicesException(org.kie.server.api.exception.KieServicesException) KieServicesException(org.kie.server.api.exception.KieServicesException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

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