}
JMSMessageHeadersType headers = (JMSMessageHeadersType)outMessage
.get(JMSConstants.JMS_CLIENT_REQUEST_HEADERS);
JmsTemplate jmsTemplate = JMSFactory.createJmsTemplate(jmsConfig, headers);
if (!exchange.isOneWay() && jmsListener == null) {
jmsListener = JMSFactory.createJmsListener(jmsConfig, this, jmsConfig.getReplyDestination());
}
final javax.jms.Destination replyTo = exchange.isOneWay() ? null : jmsListener.getDestination();
final String correlationId = (headers != null && headers.isSetJMSCorrelationID()) ? headers
.getJMSCorrelationID() : JMSUtils.generateCorrelationId();
MessageCreator messageCreator = new MessageCreator() {
public javax.jms.Message createMessage(Session session) throws JMSException {
String messageType = jmsConfig.getMessageType();
final javax.jms.Message jmsMessage;
jmsMessage = JMSUtils.buildJMSMessageFromCXFMessage(outMessage, request, messageType,
session, replyTo,
correlationId);
LOG.log(Level.FINE, "client sending request: ", jmsMessage);
return jmsMessage;
}
};
/**
* If the message is not oneWay we will expect to receive a reply on the listener. To receive this
* reply we add the correlationId and an empty CXF Message to the correlationMap. The listener will
* fill to Message and notify this thread
*/
if (!exchange.isOneWay()) {
Message inMessage = new MessageImpl();
synchronized (inMessage) {
correlationMap.put(correlationId, inMessage);
jmsTemplate.send(jmsConfig.getTargetDestination(), messageCreator);
try {
inMessage.wait(jmsTemplate.getReceiveTimeout());
} catch (InterruptedException e) {
correlationMap.remove(correlationId);
throw new RuntimeException(e);
}
correlationMap.remove(correlationId);
if (inMessage.getContent(InputStream.class) == null) {
throw new RuntimeException("Timeout receiving message with correlationId "
+ correlationId);
}
}
exchange.setInMessage(inMessage);
if (incomingObserver != null) {
incomingObserver.onMessage(inMessage);
}
} else {
jmsTemplate.send(jmsConfig.getTargetDestination(), messageCreator);
}
}