Search in sources :

Example 21 with ServiceResponse

use of org.kie.server.api.model.ServiceResponse 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 22 with ServiceResponse

use of org.kie.server.api.model.ServiceResponse 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 23 with ServiceResponse

use of org.kie.server.api.model.ServiceResponse in project droolsjbpm-integration by kiegroup.

the class UIServicesClientImpl method getTaskFormByTypeAsUser.

private String getTaskFormByTypeAsUser(String containerId, Long taskId, String language, String formType, boolean marshallContent, String userId) {
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<>();
        valuesMap.put(RestURI.CONTAINER_ID, containerId);
        valuesMap.put(RestURI.TASK_INSTANCE_ID, taskId);
        String userQuery = StringUtils.isEmpty(userId) ? "" : getUserQueryStr(userId);
        StringBuilder params = new StringBuilder(userQuery);
        if (params.length() == 0) {
            params.append("?");
        } else {
            params.append("&");
        }
        params.append("type=").append(formType);
        params.append("&marshallContent=").append(marshallContent);
        boolean filter = false;
        if (!StringUtils.isEmpty(language)) {
            params.append("&lang=").append(language);
            filter = true;
        }
        params.append("&filter=").append(filter);
        return makeHttpGetRequestAndCreateRawResponse(build(loadBalancer.getUrl(), FORM_URI + "/" + TASK_FORM_GET_URI, valuesMap) + params.toString());
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("FormService", "getFormDisplayTask", new Object[] { containerId, taskId, StringUtils.defaultString(userId), StringUtils.defaultString(language), !StringUtils.isEmpty(language), formType })));
        ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM-UI", containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        return response.getResult();
    }
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript)

Example 24 with ServiceResponse

use of org.kie.server.api.model.ServiceResponse in project droolsjbpm-integration by kiegroup.

the class UIServicesClientImpl method getProcessInstanceImage.

@Override
public String getProcessInstanceImage(String containerId, Long processInstanceId) {
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(RestURI.CONTAINER_ID, containerId);
        valuesMap.put(RestURI.PROCESS_INST_ID, processInstanceId);
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Accept", MediaType.APPLICATION_SVG_XML);
        return makeHttpGetRequestAndCreateRawResponse(build(loadBalancer.getUrl(), IMAGE_URI + "/" + PROCESS_INST_IMG_GET_URI, valuesMap), headers);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("ImageService", "getActiveProcessImage", new Object[] { containerId, processInstanceId })));
        ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM-UI", containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        return response.getResult();
    }
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript)

Example 25 with ServiceResponse

use of org.kie.server.api.model.ServiceResponse in project droolsjbpm-integration by kiegroup.

the class UserTaskServicesClientImpl method getTaskInstance.

@Override
public TaskInstance getTaskInstance(String containerId, Long taskId, boolean withInputs, boolean withOutputs, boolean withAssignments) {
    TaskInstance result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(TASK_INSTANCE_ID, taskId);
        StringBuilder queryString = new StringBuilder();
        queryString.append("?withInputData").append("=").append(withInputs).append("&withOutputData").append("=").append(withOutputs).append("&withAssignments").append("=").append(withAssignments);
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), TASK_URI + "/" + TASK_INSTANCE_GET_URI, valuesMap) + queryString.toString(), TaskInstance.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("UserTaskService", "getTask", marshaller.getFormat().getType(), new Object[] { containerId, taskId, withInputs, withOutputs, withAssignments })));
        ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM", containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = deserialize(response.getResult(), TaskInstance.class);
    }
    return result;
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) TaskInstance(org.kie.server.api.model.instance.TaskInstance) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript)

Aggregations

ServiceResponse (org.kie.server.api.model.ServiceResponse)315 CommandScript (org.kie.server.api.commands.CommandScript)269 KieServerCommand (org.kie.server.api.model.KieServerCommand)261 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)234 HashMap (java.util.HashMap)224 ArrayList (java.util.ArrayList)41 Wrapped (org.kie.server.api.model.Wrapped)32 ServiceResponsesList (org.kie.server.api.model.ServiceResponsesList)23 KieContainerResource (org.kie.server.api.model.KieContainerResource)18 ProcessInstanceList (org.kie.server.api.model.instance.ProcessInstanceList)18 TaskSummaryList (org.kie.server.api.model.instance.TaskSummaryList)17 NodeInstanceList (org.kie.server.api.model.instance.NodeInstanceList)15 Map (java.util.Map)13 Message (org.kie.server.api.model.Message)13 WebSocketServiceResponse (org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse)13 Test (org.junit.Test)11 List (java.util.List)9 ReleaseId (org.kie.server.api.model.ReleaseId)9 ProcessDefinitionList (org.kie.server.api.model.definition.ProcessDefinitionList)9 ExecutionErrorInstanceList (org.kie.server.api.model.admin.ExecutionErrorInstanceList)8