The Spring Framework

org.springframework.jms.remoting
Class JmsInvokerClientInterceptor

java.lang.Object
  extended by org.springframework.jms.remoting.JmsInvokerClientInterceptor
All Implemented Interfaces:
Advice, Interceptor, MethodInterceptor, InitializingBean
Direct Known Subclasses:
JmsInvokerProxyFactoryBean

public class JmsInvokerClientInterceptor
extends Object
implements MethodInterceptor, InitializingBean

Interceptor for accessing a JMS-based remote service.

To be configured with a QueueConnectionFactory and a target queue (either as Queue reference or as queue name).

Since:
2.0
Author:
Juergen Hoeller, James Strachan
See Also:
setConnectionFactory(javax.jms.QueueConnectionFactory), setQueue(javax.jms.Queue), setQueueName(java.lang.String), JmsInvokerServiceExporter, JmsInvokerProxyFactoryBean

Constructor Summary
JmsInvokerClientInterceptor()
           
 
Method Summary
 void afterPropertiesSet()
          Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
protected  RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation)
          Create a new RemoteInvocation object for the given AOP method invocation.
protected  Message createRequestMessage(Session session, RemoteInvocation invocation)
          Create the invoker request message.
protected  RemoteInvocationResult 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.
protected  RemoteInvocationResult extractInvocationResult(Message responseMessage)
          Extract the invocation result from the response message.
protected  QueueConnectionFactory getConnectionFactory()
          Return the QueueConnectionFactory to use for obtaining JMS QueueConnections.
 Object invoke(MethodInvocation methodInvocation)
           
protected  RemoteInvocationResult onInvalidResponse(Message responseMessage)
          Callback that is invoked by extractInvocationResult when it encounters an invalid response message.
protected  Object recreateRemoteInvocationResult(RemoteInvocationResult result)
          Recreate the invocation result contained in the given RemoteInvocationResult object.
protected  Queue resolveQueue(Session session)
          Resolve this accessor's target queue.
protected  Queue resolveQueueName(Session session, String queueName)
          Resolve the given queue name into a JMS Queue, via this accessor's DestinationResolver.
 void setConnectionFactory(QueueConnectionFactory connectionFactory)
          Set the QueueConnectionFactory to use for obtaining JMS QueueConnections.
 void setDestinationResolver(DestinationResolver destinationResolver)
          Set the DestinationResolver that is to be used to resolve Queue references for this accessor.
 void setQueue(Queue queue)
          Set the target Queue to send invoker requests to.
 void setQueueName(String queueName)
          Set the name of target queue to send invoker requests to.
 void setRemoteInvocationFactory(RemoteInvocationFactory remoteInvocationFactory)
          Set the RemoteInvocationFactory to use for this accessor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JmsInvokerClientInterceptor

public JmsInvokerClientInterceptor()
Method Detail

setConnectionFactory

public void setConnectionFactory(QueueConnectionFactory connectionFactory)
Set the QueueConnectionFactory to use for obtaining JMS QueueConnections.


getConnectionFactory

protected QueueConnectionFactory getConnectionFactory()
Return the QueueConnectionFactory to use for obtaining JMS QueueConnections.


setQueue

public void setQueue(Queue queue)
Set the target Queue to send invoker requests to.


setQueueName

public void setQueueName(String queueName)
Set the name of target queue to send invoker requests to.


setDestinationResolver

public void setDestinationResolver(DestinationResolver destinationResolver)
Set the DestinationResolver that is to be used to resolve Queue references for this accessor.

The default resolver is a DynamicDestinationResolver. Specify a JndiDestinationResolver for resolving destination names as JNDI locations.

Parameters:
destinationResolver - the DestinationResolver that is to be used
See Also:
DynamicDestinationResolver, JndiDestinationResolver

setRemoteInvocationFactory

public void setRemoteInvocationFactory(RemoteInvocationFactory remoteInvocationFactory)
Set the RemoteInvocationFactory to use for this accessor. Default is a DefaultRemoteInvocationFactory.

A custom invocation factory can add further context information to the invocation, for example user credentials.


afterPropertiesSet

public void afterPropertiesSet()
Description copied from interface: InitializingBean
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

Specified by:
afterPropertiesSet in interface InitializingBean

invoke

public Object invoke(MethodInvocation methodInvocation)
              throws Throwable
Specified by:
invoke in interface MethodInterceptor
Throws:
Throwable

createRemoteInvocation

protected RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation)
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
Returns:
the RemoteInvocation object
See Also:
RemoteInvocationFactory.createRemoteInvocation(org.aopalliance.intercept.MethodInvocation)

executeRequest

protected RemoteInvocationResult executeRequest(RemoteInvocation invocation)
                                         throws JMSException
Execute the given remote invocation, sending an invoker request message to this accessor's target queue and waiting for a corresponding response.

The default implementation is based on a JMS QueueRequestor, using a freshly obtained JMS Session.

Parameters:
invocation - the RemoteInvocation to execute
Returns:
the RemoteInvocationResult object
Throws:
JMSException - in case of JMS failure

resolveQueue

protected Queue resolveQueue(Session session)
                      throws JMSException
Resolve this accessor's target queue.

Parameters:
session - the current JMS Session
Returns:
the resolved target Queue
Throws:
JMSException - if resolution failed

resolveQueueName

protected Queue resolveQueueName(Session session,
                                 String queueName)
                          throws JMSException
Resolve the given queue name into a JMS Queue, via this accessor's DestinationResolver.

Parameters:
session - the current JMS Session
queueName - the name of the queue
Returns:
the located Queue
Throws:
JMSException - if resolution failed
See Also:
setDestinationResolver(org.springframework.jms.support.destination.DestinationResolver)

createRequestMessage

protected Message createRequestMessage(Session session,
                                       RemoteInvocation invocation)
                                throws JMSException
Create the invoker request message.

The default implementation creates a JMS ObjectMessage for the given RemoteInvocation object.

Parameters:
session - the current JMS Session
invocation - the remote invocation to send
Throws:
JMSException - if the message could not be created

extractInvocationResult

protected RemoteInvocationResult extractInvocationResult(Message responseMessage)
                                                  throws JMSException
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
Returns:
the invocation result
Throws:
JMSException - is thrown if a JMS exception occurs
See Also:
onInvalidResponse(javax.jms.Message)

onInvalidResponse

protected RemoteInvocationResult onInvalidResponse(Message responseMessage)
                                            throws JMSException
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
Returns:
an alternative invocation result that should be returned to the caller (if desired)
Throws:
JMSException - if the invalid response should lead to an infrastructure exception propagated to the caller
See Also:
extractInvocationResult(javax.jms.Message)

recreateRemoteInvocationResult

protected Object recreateRemoteInvocationResult(RemoteInvocationResult result)
                                         throws Throwable
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
Returns:
a return value if the invocation result is a successful return
Throws:
Throwable - if the invocation result is an exception
See Also:
RemoteInvocationResult.recreate()

The Spring Framework

Copyright © 2002-2007 The Spring Framework.