Renamed JmsAttributeKeys to JmsHeaders and MailAttributeKeys to MailHeaders. JMS Headers are now propagated properly by the JmsGateway (INT-290).

This commit is contained in:
Mark Fisher
2008-08-19 17:32:48 +00:00
parent c00c13bdff
commit ce87fef7ac
11 changed files with 122 additions and 105 deletions

View File

@@ -48,19 +48,19 @@ public class DefaultJmsHeaderMapper implements MessageHeaderMapper<javax.jms.Mes
public void mapFromMessageHeaders(MessageHeaders headers, javax.jms.Message jmsMessage) {
try {
Object jmsCorrelationId = headers.get(JmsAttributeKeys.CORRELATION_ID);
Object jmsCorrelationId = headers.get(JmsHeaders.CORRELATION_ID);
if (jmsCorrelationId != null && (jmsCorrelationId instanceof String)) {
jmsMessage.setJMSCorrelationID((String) jmsCorrelationId);
}
Object jmsReplyTo = headers.get(JmsAttributeKeys.REPLY_TO);
Object jmsReplyTo = headers.get(JmsHeaders.REPLY_TO);
if (jmsReplyTo != null && (jmsReplyTo instanceof Destination)) {
jmsMessage.setJMSReplyTo((Destination) jmsReplyTo);
}
Object jmsType = headers.get(JmsAttributeKeys.TYPE);
Object jmsType = headers.get(JmsHeaders.TYPE);
if (jmsType != null && (jmsType instanceof String)) {
jmsMessage.setJMSType((String) jmsType);
}
String prefix = JmsAttributeKeys.USER_DEFINED_ATTRIBUTE_PREFIX;
String prefix = JmsHeaders.USER_PREFIX;
Set<String> attributeNames = headers.keySet();
for (String attributeName : attributeNames) {
if (attributeName.startsWith(prefix)) {
@@ -93,22 +93,22 @@ public class DefaultJmsHeaderMapper implements MessageHeaderMapper<javax.jms.Mes
try {
String correlationId = jmsMessage.getJMSCorrelationID();
if (correlationId != null) {
headers.put(JmsAttributeKeys.CORRELATION_ID, correlationId);
headers.put(JmsHeaders.CORRELATION_ID, correlationId);
}
Destination replyTo = jmsMessage.getJMSReplyTo();
if (replyTo != null) {
headers.put(JmsAttributeKeys.REPLY_TO, replyTo);
headers.put(JmsHeaders.REPLY_TO, replyTo);
}
headers.put(JmsAttributeKeys.REDELIVERED, jmsMessage.getJMSRedelivered());
headers.put(JmsHeaders.REDELIVERED, jmsMessage.getJMSRedelivered());
String type = jmsMessage.getJMSType();
if (type != null) {
headers.put(JmsAttributeKeys.TYPE, type);
headers.put(JmsHeaders.TYPE, type);
}
Enumeration<?> jmsPropertyNames = jmsMessage.getPropertyNames();
if (jmsPropertyNames != null) {
while (jmsPropertyNames.hasMoreElements()) {
String propertyName = jmsPropertyNames.nextElement().toString();
headers.put(JmsAttributeKeys.USER_DEFINED_ATTRIBUTE_PREFIX + propertyName,
headers.put(JmsHeaders.USER_PREFIX + propertyName,
jmsMessage.getObjectProperty(propertyName));
}
}

View File

@@ -1,37 +0,0 @@
/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.adapter.jms;
/**
* Keys to be used for setting and/or retrieving JMS attributes stored in the
* integration message header.
*
* @author Mark Fisher
*/
public abstract class JmsAttributeKeys {
public static final String USER_DEFINED_ATTRIBUTE_PREFIX = "jms.";
public static final String CORRELATION_ID = "_jms.JMSCorrelationID";
public static final String REPLY_TO = "_jms.JMSReplyTo";
public static final String REDELIVERED = "_jms.JMSRedelivered";
public static final String TYPE = "_jms.JMSType";
}

View File

@@ -48,7 +48,7 @@ public class JmsGateway extends SimpleMessagingGateway implements Lifecycle, Dis
private volatile String destinationName;
private volatile MessageConverter messageConverter = new SimpleMessageConverter();
private volatile MessageConverter messageConverter;
private volatile TaskExecutor taskExecutor;
@@ -133,6 +133,12 @@ public class JmsGateway extends SimpleMessagingGateway implements Lifecycle, Dis
MessageListenerAdapter listener = new MessageListenerAdapter();
listener.setDelegate(this);
listener.setDefaultListenerMethod(this.expectReply ? "sendAndReceive" : "send");
if (this.messageConverter == null) {
this.messageConverter = new SimpleMessageConverter();
}
if (!(this.messageConverter instanceof HeaderMappingMessageConverter)) {
this.messageConverter = new HeaderMappingMessageConverter(this.messageConverter);
}
listener.setMessageConverter(this.messageConverter);
this.container.setMessageListener(listener);
if (!this.container.isActive()) {

View File

@@ -0,0 +1,46 @@
/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.adapter.jms;
/**
* Pre-defined names and prefixes to be used for setting and/or retrieving JMS attributes
* from/to integration Message Headers.
*
* @author Mark Fisher
*/
public abstract class JmsHeaders {
/**
* Prefix for any message header that should be passed for usage by the JMS transport.
*/
public static final String TRANSFPORT_PREFIX = "spring.integration.transport.jms.";
/**
* Prefix for any user-defined message header that should be passed within JMS properties.
*/
public static final String USER_PREFIX = "spring.integration.user.jms.";
public static final String CORRELATION_ID = TRANSFPORT_PREFIX + "JMSCorrelationID";
public static final String REPLY_TO = TRANSFPORT_PREFIX + "JMSReplyTo";
public static final String REDELIVERED = TRANSFPORT_PREFIX + "JMSRedelivered";
public static final String TYPE = TRANSFPORT_PREFIX + "JMSType";
}

View File

@@ -129,12 +129,12 @@ public abstract class AbstractMailHeaderMapper implements MessageHeaderMapper<Mi
public Map<String,Object> mapToMessageHeaders(MimeMessage mailMessage) {
try {
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(MailAttributeKeys.FROM, convertToString(mailMessage.getFrom()));
headers.put(MailAttributeKeys.BCC, convertToStringArray(mailMessage.getRecipients(RecipientType.BCC)));
headers.put(MailAttributeKeys.CC, convertToStringArray(mailMessage.getRecipients(RecipientType.CC)));
headers.put(MailAttributeKeys.TO, convertToStringArray(mailMessage.getRecipients(RecipientType.TO)));
headers.put(MailAttributeKeys.REPLY_TO, convertToString(mailMessage.getReplyTo()));
headers.put(MailAttributeKeys.SUBJECT, mailMessage.getSubject());
headers.put(MailHeaders.FROM, convertToString(mailMessage.getFrom()));
headers.put(MailHeaders.BCC, convertToStringArray(mailMessage.getRecipients(RecipientType.BCC)));
headers.put(MailHeaders.CC, convertToStringArray(mailMessage.getRecipients(RecipientType.CC)));
headers.put(MailHeaders.TO, convertToStringArray(mailMessage.getRecipients(RecipientType.TO)));
headers.put(MailHeaders.REPLY_TO, convertToString(mailMessage.getReplyTo()));
headers.put(MailHeaders.SUBJECT, mailMessage.getSubject());
return headers;
}
catch (Exception e) {

View File

@@ -21,7 +21,7 @@ import org.springframework.integration.message.Message;
/**
* The default implementation of {@link MailHeaderGenerator}. Configures the
* {@link org.springframework.mail.MailMessage} properties based on attributes
* provided with known attribute keys as defined in {@link MailAttributeKeys}.
* provided with known attribute keys as defined in {@link MailHeaders}.
*
* @author Mark Fisher
*/
@@ -29,32 +29,32 @@ public class DefaultMailHeaderGenerator extends AbstractMailHeaderGenerator {
@Override
protected String getSubject(Message<?> message) {
return this.retrieveAsString(message, MailAttributeKeys.SUBJECT);
return this.retrieveAsString(message, MailHeaders.SUBJECT);
}
@Override
protected String[] getTo(Message<?> message) {
return this.retrieveAsStringArray(message, MailAttributeKeys.TO);
return this.retrieveAsStringArray(message, MailHeaders.TO);
}
@Override
protected String[] getCc(Message<?> message) {
return this.retrieveAsStringArray(message, MailAttributeKeys.CC);
return this.retrieveAsStringArray(message, MailHeaders.CC);
}
@Override
protected String[] getBcc(Message<?> message) {
return this.retrieveAsStringArray(message, MailAttributeKeys.BCC);
return this.retrieveAsStringArray(message, MailHeaders.BCC);
}
@Override
protected String getFrom(Message<?> message) {
return this.retrieveAsString(message, MailAttributeKeys.FROM);
return this.retrieveAsString(message, MailHeaders.FROM);
}
@Override
protected String getReplyTo(Message<?> message) {
return this.retrieveAsString(message, MailAttributeKeys.REPLY_TO);
return this.retrieveAsString(message, MailHeaders.REPLY_TO);
}

View File

@@ -26,32 +26,32 @@ public class DefaultMailMessageHeaderMapper extends AbstractMailHeaderMapper {
@Override
protected String getSubject(MessageHeaders headers) {
return this.retrieveAsString(headers, MailAttributeKeys.SUBJECT);
return this.retrieveAsString(headers, MailHeaders.SUBJECT);
}
@Override
protected String[] getTo(MessageHeaders headers) {
return this.retrieveAsStringArray(headers, MailAttributeKeys.TO);
return this.retrieveAsStringArray(headers, MailHeaders.TO);
}
@Override
protected String[] getCc(MessageHeaders headers) {
return this.retrieveAsStringArray(headers, MailAttributeKeys.CC);
return this.retrieveAsStringArray(headers, MailHeaders.CC);
}
@Override
protected String[] getBcc(MessageHeaders headers) {
return this.retrieveAsStringArray(headers, MailAttributeKeys.BCC);
return this.retrieveAsStringArray(headers, MailHeaders.BCC);
}
@Override
protected String getFrom(MessageHeaders headers) {
return this.retrieveAsString(headers, MailAttributeKeys.FROM);
return this.retrieveAsString(headers, MailHeaders.FROM);
}
@Override
protected String getReplyTo(MessageHeaders headers) {
return this.retrieveAsString(headers, MailAttributeKeys.REPLY_TO);
return this.retrieveAsString(headers, MailHeaders.REPLY_TO);
}
}

View File

@@ -17,23 +17,25 @@
package org.springframework.integration.adapter.mail;
/**
* Keys to be used for setting and/or retrieving mail attributes stored in the
* integration message header.
* Pre-defined names and prefixes to be used for setting and/or retrieving Mail attributes
* from/to integration Message Headers.
*
* @author Mark Fisher
*/
public class MailAttributeKeys {
public class MailHeaders {
public static final String SUBJECT = "_mail.SUBJECT";
public static final String TRANSFPORT_PREFIX = "spring.integration.transport.mail.";
public static final String TO = "_mail.TO";
public static final String SUBJECT = TRANSFPORT_PREFIX + "SUBJECT";
public static final String CC = "_mail.CC";
public static final String TO = TRANSFPORT_PREFIX + "TO";
public static final String BCC = "_mail.BCC";
public static final String CC = TRANSFPORT_PREFIX + "CC";
public static final String FROM = "_mail.FROM";
public static final String BCC = TRANSFPORT_PREFIX + "BCC";
public static final String REPLY_TO = "_mail.REPLY_TO";
public static final String FROM = TRANSFPORT_PREFIX + "FROM";
public static final String REPLY_TO = TRANSFPORT_PREFIX+ "REPLY_TO";
}