Search in sources :

Example 1 with ServiceResponsesList

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

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

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

the class JBPMUIKieContainerCommandServiceImpl method executeScript.

@Override
public ServiceResponsesList executeScript(CommandScript commands, MarshallingFormat marshallingFormat, String classType) {
    List<ServiceResponse<? extends Object>> responses = new ArrayList<ServiceResponse<? extends Object>>();
    for (KieServerCommand command : commands.getCommands()) {
        if (!(command instanceof DescriptorCommand)) {
            logger.warn("Unsupported command '{}' given, will not process it", command.getClass().getName());
            continue;
        }
        try {
            Object result = null;
            Object handler = null;
            DescriptorCommand descriptorCommand = (DescriptorCommand) command;
            // find out the handler to call to process given command
            if ("FormService".equals(descriptorCommand.getService())) {
                handler = formServiceBase;
            } else if ("ImageService".equals(descriptorCommand.getService())) {
                handler = imageServiceBase;
            } else if ("FormRendererService".equals(descriptorCommand.getService())) {
                handler = formRendererBase;
            } else {
                throw new IllegalStateException("Unable to find handler for " + descriptorCommand.getService() + " service");
            }
            List<Object> arguments = new ArrayList();
            // process and unwrap arguments
            for (Object arg : descriptorCommand.getArguments()) {
                logger.debug("Before :: Argument with type {} and value {}", arg.getClass(), arg);
                if (arg instanceof Wrapped) {
                    arg = ((Wrapped) arg).unwrap();
                }
                logger.debug("After :: Argument with type {} and value {}", arg.getClass(), arg);
                arguments.add(arg);
            }
            logger.debug("About to execute {} operation on {} with args {}", descriptorCommand.getMethod(), handler, arguments);
            // process command via reflection and handler
            result = MethodUtils.invokeMethod(handler, descriptorCommand.getMethod(), arguments.toArray());
            logger.debug("Handler {} returned response {}", handler, result);
            // return successful result
            responses.add(new ServiceResponse(ServiceResponse.ResponseType.SUCCESS, "", result));
        } catch (InvocationTargetException e) {
            responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, e.getTargetException().getMessage()));
        } catch (Throwable e) {
            logger.error("Error while processing {} command", command, e);
            // return failure result
            responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, e.getMessage()));
        }
    }
    logger.debug("About to return responses '{}'", responses);
    return new ServiceResponsesList(responses);
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) Wrapped(org.kie.server.api.model.Wrapped) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with ServiceResponsesList

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

the class AbstractKieServerImplTest method testManagementDisabledConfiguredViaCommandService.

