Search in sources :

Example 1 with KieServicesClientImpl

use of org.kie.server.client.impl.KieServicesClientImpl 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)

Aggregations

ArrayList (java.util.ArrayList)1 JMSException (javax.jms.JMSException)1 Message (javax.jms.Message)1 MessageConsumer (javax.jms.MessageConsumer)1 TextMessage (javax.jms.TextMessage)1 KieServicesException (org.kie.server.api.exception.KieServicesException)1 ServiceResponse (org.kie.server.api.model.ServiceResponse)1 ServiceResponsesList (org.kie.server.api.model.ServiceResponsesList)1 KieServicesClientImpl (org.kie.server.client.impl.KieServicesClientImpl)1