public abstract class AbstractAdaptableMessageListener extends java.lang.Object implements SessionAwareMessageListener<Message>
MessageListener
adapter providing the necessary
infrastructure to extract the payload of a JMS Message
.MessageListener
,
SessionAwareMessageListener
Modifier and Type | Class and Description |
---|---|
private static class |
AbstractAdaptableMessageListener.DestinationNameHolder
Internal class combining a destination name
and its target destination type (queue or topic).
|
private class |
AbstractAdaptableMessageListener.MessagingMessageConverterAdapter
Delegates payload extraction to
#extractMessage(javax.jms.Message) to
enforce backward compatibility. |
Modifier and Type | Field and Description |
---|---|
private java.lang.Object |
defaultResponseDestination |
private DestinationResolver |
destinationResolver |
protected Log |
logger
Logger available to subclasses
|
private MessageConverter |
messageConverter |
private AbstractAdaptableMessageListener.MessagingMessageConverterAdapter |
messagingMessageConverter |
Constructor and Description |
---|
AbstractAdaptableMessageListener() |
Modifier and Type | Method and Description |
---|---|
protected Message |
buildMessage(Session session,
java.lang.Object result)
Build a JMS message to be sent as response based on the given result object.
|
protected java.lang.Object |
extractMessage(Message message)
Extract the message body from the given JMS message.
|
protected DestinationResolver |
getDestinationResolver()
Return the DestinationResolver for this adapter.
|
protected MessageConverter |
getMessageConverter()
Return the converter that will convert incoming JMS messages to
listener method arguments, and objects returned from listener
methods back to JMS messages.
|
protected MessagingMessageConverter |
getMessagingMessageConverter()
Return the
MessagingMessageConverter for this listener,
being able to convert Message . |
protected Destination |
getResponseDestination(Message request,
Message response,
Session session)
Determine a response destination for the given message.
|
private Destination |
getResponseDestination(Message request,
Message response,
Session session,
java.lang.Object result) |
protected void |
handleListenerException(java.lang.Throwable ex)
Handle the given exception that arose during listener execution.
|
protected void |
handleResult(java.lang.Object result,
Message request,
Session session)
Handle the given result object returned from the listener method,
sending a response message back.
|
void |
onMessage(Message message)
Standard JMS
MessageListener entry point. |
protected void |
postProcessProducer(MessageProducer producer,
Message response)
Post-process the given message producer before using it to send the response.
|
protected void |
postProcessResponse(Message request,
Message response)
Post-process the given response message before it will be sent.
|
protected Destination |
resolveDefaultResponseDestination(Session session)
Resolve the default response destination into a JMS
Destination , using this
accessor's DestinationResolver in case of a destination name. |
protected void |
sendResponse(Session session,
Destination destination,
Message response)
Send the given response message to the given destination.
|
void |
setDefaultResponseDestination(Destination destination)
Set the default destination to send response messages to.
|
void |
setDefaultResponseQueueName(java.lang.String destinationName)
Set the name of the default response queue to send response messages to.
|
void |
setDefaultResponseTopicName(java.lang.String destinationName)
Set the name of the default response topic to send response messages to.
|
void |
setDestinationResolver(DestinationResolver destinationResolver)
Set the DestinationResolver that should be used to resolve response
destination names for this adapter.
|
void |
setHeaderMapper(JmsHeaderMapper headerMapper)
Set the
JmsHeaderMapper implementation to use to map the standard
JMS headers. |
void |
setMessageConverter(MessageConverter messageConverter)
Set the converter that will convert incoming JMS messages to
listener method arguments, and objects returned from listener
methods back to JMS messages.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
onMessage
protected final Log logger
private java.lang.Object defaultResponseDestination
private DestinationResolver destinationResolver
private MessageConverter messageConverter
private final AbstractAdaptableMessageListener.MessagingMessageConverterAdapter messagingMessageConverter
public void setDefaultResponseDestination(Destination destination)
Response destinations are only relevant for listener methods that return result objects, which will be wrapped in a response message and sent to a response destination.
Alternatively, specify a "defaultResponseQueueName" or "defaultResponseTopicName", to be dynamically resolved via the DestinationResolver.
public void setDefaultResponseQueueName(java.lang.String destinationName)
Alternatively, specify a JMS Destination object as "defaultResponseDestination".
setDestinationResolver(org.springframework.jms.support.destination.DestinationResolver)
,
#setDefaultResponseDestination(javax.jms.Destination)
public void setDefaultResponseTopicName(java.lang.String destinationName)
Alternatively, specify a JMS Destination object as "defaultResponseDestination".
setDestinationResolver(org.springframework.jms.support.destination.DestinationResolver)
,
#setDefaultResponseDestination(javax.jms.Destination)
public void setDestinationResolver(DestinationResolver destinationResolver)
The default resolver is a DynamicDestinationResolver. Specify a JndiDestinationResolver for resolving destination names as JNDI locations.
protected DestinationResolver getDestinationResolver()
public void setMessageConverter(MessageConverter messageConverter)
The default converter is a SimpleMessageConverter
, which is able
to handle BytesMessages
,
TextMessages
and
ObjectMessages
.
protected MessageConverter getMessageConverter()
public void setHeaderMapper(JmsHeaderMapper headerMapper)
JmsHeaderMapper
implementation to use to map the standard
JMS headers. By default, a SimpleJmsHeaderMapper
is used.SimpleJmsHeaderMapper
protected final MessagingMessageConverter getMessagingMessageConverter()
MessagingMessageConverter
for this listener,
being able to convert Message
.public void onMessage(Message message)
MessageListener
entry point.
Delegates the message to the target listener method, with appropriate
conversion of the message argument. In case of an exception, the
handleListenerException(Throwable)
method will be invoked.
Note: Does not support sending response messages based on
result objects returned from listener methods. Use the
SessionAwareMessageListener
entry point (typically through a Spring
message listener container) for handling result objects as well.
message
- the incoming JMS messagehandleListenerException(java.lang.Throwable)
,
#onMessage(javax.jms.Message, javax.jms.Session)
protected void handleListenerException(java.lang.Throwable ex)
This method only applies when used as standard JMS MessageListener
.
In case of the Spring SessionAwareMessageListener
mechanism,
exceptions get handled by the caller instead.
ex
- the exception to handle#onMessage(javax.jms.Message)
protected java.lang.Object extractMessage(Message message)
message
- the JMS Message
MessageConversionException
- if the message could not be unmarshaledprotected void handleResult(java.lang.Object result, Message request, Session session)
result
- the result object to handle (never null
)request
- the original request messagesession
- the JMS Session to operate on (may be null
)ReplyFailureException
- if the response message could not be sentbuildMessage(Session, java.lang.Object)
,
postProcessResponse(Message, Message)
,
getResponseDestination(Message, Message, Session, java.lang.Object)
,
sendResponse(Session, Destination, Message)
protected Message buildMessage(Session session, java.lang.Object result) throws JMSException
session
- the JMS Session to operate onresult
- the content of the message, as returned from the listener methodMessage
(never null
)JMSException
- if thrown by JMS API methodssetMessageConverter(org.springframework.jms.support.converter.MessageConverter)
protected void postProcessResponse(Message request, Message response) throws JMSException
The default implementation sets the response's correlation id to the request message's correlation id, if any; otherwise to the request message id.
request
- the original incoming JMS messageresponse
- the outgoing JMS message about to be sentJMSException
- if thrown by JMS API methodsjavax.jms.Message#setJMSCorrelationID
private Destination getResponseDestination(Message request, Message response, Session session, java.lang.Object result) throws JMSException
JMSException
protected Destination getResponseDestination(Message request, Message response, Session session) throws JMSException
The default implementation first checks the JMS Reply-To
Destination
of the supplied request; if that is not null
it is returned; if it is null
, then the configured
default response destination
is returned; if this too is null
, then an
javax.jms.InvalidDestinationException
is thrown.
request
- the original incoming JMS messageresponse
- the outgoing JMS message about to be sentsession
- the JMS Session to operate onnull
)JMSException
- if thrown by JMS API methodsjavax.jms.InvalidDestinationException
- if no Destination
can be determinedsetDefaultResponseDestination(Destination)
,
javax.jms.Message#getJMSReplyTo()
protected Destination resolveDefaultResponseDestination(Session session) throws JMSException
Destination
, using this
accessor's DestinationResolver
in case of a destination name.Destination
javax.jms.JMSException
- if resolution failedJMSException
setDefaultResponseDestination(Destination)
,
setDefaultResponseQueueName(java.lang.String)
,
setDefaultResponseTopicName(java.lang.String)
,
setDestinationResolver(org.springframework.jms.support.destination.DestinationResolver)
protected void sendResponse(Session session, Destination destination, Message response) throws JMSException
response
- the JMS message to senddestination
- the JMS destination to send tosession
- the JMS session to operate onJMSException
- if thrown by JMS API methodspostProcessProducer(MessageProducer, Message)
,
javax.jms.Session#createProducer
,
javax.jms.MessageProducer#send
protected void postProcessProducer(MessageProducer producer, Message response) throws JMSException
The default implementation is empty.
producer
- the JMS message producer that will be used to send the messageresponse
- the outgoing JMS message about to be sentJMSException
- if thrown by JMS API methods