}
final JMSMessageHeadersType headers = (JMSMessageHeadersType)outMessage
.get(JMSConstants.JMS_CLIENT_REQUEST_HEADERS);
final JmsTemplate jmsTemplate = JMSFactory.createJmsTemplate(jmsConfig, headers);
String userCID = headers != null ? headers.getJMSCorrelationID() : null;
AbstractMessageListenerContainer jmsList = jmsListener;
if (!exchange.isOneWay()) {
if (userCID == null || !jmsConfig.isUseConduitIdSelector()) {
jmsList = getJMSListener();
} else {
jmsList = getAllListener();
}
}
final javax.jms.Destination replyTo = exchange.isOneWay() ? null : jmsList.getDestination();
final String correlationId = (headers != null && headers.isSetJMSCorrelationID())
? headers.getJMSCorrelationID()
: JMSUtils.createCorrelationId(jmsConfig.getConduitSelectorPrefix() + conduitId,
messageCount.incrementAndGet());
MessageCreator messageCreator = new MessageCreator() {
public javax.jms.Message createMessage(Session session) throws JMSException {
String messageType = jmsConfig.getMessageType();
final javax.jms.Message jmsMessage;
Destination replyToDestination = replyTo;
if (exchange.isOneWay() && !jmsConfig.isEnforceSpec() && isSetReplyTo(outMessage)) {
String replyToName = (headers != null) ? headers.getJMSReplyTo() : null;
if (replyToName == null && jmsConfig.getReplyDestination() != null) {
replyToName = jmsConfig.getReplyDestination();
}
if (replyToName != null) {
replyToDestination =
JMSFactory.resolveOrCreateDestination(jmsTemplate,
replyToName,
jmsConfig.isPubSubDomain());
}
}
jmsMessage = JMSUtils.buildJMSMessageFromCXFMessage(outMessage, request,
messageType, session, replyToDestination,
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()) {
synchronized (exchange) {
correlationMap.put(correlationId, exchange);
jmsTemplate.send(jmsConfig.getTargetDestination(), messageCreator);
if (exchange.isSynchronous()) {
try {
exchange.wait(jmsTemplate.getReceiveTimeout());
} catch (InterruptedException e) {
correlationMap.remove(correlationId);
throw new RuntimeException(e);
}
correlationMap.remove(correlationId);
if (exchange.get(CORRELATED) == null) {
throw new RuntimeException("Timeout receiving message with correlationId "
+ correlationId);
}
}
}
} else {
jmsTemplate.send(jmsConfig.getTargetDestination(), messageCreator);
}
}