}
if (destinationName == null) {
destinationName = endpoint.getDestinationName();
}
Destination destination = in.getHeader(JmsConstants.JMS_DESTINATION, Destination.class);
if (destination != null) {
// remove the header so it wont be propagated
in.removeHeader(JmsConstants.JMS_DESTINATION);
}
if (destination == null) {
destination = endpoint.getDestination();
}
if (destination != null) {
// prefer to use destination over destination name
destinationName = null;
}
final String to = destinationName != null ? destinationName : "" + destination;
MessageSentCallback messageSentCallback = getEndpoint().getConfiguration().isIncludeSentJMSMessageID()
? new InOnlyMessageSentCallback(exchange) : null;
MessageCreator messageCreator = new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
Message answer = endpoint.getBinding().makeJmsMessage(exchange, in, session, null);
// when in InOnly mode the JMSReplyTo is a bit complicated
// we only want to set the JMSReplyTo on the answer if
// there is a JMSReplyTo from the header/endpoint and
// we have been told to preserveMessageQos
Object jmsReplyTo = JmsMessageHelper.getJMSReplyTo(answer);
if (endpoint.isDisableReplyTo()) {
// honor disable reply to configuration
LOG.trace("ReplyTo is disabled on endpoint: {}", endpoint);
JmsMessageHelper.setJMSReplyTo(answer, null);
} else {
// if the binding did not create the reply to then we have to try to create it here
if (jmsReplyTo == null) {
// prefer reply to from header over endpoint configured
jmsReplyTo = exchange.getIn().getHeader("JMSReplyTo", String.class);
if (jmsReplyTo == null) {
jmsReplyTo = endpoint.getReplyTo();
}
}
}
// we must honor these special flags to preserve QoS
// as we are not OUT capable and thus do not expect a reply, and therefore
// the consumer of this message should not return a reply so we remove it
// unless we use preserveMessageQos=true to tell that we still want to use JMSReplyTo
if (jmsReplyTo != null && !(endpoint.isPreserveMessageQos() || endpoint.isExplicitQosEnabled())) {
// log at debug what we are doing, as higher level may cause noise in production logs
// this behavior is also documented at the camel website
if (LOG.isDebugEnabled()) {
LOG.debug("Disabling JMSReplyTo: {} for destination: {}. Use preserveMessageQos=true to force Camel to keep the JMSReplyTo on endpoint: {}",
new Object[]{jmsReplyTo, to, endpoint});
}
jmsReplyTo = null;
}
// the reply to is a String, so we need to look up its Destination instance
// and if needed create the destination using the session if needed to
if (jmsReplyTo != null && jmsReplyTo instanceof String) {
// must normalize the destination name
String before = (String) jmsReplyTo;
String replyTo = normalizeDestinationName(before);
// we need to null it as we use the String to resolve it as a Destination instance
jmsReplyTo = null;
LOG.trace("Normalized JMSReplyTo destination name {} -> {}", before, replyTo);
// try using destination resolver to lookup the destination
if (endpoint.getDestinationResolver() != null) {
jmsReplyTo = endpoint.getDestinationResolver().resolveDestinationName(session, replyTo, endpoint.isPubSubDomain());
if (LOG.isDebugEnabled()) {
LOG.debug("Resolved JMSReplyTo destination {} using DestinationResolver {} as PubSubDomain {} -> {}",
new Object[]{replyTo, endpoint.getDestinationResolver(), endpoint.isPubSubDomain(), jmsReplyTo});
}
}
if (jmsReplyTo == null) {
// okay then fallback and create the queue
if (endpoint.isPubSubDomain()) {
LOG.debug("Creating JMSReplyTo topic: {}", replyTo);
jmsReplyTo = session.createTopic(replyTo);
} else {
LOG.debug("Creating JMSReplyTo queue: {}", replyTo);
jmsReplyTo = session.createQueue(replyTo);
}
}
}
// set the JMSReplyTo on the answer if we are to use it
Destination replyTo = null;
if (jmsReplyTo instanceof Destination) {
replyTo = (Destination) jmsReplyTo;
}
if (replyTo != null) {
LOG.debug("Using JMSReplyTo destination: {}", replyTo);