@Test
public void testManagementDisabledConfiguredViaCommandService() {
    System.setProperty(KieServerConstants.KIE_SERVER_MGMT_API_DISABLED, "true");
    try {
        kieServer.destroy();
        kieServer = new KieServerImpl(new KieServerStateFileRepository(REPOSITORY_DIR));
        kieServer.init();
        KieContainerCommandServiceImpl commandService = new KieContainerCommandServiceImpl(kieServer, kieServer.getServerRegistry());
        List<KieServerCommand> commands = new ArrayList<>();
        commands.add(new CreateContainerCommand());
        commands.add(new DisposeContainerCommand());
        commands.add(new UpdateScannerCommand());
        commands.add(new UpdateReleaseIdCommand());
        CommandScript commandScript = new CommandScript(commands);
        ServiceResponsesList responseList = commandService.executeScript(commandScript, MarshallingFormat.JAXB, null);
        assertNotNull(responseList);
        List<ServiceResponse<?>> responses = responseList.getResponses();
        assertEquals(4, responses.size());
        for (ServiceResponse<?> forbidden : responses) {
            assertForbiddenResponse(forbidden);
        }
    } finally {
        System.clearProperty(KieServerConstants.KIE_SERVER_MGMT_API_DISABLED);
    }
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) KieServerStateFileRepository(org.kie.server.services.impl.storage.file.KieServerStateFileRepository) KieServerCommand(org.kie.server.api.model.KieServerCommand) ArrayList(java.util.ArrayList) CommandScript(org.kie.server.api.commands.CommandScript) DisposeContainerCommand(org.kie.server.api.commands.DisposeContainerCommand) UpdateReleaseIdCommand(org.kie.server.api.commands.UpdateReleaseIdCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServiceResponse(org.kie.server.api.model.KieServiceResponse) UpdateScannerCommand(org.kie.server.api.commands.UpdateScannerCommand) CreateContainerCommand(org.kie.server.api.commands.CreateContainerCommand) Test(org.junit.Test)

Example 5 with ServiceResponsesList

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

the class KieContainerCommandServiceImpl method executeScript.

@Override
public ServiceResponsesList executeScript(CommandScript commands, MarshallingFormat marshallingFormat, String classType) {
    List<ServiceResponse<? extends Object>> responses = new ArrayList<ServiceResponse<? extends Object>>();
    if (commands != null) {
        for (KieServerCommand command : commands.getCommands()) {
            if (command instanceof CreateContainerCommand) {
                ServiceResponse<?> forbidden = this.kieServer.checkAccessability();
                if (forbidden != null) {
                    logger.warn("Kie Server management api is disabled, skiping command execution {}", command);
                    responses.add(forbidden);
                    continue;
                }
                responses.add(this.kieServer.createContainer(((CreateContainerCommand) command).getContainer().getContainerId(), ((CreateContainerCommand) command).getContainer()));
            } else if (command instanceof GetServerInfoCommand) {
                responses.add(this.kieServer.getInfo());
            } else if (command instanceof ListContainersCommand) {
                responses.add(this.kieServer.listContainers(((ListContainersCommand) command).getKieContainerResourceFilter()));
            } else if (command instanceof CallContainerCommand) {
                ServiceResponse response = callContainer(((CallContainerCommand) command).getContainerId(), ((CallContainerCommand) command).getPayload(), marshallingFormat, classType, true);
                responses.add(response);
            } else if (command instanceof DisposeContainerCommand) {
                ServiceResponse<?> forbidden = this.kieServer.checkAccessability();
                if (forbidden != null) {
                    logger.warn("Kie Server management api is disabled, skiping command execution {}", command);
                    responses.add(forbidden);
                    continue;
                }
                responses.add(this.kieServer.disposeContainer(((DisposeContainerCommand) command).getContainerId()));
            } else if (command instanceof GetContainerInfoCommand) {
                responses.add(this.kieServer.getContainerInfo(((GetContainerInfoCommand) command).getContainerId()));
            } else if (command instanceof GetScannerInfoCommand) {
                responses.add(this.kieServer.getScannerInfo(((GetScannerInfoCommand) command).getContainerId()));
            } else if (command instanceof UpdateScannerCommand) {
                ServiceResponse<?> forbidden = this.kieServer.checkAccessability();
                if (forbidden != null) {
                    logger.warn("Kie Server management api is disabled, skiping command execution {}", command);
                    responses.add(forbidden);
                    continue;
                }
                responses.add(this.kieServer.updateScanner(((UpdateScannerCommand) command).getContainerId(), ((UpdateScannerCommand) command).getScanner()));
            } else if (command instanceof GetReleaseIdCommand) {
                responses.add(this.kieServer.getContainerReleaseId(((GetReleaseIdCommand) command).getContainerId()));
            } else if (command instanceof UpdateReleaseIdCommand) {
                ServiceResponse<?> forbidden = this.kieServer.checkAccessability();
                if (forbidden != null) {
                    logger.warn("Kie Server management api is disabled, skiping command execution {}", command);
                    responses.add(forbidden);
                    continue;
                }
                responses.add(this.kieServer.updateContainerReleaseId(((UpdateReleaseIdCommand) command).getContainerId(), ((UpdateReleaseIdCommand) command).getReleaseId(), ((UpdateReleaseIdCommand) command).isResetBeforeUpdate()));
            } else if (command instanceof GetServerStateCommand) {
                responses.add(this.kieServer.getServerState());
            } else if (command instanceof ActivateContainerCommand) {
                ServiceResponse<?> forbidden = this.kieServer.checkAccessability();
                if (forbidden != null) {
                    logger.warn("Kie Server management api is disabled, skiping command execution {}", command);
                    responses.add(forbidden);
                    continue;
                }
                responses.add(this.kieServer.activateContainer(((ActivateContainerCommand) command).getContainerId()));
            } else if (command instanceof DeactivateContainerCommand) {
                ServiceResponse<?> forbidden = this.kieServer.checkAccessability();
                if (forbidden != null) {
                    logger.warn("Kie Server management api is disabled, skiping command execution {}", command);
                    responses.add(forbidden);
                    continue;
                }
                responses.add(this.kieServer.deactivateContainer(((DeactivateContainerCommand) command).getContainerId()));
            }
        }
    }
    return new ServiceResponsesList(responses);
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) CallContainerCommand(org.kie.server.api.commands.CallContainerCommand) KieServerCommand(org.kie.server.api.model.KieServerCommand) ActivateContainerCommand(org.kie.server.api.commands.ActivateContainerCommand) ArrayList(java.util.ArrayList) DisposeContainerCommand(org.kie.server.api.commands.DisposeContainerCommand) DeactivateContainerCommand(org.kie.server.api.commands.DeactivateContainerCommand) GetContainerInfoCommand(org.kie.server.api.commands.GetContainerInfoCommand) GetReleaseIdCommand(org.kie.server.api.commands.GetReleaseIdCommand) UpdateReleaseIdCommand(org.kie.server.api.commands.UpdateReleaseIdCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) ListContainersCommand(org.kie.server.api.commands.ListContainersCommand) GetServerStateCommand(org.kie.server.api.commands.GetServerStateCommand) UpdateScannerCommand(org.kie.server.api.commands.UpdateScannerCommand) CreateContainerCommand(org.kie.server.api.commands.CreateContainerCommand) GetServerInfoCommand(org.kie.server.api.commands.GetServerInfoCommand) GetScannerInfoCommand(org.kie.server.api.commands.GetScannerInfoCommand)

Aggregations

ServiceResponsesList (org.kie.server.api.model.ServiceResponsesList)30 ServiceResponse (org.kie.server.api.model.ServiceResponse)23 KieServerCommand (org.kie.server.api.model.KieServerCommand)18 CommandScript (org.kie.server.api.commands.CommandScript)17 WebSocketServiceResponse (org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse)13 ArrayList (java.util.ArrayList)9 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)5 KieContainerResource (org.kie.server.api.model.KieContainerResource)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 JMSException (javax.jms.JMSException)4 CreateContainerCommand (org.kie.server.api.commands.CreateContainerCommand)4 DisposeContainerCommand (org.kie.server.api.commands.DisposeContainerCommand)4 Wrapped (org.kie.server.api.model.Wrapped)4 TextMessage (javax.jms.TextMessage)3 Test (org.junit.Test)3 UpdateReleaseIdCommand (org.kie.server.api.commands.UpdateReleaseIdCommand)3 UpdateScannerCommand (org.kie.server.api.commands.UpdateScannerCommand)3 KieServicesException (org.kie.server.api.exception.KieServicesException)3 ReleaseId (org.kie.server.api.model.ReleaseId)3 IOException (java.io.IOException)2