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);
}
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);
}
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));
}
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());
}
}
}
}
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;
}
Aggregations