Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[SPR-10412] Support generics in JmsTemplate #266

Open
wants to merge 1 commit into from

2 participants

@marschall

The #convertAndSend and #receiveAndConvert methods and the
MessageConverter interface currently are not type safe. Everywhere
Object is passed around casts have to be made.

This pull request tries to address the issue by:

  • split MessageConverter into two interfaces, MessageDecoder and
    MessageEncoder so that Java 8 lambdas can be used

  • add generics to MessageConverter, MessageDecoder and
    MessageEncoder

  • for every #convertAndSend method add a new one that has a
    MessageEncoder as a second argument

  • for every #receiveAndConvert method add a new one that
    has a MessageDecoder as a second argument

  • add generics to the new #convertAndSend and
    #receiveAndConvert methods

MessageConverter and MessageDecoder are not be best names but the best
ones I could come up with.

Maybe MessageConverter and MessageDecoder should be annotated with
java.lang.FunctionalInterface but this would have to be done over the
entire code base eg. org.springframework.jdbc.core.RowMapper.

As usual, I'm not one hundred percent certain when it comes to wild
cards.

And tests are missing.

Issue: SPR-10412
https://jira.springsource.org/browse/SPR-10412

@marschall marschall [SPR-10412] Support generics in JmsTemplate
The `#convertAndSend` and `#receiveAndConvert` methods and the
`MessageConverter` interface currently are not type safe. Everywhere
`Object` is passed around casts have to be made.

This pull request tries to address the issue by:

 - split `MessageConverter` into two interfaces, `MessageDecoder` and
   `MessageEncoder` so that Java 8 lambdas can be used

 - add generics to `MessageConverter`, `MessageDecoder` and
   `MessageEncoder`

 - for every `#convertAndSend` method add a new one that has a
  `MessageEncoder` as a second argument

 - for every `#receiveAndConvert` method add a new one that
   has a `MessageDecoder` as a second argument

 - add generics to the new `#convertAndSend` and
  `#receiveAndConvert` methods

MessageConverter and MessageDecoder are not be best names but the best
ones I could come up with.

Maybe `MessageConverter` and `MessageDecoder` should be annotated with
`java.lang.FunctionalInterface` but this would have to be done over the
entire code base eg. `org.springframework.jdbc.core.RowMapper`.

As usual, I'm not one hundred percent certain when it comes to wild
cards.

And tests are missing.

Issue: SPR-10412
https://jira.springsource.org/browse/SPR-10412
4e3ecd9
@jhoeller jhoeller was assigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 24, 2013
  1. @marschall

    [SPR-10412] Support generics in JmsTemplate

    marschall authored
    The `#convertAndSend` and `#receiveAndConvert` methods and the
    `MessageConverter` interface currently are not type safe. Everywhere
    `Object` is passed around casts have to be made.
    
    This pull request tries to address the issue by:
    
     - split `MessageConverter` into two interfaces, `MessageDecoder` and
       `MessageEncoder` so that Java 8 lambdas can be used
    
     - add generics to `MessageConverter`, `MessageDecoder` and
       `MessageEncoder`
    
     - for every `#convertAndSend` method add a new one that has a
      `MessageEncoder` as a second argument
    
     - for every `#receiveAndConvert` method add a new one that
       has a `MessageDecoder` as a second argument
    
     - add generics to the new `#convertAndSend` and
      `#receiveAndConvert` methods
    
    MessageConverter and MessageDecoder are not be best names but the best
    ones I could come up with.
    
    Maybe `MessageConverter` and `MessageDecoder` should be annotated with
    `java.lang.FunctionalInterface` but this would have to be done over the
    entire code base eg. `org.springframework.jdbc.core.RowMapper`.
    
    As usual, I'm not one hundred percent certain when it comes to wild
    cards.
    
    And tests are missing.
    
    Issue: SPR-10412
    https://jira.springsource.org/browse/SPR-10412
