public class JmsInvokerServiceExporter extends RemoteInvocationBasedExporter implements SessionAwareMessageListener<Message>, InitializingBean
Note that this class implements Spring's
SessionAwareMessageListener
interface, since it requires access to the active JMS Session.
Hence, this class can only be used with message listener containers
which support the SessionAwareMessageListener interface (e.g. Spring's
DefaultMessageListenerContainer
).
Thanks to James Strachan for the original prototype that this JMS invoker mechanism was inspired by!
JmsInvokerClientInterceptor
,
JmsInvokerProxyFactoryBean
logger
Constructor and Description |
---|
JmsInvokerServiceExporter() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Invoked by the containing
BeanFactory after it has set all bean properties
and satisfied BeanFactoryAware , ApplicationContextAware etc. |
protected Message |
createResponseMessage(Message request,
Session session,
RemoteInvocationResult result)
Create the invocation result response message.
|
protected RemoteInvocation |
onInvalidRequest(Message requestMessage)
Callback that is invoked by
readRemoteInvocation(javax.jms.Message)
when it encounters an invalid request message. |
void |
onMessage(Message requestMessage,
Session session)
Callback for processing a received JMS message.
|
protected RemoteInvocation |
readRemoteInvocation(Message requestMessage)
Read a RemoteInvocation from the given JMS message.
|
void |
setIgnoreInvalidRequests(boolean ignoreInvalidRequests)
Set whether invalidly formatted messages should be discarded.
|
void |
setMessageConverter(MessageConverter messageConverter)
Specify the MessageConverter to use for turning request messages into
RemoteInvocation objects,
as well as RemoteInvocationResult
objects into response messages. |
protected void |
writeRemoteInvocationResult(Message requestMessage,
Session session,
RemoteInvocationResult result)
Send the given RemoteInvocationResult as a JMS message to the originator.
|
getRemoteInvocationExecutor, invoke, invokeAndCreateResult, setRemoteInvocationExecutor
checkService, checkServiceInterface, getExporterName, getProxyForService, getService, getServiceInterface, setInterceptors, setRegisterTraceInterceptor, setService, setServiceInterface
getBeanClassLoader, overrideThreadContextClassLoader, resetThreadContextClassLoader, setBeanClassLoader
public void setMessageConverter(@Nullable MessageConverter messageConverter)
RemoteInvocation
objects,
as well as RemoteInvocationResult
objects into response messages.
Default is a SimpleMessageConverter
,
using a standard JMS ObjectMessage
for each invocation /
invocation result object.
Custom implementations may generally adapt Serializables into special kinds of messages, or might be specifically tailored for translating RemoteInvocation(Result)s into specific kinds of messages.
public void setIgnoreInvalidRequests(boolean ignoreInvalidRequests)
Switch this flag to "false" to throw an exception back to the listener container. This will typically lead to redelivery of the message, which is usually undesirable - since the message content will be the same (that is, still invalid).
public void afterPropertiesSet()
InitializingBean
BeanFactory
after it has set all bean properties
and satisfied BeanFactoryAware
, ApplicationContextAware
etc.
This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
afterPropertiesSet
in interface InitializingBean
public void onMessage(Message requestMessage, Session session) throws JMSException
SessionAwareMessageListener
Implementors are supposed to process the given Message, typically sending reply messages through the given Session.
onMessage
in interface SessionAwareMessageListener<Message>
requestMessage
- the received JMS message (never null
)session
- the underlying JMS Session (never null
)JMSException
- if thrown by JMS methods@Nullable protected RemoteInvocation readRemoteInvocation(Message requestMessage) throws JMSException
requestMessage
- current request messagenull
in case of an invalid message that will simply be ignored)JMSException
- in case of message access failureprotected void writeRemoteInvocationResult(Message requestMessage, Session session, RemoteInvocationResult result) throws JMSException
requestMessage
- current request messagesession
- the JMS Session to useresult
- the RemoteInvocationResult objectJMSException
- if thrown by trying to send the messageprotected Message createResponseMessage(Message request, Session session, RemoteInvocationResult result) throws JMSException
The default implementation creates a JMS ObjectMessage for the given RemoteInvocationResult object. It sets the response's correlation id to the request message's correlation id, if any; otherwise to the request message id.
request
- the original request messagesession
- the JMS session to useresult
- the invocation resultJMSException
- if creating the message failed@Nullable protected RemoteInvocation onInvalidRequest(Message requestMessage) throws JMSException
readRemoteInvocation(javax.jms.Message)
when it encounters an invalid request message.
The default implementation either discards the invalid message or throws a MessageFormatException - according to the "ignoreInvalidRequests" flag, which is set to "true" (that is, discard invalid messages) by default.
requestMessage
- the invalid request messagenull
in case of an invalid message that will simply be ignored)JMSException
- in case of the invalid request supposed
to lead to an exception (instead of ignoring it)readRemoteInvocation(javax.jms.Message)
,
setIgnoreInvalidRequests(boolean)