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