diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/AbstractMessagingGateway.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/AbstractMessagingGateway.java index 86bf1b8697..66bec0b28a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/AbstractMessagingGateway.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/AbstractMessagingGateway.java @@ -31,6 +31,7 @@ import org.springframework.integration.message.InboundMessageMapper; import org.springframework.integration.message.MessageBuilder; import org.springframework.integration.message.MessageHandler; import org.springframework.integration.message.MessageDeliveryException; +import org.springframework.integration.message.MessageMappingException; import org.springframework.scheduling.support.PeriodicTrigger; import org.springframework.util.Assert; @@ -183,7 +184,13 @@ public abstract class AbstractMessagingGateway extends AbstractEndpoint { reply = this.channelTemplate.sendAndReceive(message, this.requestChannel); } catch (Exception e) { logger.warn("Execution of endpoint by the MessageListener resulted in : " + e); - reply = this.toMessage(e); + if (this.exceptionMapper != null){ + try { + reply = exceptionMapper.toMessage(e); + } catch (Exception e2) { + logger.warn("Problem mapping " + e + " to message with: " + exceptionMapper); + } + } if (reply == null){ // if reply wasn't mapped re-throw if (e instanceof RuntimeException){ throw (RuntimeException)e; @@ -250,25 +257,17 @@ public abstract class AbstractMessagingGateway extends AbstractEndpoint { this.exceptionMapper = exceptionMapper; } - /** - * Subclasses must implement this to map from an Object to a Message. - */ - protected Message toMessage(Object object){ - if (object instanceof Throwable){ - if (this.exceptionMapper != null){ - try { - return exceptionMapper.toMessage((Throwable) object); - } catch (Exception e2) { - logger.warn("Problem mapping " + object + " to message with: " + exceptionMapper); - } - } - } - return null; + protected Object fromMessage(Message message) { + throw new MessageMappingException("Can not map " + message + " to a object. No Mappers defined"); } - /** - * Subclasses must implement this to map from a Message to an Object. - */ - protected abstract Object fromMessage(Message message); + + protected Message toMessage(Object object) { + if (object instanceof Message){ + return (Message) object; + } else { + throw new MessageMappingException("Can not map " + object + " to a message. No Mappers defined"); + } + } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java index b6ba447cbf..cbc734d01c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java @@ -78,21 +78,17 @@ public class SimpleMessagingGateway extends AbstractMessagingGateway { @Override protected Message toMessage(Object object) { Message message = null; - if (object instanceof Throwable){ - message = super.toMessage(object); - } else { - try { - message = this.inboundMapper.toMessage(object); - if (message != null) { - message.getHeaders().getHistory().addEvent(this); - } + try { + message = this.inboundMapper.toMessage(object); + if (message != null) { + message.getHeaders().getHistory().addEvent(this); } - catch (Exception e) { - if (e instanceof RuntimeException) { - throw (RuntimeException) e; - } - throw new MessagingException("failed to create Message", e); + } + catch (Exception e) { + if (e instanceof RuntimeException) { + throw (RuntimeException) e; } + throw new MessagingException("failed to create Message", e); } return message; } diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListener.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListener.java index 0a5153cece..9f779a0093 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListener.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListener.java @@ -201,6 +201,10 @@ public class ChannelPublishingJmsMessageListener extends AbstractMessagingGatewa public void setExtractReplyPayload(boolean extractReplyPayload) { this.extractReplyPayload = extractReplyPayload; } + /* + * (non-Javadoc) + * @see org.springframework.integration.gateway.AbstractMessagingGateway#onInit() + */ public final void onInit() { if (!(this.messageConverter instanceof HeaderMappingMessageConverter)) { HeaderMappingMessageConverter hmmc = new HeaderMappingMessageConverter(this.messageConverter, this.headerMapper); @@ -209,7 +213,9 @@ public class ChannelPublishingJmsMessageListener extends AbstractMessagingGatewa this.messageConverter = hmmc; } } - + /** + * + */ public void onMessage(javax.jms.Message jmsMessage, Session session) throws JMSException { Object object = this.messageConverter.fromMessage(jmsMessage); Message requestMessage = (object instanceof Message) ? @@ -221,7 +227,7 @@ public class ChannelPublishingJmsMessageListener extends AbstractMessagingGatewa Message replyMessage = this.sendAndReceiveMessage(requestMessage); if (replyMessage != null){ - Destination destination = this.getReplyDestination(jmsMessage, session, false); + Destination destination = this.getReplyDestination(jmsMessage, session); if (destination != null){ javax.jms.Message jmsReply = this.messageConverter.toMessage(replyMessage, session); if (jmsReply.getJMSCorrelationID() == null) { @@ -263,7 +269,7 @@ public class ChannelPublishingJmsMessageListener extends AbstractMessagingGatewa * @see #setDefaultReplyDestination * @see javax.jms.Message#getJMSReplyTo() */ - private Destination getReplyDestination(javax.jms.Message request, Session session, boolean error) throws JMSException { + private Destination getReplyDestination(javax.jms.Message request, Session session) throws JMSException { Destination replyTo = request.getJMSReplyTo(); if (replyTo == null) { @@ -314,20 +320,4 @@ public class ChannelPublishingJmsMessageListener extends AbstractMessagingGatewa this.isTopic = isTopic; } } - - @Override - protected Object fromMessage(Message message) { - throw new UnsupportedOperationException("'fromMessage' is not supported within this instance"); - } - - @Override - protected Message toMessage(Object object) { - Message message = null; - if (object instanceof Throwable){ - message = super.toMessage(object); - } else if (object instanceof Message) { - message = (Message) object; - } - return message; - } }