public class JmsInvokerClientInterceptor implements MethodInterceptor,InitializingBean(Code)
org.aopalliance.intercept.MethodInterceptor for accessing a
JMS-based remote service.
Serializes remote invocation objects and deserializes remote invocation
result objects. Uses Java serialization just like RMI, but with the JMS
provider as communication infrastructure.
To be configured with a
javax.jms.QueueConnectionFactory and a
target queue (either as
javax.jms.Queue reference or as queue name).
doExecuteRequest(QueueSession session, Queue queue, Message requestMessage) Actually execute the given request, sending the invoker request message
to the specified target queue and waiting for a corresponding response.
executeRequest(RemoteInvocation invocation) Execute the given remote invocation, sending an invoker request message
to this accessor's target queue and waiting for a corresponding response.
Convert the given JMS invoker access exception to an appropriate
Spring RemoteAccessException.
Parameters: ex - the exception to convert the RemoteAccessException to throw
Create a new RemoteInvocation object for the given AOP method invocation.
The default implementation delegates to the RemoteInvocationFactory.
Can be overridden in subclasses to provide custom RemoteInvocation
subclasses, containing additional invocation parameters like user credentials.
Note that it is preferable to use a custom RemoteInvocationFactory which
is a reusable strategy.
Parameters: methodInvocation - the current AOP method invocation the RemoteInvocation object See Also:RemoteInvocationFactory.createRemoteInvocation
The default implementation creates a JMS ObjectMessage
for the given RemoteInvocation object.
Parameters: session - the current JMS Session Parameters: invocation - the remote invocation to send the JMS Message to send throws: JMSException - if the message could not be created
Actually execute the given request, sending the invoker request message
to the specified target queue and waiting for a corresponding response.
The default implementation is based on standard JMS send/receive,
using a
javax.jms.TemporaryQueue for receiving the response.
Parameters: session - the JMS Session to use Parameters: queue - the resolved target Queue to send to Parameters: requestMessage - the JMS Message to send the RemoteInvocationResult object throws: JMSException - in case of JMS failure
Execute the given remote invocation, sending an invoker request message
to this accessor's target queue and waiting for a corresponding response.
Parameters: invocation - the RemoteInvocation to execute the RemoteInvocationResult object throws: JMSException - in case of JMS failure See Also:JmsInvokerClientInterceptor.doExecuteRequest
Extract the invocation result from the response message.
The default implementation expects a JMS ObjectMessage carrying
a RemoteInvocationResult object. If an invalid response message is
encountered, the onInvalidResponse callback gets invoked.
Parameters: responseMessage - the response message the invocation result throws: JMSException - is thrown if a JMS exception occurs See Also:JmsInvokerClientInterceptor.onInvalidResponse
Callback that is invoked by extractInvocationResult
when it encounters an invalid response message.
The default implementation throws a MessageFormatException.
Parameters: responseMessage - the invalid response message an alternative invocation result that should bereturned to the caller (if desired) throws: JMSException - if the invalid response should leadto an infrastructure exception propagated to the caller See Also:JmsInvokerClientInterceptor.extractInvocationResult
Recreate the invocation result contained in the given RemoteInvocationResult
object. The default implementation calls the default recreate method.
Can be overridden in subclass to provide custom recreation, potentially
processing the returned result object.
Parameters: result - the RemoteInvocationResult to recreate a return value if the invocation result is a successful return throws: Throwable - if the invocation result is an exception See Also:org.springframework.remoting.support.RemoteInvocationResult.recreate
Resolve this accessor's target queue.
Parameters: session - the current JMS Session the resolved target Queue throws: JMSException - if resolution failed
Resolve the given queue name into a JMS
javax.jms.Queue ,
via this accessor's
DestinationResolver .
Parameters: session - the current JMS Session Parameters: queueName - the name of the queue the located Queue throws: JMSException - if resolution failed See Also:JmsInvokerClientInterceptor.setDestinationResolver
setConnectionFactory
public void setConnectionFactory(QueueConnectionFactory connectionFactory)(Code)
Set the QueueConnectionFactory to use for obtaining JMS QueueConnections.
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 setReceiveTimeout(long receiveTimeout)(Code)
Set the timeout to use for receiving the response message for a request
(in milliseconds).
The default is 0, which indicates a blocking receive without timeout.
See Also: javax.jms.MessageConsumer.receive(long) See Also: javax.jms.MessageConsumer.receive