This page is out of date. Refresh to see the latest.
View
170 spring-jms/src/main/java/org/springframework/jms/core/JmsOperations.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -21,6 +21,8 @@
import javax.jms.Queue;
import org.springframework.jms.JmsException;
+import org.springframework.jms.support.converter.MessageDecoder;
+import org.springframework.jms.support.converter.MessageEncoder;
/**
* Specifies a basic set of JMS operations.
@@ -34,6 +36,7 @@
*
* @author Mark Pollack
* @author Juergen Hoeller
+ * @author Philippe Marschall
* @since 1.1
* @see JmsTemplate
* @see javax.jms.Destination
@@ -130,6 +133,17 @@
* @throws JmsException converted checked JMSException to unchecked
*/
void convertAndSend(Object message) throws JmsException;
+
+ /**
+ * Send the given object to the default destination, converting the object
+ * to a JMS message with a given MessageEncoder.
+ * <p>This will only work with a default destination specified!
+ * @param message the object to convert to a message
+ * @param encoder the object doing the conversion
+ * @throws JmsException converted checked JMSException to unchecked
+ */
+ <T> void convertAndSend(T message, MessageEncoder<? super T> encoder)
+ throws JmsException;
/**
* Send the given object to the specified destination, converting the object
@@ -139,6 +153,17 @@
* @throws JmsException converted checked JMSException to unchecked
*/
void convertAndSend(Destination destination, Object message) throws JmsException;
+
+ /**
+ * Send the given object to the specified destination, converting the object
+ * to a JMS message with a given MessageConverter.
+ * @param destination the destination to send this message to
+ * @param message the object to convert to a message
+ * @param encoder the object doing the conversion
+ * @throws JmsException converted checked JMSException to unchecked
+ */
+ <T> void convertAndSend(Destination destination, T message, MessageEncoder<? super T> encoder)
+ throws JmsException;
/**
* Send the given object to the specified destination, converting the object
@@ -149,6 +174,18 @@
* @throws JmsException checked JMSException converted to unchecked
*/
void convertAndSend(String destinationName, Object message) throws JmsException;
+
+ /**
+ * Send the given object to the specified destination, converting the object
+ * to a JMS message with a given MessageConverter.
+ * @param destinationName the name of the destination to send this message to
+ * (to be resolved to an actual destination by a DestinationResolver)
+ * @param message the object to convert to a message
+ * @param encoder the object doing the conversion
+ * @throws JmsException checked JMSException converted to unchecked
+ */
+ <T> void convertAndSend(String destinationName, T message, MessageEncoder<? super T> encoder)
+ throws JmsException;
/**
* Send the given object to the default destination, converting the object
@@ -161,6 +198,19 @@
*/
void convertAndSend(Object message, MessagePostProcessor postProcessor)
throws JmsException;
+
+ /**
+ * Send the given object to the default destination, converting the object
+ * to a JMS message with a given MessageConverter. The MessagePostProcessor
+ * callback allows for modification of the message after conversion.
+ * <p>This will only work with a default destination specified!
+ * @param message the object to convert to a message
+ * @param postProcessor the callback to modify the message
+ * @param encoder the object doing the conversion
+ * @throws JmsException checked JMSException converted to unchecked
+ */
+ <T> void convertAndSend(T message, MessagePostProcessor postProcessor, MessageEncoder<? super T> encoder)
+ throws JmsException;
/**
* Send the given object to the specified destination, converting the object
@@ -173,6 +223,19 @@ void convertAndSend(Object message, MessagePostProcessor postProcessor)
*/
void convertAndSend(Destination destination, Object message, MessagePostProcessor postProcessor)
throws JmsException;
+
+ /**
+ * Send the given object to the specified destination, converting the object
+ * to a JMS message with a given MessageConverter. The MessagePostProcessor
+ * callback allows for modification of the message after conversion.
+ * @param destination the destination to send this message to
+ * @param message the object to convert to a message
+ * @param postProcessor the callback to modify the message
+ * @param encoder the object doing the conversion
+ * @throws JmsException checked JMSException converted to unchecked
+ */
+ <T> void convertAndSend(Destination destination, T message, MessagePostProcessor postProcessor, MessageEncoder<? super T> encoder)
+ throws JmsException;
/**
* Send the given object to the specified destination, converting the object
@@ -186,6 +249,20 @@ void convertAndSend(Destination destination, Object message, MessagePostProcesso
*/
void convertAndSend(String destinationName, Object message, MessagePostProcessor postProcessor)
throws JmsException;
+
+ /**
+ * Send the given object to the specified destination, converting the object
+ * to a JMS message with a configured MessageConverter. The MessagePostProcessor
+ * callback allows for modification of the message after conversion.
+ * @param destinationName the name of the destination to send this message to
+ * (to be resolved to an actual destination by a DestinationResolver)
+ * @param message the object to convert to a message.
+ * @param postProcessor the callback to modify the message
+ * @param encoder the object doing the conversion
+ * @throws JmsException checked JMSException converted to unchecked
+ */
+ <T> void convertAndSend(String destinationName, T message, MessagePostProcessor postProcessor, MessageEncoder<? super T> encoder)
+ throws JmsException;
//-------------------------------------------------------------------------
@@ -282,6 +359,19 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
* @throws JmsException checked JMSException converted to unchecked
*/
Object receiveAndConvert() throws JmsException;
+
+ /**
+ * Receive a message synchronously from the default destination, but only
+ * wait up to a specified time for delivery. Convert the message into an
+ * object with a given MessageConverter.
+ * <p>This method should be used carefully, since it will block the thread
+ * until the message becomes available or until the timeout value is exceeded.
+ * <p>This will only work with a default destination specified!
+ * @param decoder the object doing the conversion
+ * @return the message produced for the consumer or {@code null} if the timeout expires.
+ * @throws JmsException checked JMSException converted to unchecked
+ */
+ <T> T receiveAndConvert(MessageDecoder<? extends T> decoder) throws JmsException;
/**
* Receive a message synchronously from the specified destination, but only
@@ -294,6 +384,20 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
* @throws JmsException checked JMSException converted to unchecked
*/
Object receiveAndConvert(Destination destination) throws JmsException;
+
+ /**
+ * Receive a message synchronously from the specified destination, but only
+ * wait up to a specified time for delivery. Convert the message into an
+ * object with a given MessageConverter.
+ * <p>This method should be used carefully, since it will block the thread
+ * until the message becomes available or until the timeout value is exceeded.
+ * @param destination the destination to receive a message from
+ * @param decoder the object doing the conversion
+ * @return the message produced for the consumer or {@code null} if the timeout expires.
+ * @throws JmsException checked JMSException converted to unchecked
+ */
+ <T> T receiveAndConvert(Destination destination, MessageDecoder<? extends T> decoder)
+ throws JmsException;
/**
* Receive a message synchronously from the specified destination, but only
@@ -307,6 +411,21 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
* @throws JmsException checked JMSException converted to unchecked
*/
Object receiveAndConvert(String destinationName) throws JmsException;
+
+ /**
+ * Receive a message synchronously from the specified destination, but only
+ * wait up to a specified time for delivery. Convert the message into an
+ * object with a given MessageConverter.
+ * <p>This method should be used carefully, since it will block the thread
+ * until the message becomes available or until the timeout value is exceeded.
+ * @param destinationName the name of the destination to send this message to
+ * (to be resolved to an actual destination by a DestinationResolver)
+ * @param decoder the object doing the conversion
+ * @return the message produced for the consumer or {@code null} if the timeout expires.
+ * @throws JmsException checked JMSException converted to unchecked
+ */
+ <T> T receiveAndConvert(String destinationName, MessageDecoder<? extends T> decoder)
+ throws JmsException;
/**
* Receive a message synchronously from the default destination, but only
@@ -321,6 +440,22 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
* @throws JmsException checked JMSException converted to unchecked
*/
Object receiveSelectedAndConvert(String messageSelector) throws JmsException;
+
+ /**
+ * Receive a message synchronously from the default destination, but only
+ * wait up to a specified time for delivery. Convert the message into an
+ * object with a given MessageConverter.
+ * <p>This method should be used carefully, since it will block the thread
+ * until the message becomes available or until the timeout value is exceeded.
+ * <p>This will only work with a default destination specified!
+ * @param messageSelector the JMS message selector expression (or {@code null} if none).
+ * See the JMS specification for a detailed definition of selector expressions.
+ * @param decoder the object doing the conversion
+ * @return the message produced for the consumer or {@code null} if the timeout expires.
+ * @throws JmsException checked JMSException converted to unchecked
+ */
+ <T> T receiveSelectedAndConvert(String messageSelector, MessageDecoder<? extends T> decoder)
+ throws JmsException;
/**
* Receive a message synchronously from the specified destination, but only
@@ -335,6 +470,22 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
* @throws JmsException checked JMSException converted to unchecked
*/
Object receiveSelectedAndConvert(Destination destination, String messageSelector) throws JmsException;
+
+ /**
+ * Receive a message synchronously from the specified destination, but only
+ * wait up to a specified time for delivery. Convert the message into an
+ * object with a given MessageConverter.
+ * <p>This method should be used carefully, since it will block the thread
+ * until the message becomes available or until the timeout value is exceeded.
+ * @param destination the destination to receive a message from
+ * @param messageSelector the JMS message selector expression (or {@code null} if none).
+ * See the JMS specification for a detailed definition of selector expressions.
+ * @param decoder the object doing the conversion
+ * @return the message produced for the consumer or {@code null} if the timeout expires.
+ * @throws JmsException checked JMSException converted to unchecked
+ */
+ <T> T receiveSelectedAndConvert(Destination destination, String messageSelector, MessageDecoder<? extends T> decoder)
+ throws JmsException;
/**
* Receive a message synchronously from the specified destination, but only
@@ -350,6 +501,23 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
* @throws JmsException checked JMSException converted to unchecked
*/
Object receiveSelectedAndConvert(String destinationName, String messageSelector) throws JmsException;
+
+ /**
+ * Receive a message synchronously from the specified destination, but only
+ * wait up to a specified time for delivery. Convert the message into an
+ * object with a given MessageConverter.
+ * <p>This method should be used carefully, since it will block the thread
+ * until the message becomes available or until the timeout value is exceeded.
+ * @param destinationName the name of the destination to send this message to
+ * (to be resolved to an actual destination by a DestinationResolver)
+ * @param messageSelector the JMS message selector expression (or {@code null} if none).
+ * See the JMS specification for a detailed definition of selector expressions.
+ * @param decoder the object doing the conversion
+ * @return the message produced for the consumer or {@code null} if the timeout expires.
+ * @throws JmsException checked JMSException converted to unchecked
+ */
+ <T> T receiveSelectedAndConvert(String destinationName, String messageSelector, MessageDecoder<? extends T> decoder)
+ throws JmsException;
//-------------------------------------------------------------------------
View
96 spring-jms/src/main/java/org/springframework/jms/core/JmsTemplate.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -33,6 +33,8 @@
import org.springframework.jms.connection.JmsResourceHolder;
import org.springframework.jms.support.JmsUtils;
import org.springframework.jms.support.converter.MessageConverter;
+import org.springframework.jms.support.converter.MessageDecoder;
+import org.springframework.jms.support.converter.MessageEncoder;
import org.springframework.jms.support.converter.SimpleMessageConverter;
import org.springframework.jms.support.destination.JmsDestinationAccessor;
import org.springframework.transaction.support.TransactionSynchronizationManager;
@@ -74,6 +76,7 @@
*
* @author Mark Pollack
* @author Juergen Hoeller
+ * @author Philippe Marschall
* @since 1.1
* @see #setConnectionFactory
* @see #setPubSubDomain
@@ -599,38 +602,57 @@ protected void doSend(MessageProducer producer, Message message) throws JMSExcep
//-------------------------------------------------------------------------
public void convertAndSend(Object message) throws JmsException {
+ convertAndSend(message, getRequiredMessageConverter());
+ }
+
+ public <T> void convertAndSend(final T message, final MessageEncoder<? super T> encoder) throws JmsException {
Destination defaultDestination = getDefaultDestination();
if (defaultDestination != null) {
- convertAndSend(defaultDestination, message);
+ convertAndSend(defaultDestination, message, encoder);
}
else {
- convertAndSend(getRequiredDefaultDestinationName(), message);
+ convertAndSend(getRequiredDefaultDestinationName(), message, encoder);
}
}
public void convertAndSend(Destination destination, final Object message) throws JmsException {
+ convertAndSend(destination, message, getRequiredMessageConverter());
+ }
+
+ public <T> void convertAndSend(Destination destination, final T message, final MessageEncoder<? super T> encoder)
+ throws JmsException {
send(destination, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
- return getRequiredMessageConverter().toMessage(message, session);
+ return encoder.toMessage(message, session);
}
});
}
public void convertAndSend(String destinationName, final Object message) throws JmsException {
+ convertAndSend(destinationName, message, getRequiredMessageConverter());
+ }
+
+ public <T> void convertAndSend(String destinationName, final T message, final MessageEncoder<? super T> encoder)
+ throws JmsException {
send(destinationName, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
- return getRequiredMessageConverter().toMessage(message, session);
+ return encoder.toMessage(message, session);
}
});
}
public void convertAndSend(Object message, MessagePostProcessor postProcessor) throws JmsException {
+ convertAndSend(message, postProcessor, getRequiredMessageConverter());
+ }
+
+ public <T> void convertAndSend(T message, MessagePostProcessor postProcessor, MessageEncoder<? super T> encoder)
+ throws JmsException {
Destination defaultDestination = getDefaultDestination();
if (defaultDestination != null) {
- convertAndSend(defaultDestination, message, postProcessor);
+ convertAndSend(defaultDestination, message, postProcessor, encoder);
}
else {
- convertAndSend(getRequiredDefaultDestinationName(), message, postProcessor);
+ convertAndSend(getRequiredDefaultDestinationName(), message, postProcessor, encoder);
}
}
@@ -638,9 +660,16 @@ public void convertAndSend(
Destination destination, final Object message, final MessagePostProcessor postProcessor)
throws JmsException {
+ convertAndSend(destination, message, postProcessor, getRequiredMessageConverter());
+ }
+
+ public <T> void convertAndSend(
+ Destination destination, final T message, final MessagePostProcessor postProcessor, final MessageEncoder<? super T> encoder)
+ throws JmsException {
+
send(destination, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
- Message msg = getRequiredMessageConverter().toMessage(message, session);
+ Message msg = encoder.toMessage(message, session);
return postProcessor.postProcessMessage(msg);
}
});
@@ -650,9 +679,16 @@ public void convertAndSend(
String destinationName, final Object message, final MessagePostProcessor postProcessor)
throws JmsException {
+ convertAndSend(destinationName, message, postProcessor, getRequiredMessageConverter());
+ }
+
+ public <T> void convertAndSend(
+ String destinationName, final T message, final MessagePostProcessor postProcessor, final MessageEncoder<? super T> encoder)
+ throws JmsException {
+
send(destinationName, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
- Message msg = getRequiredMessageConverter().toMessage(message, session);
+ Message msg = encoder.toMessage(message, session);
return postProcessor.postProcessMessage(msg);
}
});
@@ -786,26 +822,55 @@ else if (timeout > 0) {
public Object receiveAndConvert() throws JmsException {
return doConvertFromMessage(receive());
}
+
+ public <T> T receiveAndConvert(MessageDecoder<? extends T> decoder) throws JmsException {
+ return doConvertFromMessage(receive(), decoder);
+ }
public Object receiveAndConvert(Destination destination) throws JmsException {
return doConvertFromMessage(receive(destination));
}
+
+ public <T> T receiveAndConvert(Destination destination, MessageDecoder<? extends T> decoder)
+ throws JmsException {
+ return doConvertFromMessage(receive(destination), decoder);
+ }
public Object receiveAndConvert(String destinationName) throws JmsException {
return doConvertFromMessage(receive(destinationName));
}
+
+ public <T> T receiveAndConvert(String destinationName, MessageDecoder<? extends T> decoder)
+ throws JmsException {
+ return doConvertFromMessage(receive(destinationName), decoder);
+ }
public Object receiveSelectedAndConvert(String messageSelector) throws JmsException {
return doConvertFromMessage(receiveSelected(messageSelector));
}
+
+ public <T> T receiveSelectedAndConvert(String messageSelector, MessageDecoder<? extends T> decoder)
+ throws JmsException {
+ return doConvertFromMessage(receiveSelected(messageSelector), decoder);
+ }
public Object receiveSelectedAndConvert(Destination destination, String messageSelector) throws JmsException {
return doConvertFromMessage(receiveSelected(destination, messageSelector));
}
+
+ public <T> T receiveSelectedAndConvert(Destination destination, String messageSelector, MessageDecoder<? extends T> decoder)
+ throws JmsException {
+ return doConvertFromMessage(receiveSelected(destination, messageSelector), decoder);
+ }
public Object receiveSelectedAndConvert(String destinationName, String messageSelector) throws JmsException {
return doConvertFromMessage(receiveSelected(destinationName, messageSelector));
}
+
+ public <T> T receiveSelectedAndConvert(String destinationName, String messageSelector, MessageDecoder<? extends T> decoder)
+ throws JmsException {
+ return doConvertFromMessage(receiveSelected(destinationName, messageSelector), decoder);
+ }
/**
* Extract the content from the given JMS message.
@@ -813,9 +878,20 @@ public Object receiveSelectedAndConvert(String destinationName, String messageSe
* @return the content of the message, or {@code null} if none
*/
protected Object doConvertFromMessage(Message message) {
+ return doConvertFromMessage(message, getMessageConverter());
+ }
+
+ /**
+ * Extract the content from the given JMS message.
+ * @param message the JMS Message to convert (can be {@code null})
+ * @param decoder the object doing the conversion (can be only be {@code null} when
+ * the message is {@code null})
+ * @return the content of the message, or {@code null} if none
+ */
+ protected <T> T doConvertFromMessage(Message message, MessageDecoder<? extends T> decoder) {
if (message != null) {
try {
- return getRequiredMessageConverter().fromMessage(message);
+ return decoder.fromMessage(message);
}
catch (JMSException ex) {
throw convertJmsAccessException(ex);
View
27 spring-jms/src/main/java/org/springframework/jms/support/converter/MessageConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2007 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -16,9 +16,6 @@
package org.springframework.jms.support.converter;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.Session;
/**
* Strategy interface that specifies a converter between Java objects and JMS messages.
@@ -34,26 +31,6 @@
* @see org.springframework.jms.remoting.JmsInvokerClientInterceptor#setMessageConverter
* @see org.springframework.jms.remoting.JmsInvokerServiceExporter#setMessageConverter
*/
-public interface MessageConverter {
-
- /**
- * Convert a Java object to a JMS Message using the supplied session
- * to create the message object.
- * @param object the object to convert
- * @param session the Session to use for creating a JMS Message
- * @return the JMS Message
- * @throws javax.jms.JMSException if thrown by JMS API methods
- * @throws MessageConversionException in case of conversion failure
- */
- Message toMessage(Object object, Session session) throws JMSException, MessageConversionException;
-
- /**
- * Convert from a JMS Message to a Java object.
- * @param message the message to convert
- * @return the converted Java object
- * @throws javax.jms.JMSException if thrown by JMS API methods
- * @throws MessageConversionException in case of conversion failure
- */
- Object fromMessage(Message message) throws JMSException, MessageConversionException;
+public interface MessageConverter<T> extends MessageDecoder<T>, MessageEncoder<T> {
}
View
40 spring-jms/src/main/java/org/springframework/jms/support/converter/MessageDecoder.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2004-2013 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.jms.support.converter;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+
+
+/**
+ * Strategy interface that specifies a converter from JMS messages to Java objects.
+ *
+ * @author Philippe Marschall
+ * @since 4.0
+ */
+public interface MessageDecoder<T> {
+
+ /**
+ * Convert from a JMS Message to a Java object.
+ * @param message the message to convert
+ * @return the converted Java object
+ * @throws javax.jms.JMSException if thrown by JMS API methods
+ * @throws MessageConversionException in case of conversion failure
+ */
+ T fromMessage(Message message) throws JMSException, MessageConversionException;
+
+}
View
43 spring-jms/src/main/java/org/springframework/jms/support/converter/MessageEncoder.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2004-2013 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.jms.support.converter;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+
+
+/**
+ * Strategy interface that specifies a converter from Java objects to JMS messages.
+ *
+ * @author Philippe Marschall
+ * @since 4.0
+ */
+public interface MessageEncoder<T> {
+
+ /**
+ * Convert a Java object to a JMS Message using the supplied session
+ * to create the message object.
+ * @param object the object to convert
+ * @param session the Session to use for creating a JMS Message
+ * @return the JMS Message
+ * @throws javax.jms.JMSException if thrown by JMS API methods
+ * @throws MessageConversionException in case of conversion failure
+ */
+ Message toMessage(T object, Session session) throws JMSException, MessageConversionException;
+
+}
View
4 spring-jms/src/main/java/org/springframework/jms/support/converter/SimpleMessageConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -45,7 +45,7 @@
* @see org.springframework.jms.core.JmsTemplate#convertAndSend
* @see org.springframework.jms.core.JmsTemplate#receiveAndConvert
*/
-public class SimpleMessageConverter implements MessageConverter {
+public class SimpleMessageConverter implements MessageConverter<Object> {
/**
* This implementation creates a TextMessage for a String, a
Something went wrong with that request. Please try again.