类 JmsInvokerClientInterceptor
- java.lang.Object
- org.springframework.jms.remoting.JmsInvokerClientInterceptor
- 所有已实现的接口:
Advice
,Interceptor
,MethodInterceptor
,InitializingBean
- 直接已知子类:
JmsInvokerProxyFactoryBean
public class JmsInvokerClientInterceptor extends Object implements MethodInterceptor, InitializingBean
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
QueueConnectionFactory
and a target queue (either asQueue
reference or as queue name).Thanks to James Strachan for the original prototype that this JMS invoker mechanism was inspired by!
- 从以下版本开始:
- 2.0
- 作者:
- Juergen Hoeller, James Strachan, Stephane Nicoll
- 另请参阅:
setConnectionFactory(javax.jms.ConnectionFactory)
,setQueue(javax.jms.Queue)
,setQueueName(java.lang.String)
,JmsInvokerServiceExporter
,JmsInvokerProxyFactoryBean
构造器概要
构造器 构造器 说明 JmsInvokerClientInterceptor()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.protected RemoteAccessException
convertJmsInvokerAccessException(JMSException ex)
Convert the given JMS invoker access exception to an appropriate SpringRemoteAccessException
.protected Connection
createConnection()
Create a new JMS Connection for this JMS invoker.protected RemoteInvocation
createRemoteInvocation(MethodInvocation methodInvocation)
Create a newRemoteInvocation
object for the given AOP method invocation.protected Message
createRequestMessage(Session session, RemoteInvocation invocation)
Create the invoker request message.protected Session
createSession(Connection con)
Create a new JMS Session for this JMS invoker.protected Message
doExecuteRequest(Session 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.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 ConnectionFactory
getConnectionFactory()
Return the QueueConnectionFactory to use for obtaining JMS QueueConnections.protected long
getReceiveTimeout()
Return the timeout to use for receiving the response message for a request (in milliseconds).Object
invoke(MethodInvocation methodInvocation)
Implement this method to perform extra treatments before and after the invocation.protected RemoteInvocationResult
onInvalidResponse(Message responseMessage)
Callback that is invoked byextractInvocationResult(javax.jms.Message)
when it encounters an invalid response message.protected RemoteInvocationResult
onReceiveTimeout(RemoteInvocation invocation)
Callback that is invoked byexecuteRequest(org.springframework.remoting.support.RemoteInvocation)
when the receive timeout has expired for the specifiedRemoteInvocation
.protected Object
recreateRemoteInvocationResult(RemoteInvocationResult result)
Recreate the invocation result contained in the givenRemoteInvocationResult
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 JMSQueue
, via this accessor'sDestinationResolver
.void
setConnectionFactory(ConnectionFactory 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
setMessageConverter(MessageConverter messageConverter)
Specify theMessageConverter
to use for turningRemoteInvocation
objects into request messages, as well as response messages intoRemoteInvocationResult
objects.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
setReceiveTimeout(long receiveTimeout)
Set the timeout to use for receiving the response message for a request (in milliseconds).void
setRemoteInvocationFactory(RemoteInvocationFactory remoteInvocationFactory)
Set theRemoteInvocationFactory
to use for this accessor.
构造器详细资料
JmsInvokerClientInterceptor
public JmsInvokerClientInterceptor()
方法详细资料
setConnectionFactory
public void setConnectionFactory(ConnectionFactory connectionFactory)
Set the QueueConnectionFactory to use for obtaining JMS QueueConnections.
getConnectionFactory
protected ConnectionFactory getConnectionFactory()
Return the QueueConnectionFactory to use for obtaining JMS QueueConnections.
setQueueName
public void setQueueName(String queueName)
Set the name of target queue to send invoker requests to.The specified name will be dynamically resolved via the
DestinationResolver
.
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 aJndiDestinationResolver
for resolving destination names as JNDI locations.
setRemoteInvocationFactory
public void setRemoteInvocationFactory(RemoteInvocationFactory remoteInvocationFactory)
Set theRemoteInvocationFactory
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.
setMessageConverter
public void setMessageConverter(MessageConverter messageConverter)
Specify theMessageConverter
to use for turningRemoteInvocation
objects into request messages, as well as response messages intoRemoteInvocationResult
objects.Default is a
SimpleMessageConverter
, using a standard JMSObjectMessage
for each invocation / invocation result object.Custom implementations may generally adapt
Serializable
objects into special kinds of messages, or might be specifically tailored for translatingRemoteInvocation(Result)s
into specific kinds of messages.
setReceiveTimeout
public void setReceiveTimeout(long receiveTimeout)
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.
getReceiveTimeout
protected long getReceiveTimeout()
Return the timeout to use for receiving the response message for a request (in milliseconds).
afterPropertiesSet
public void afterPropertiesSet()
从接口复制的说明:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,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
在接口中InitializingBean
invoke
public Object invoke(MethodInvocation methodInvocation) throws Throwable
从接口复制的说明:MethodInterceptor
Implement this method to perform extra treatments before and after the invocation. Polite implementations would certainly like to invokeJoinpoint.proceed()
.- 指定者:
invoke
在接口中MethodInterceptor
- 参数:
methodInvocation
- the method invocation joinpoint- 返回:
- the result of the call to
Joinpoint.proceed()
; might be intercepted by the interceptor - 抛出:
Throwable
- if the interceptors or the target object throws an exception
createRemoteInvocation
protected RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation)
Create a newRemoteInvocation
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 customRemoteInvocationFactory
which is a reusable strategy.- 参数:
methodInvocation
- the current AOP method invocation- 返回:
- the RemoteInvocation object
- 另请参阅:
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.- 参数:
invocation
- the RemoteInvocation to execute- 返回:
- the RemoteInvocationResult object
- 抛出:
JMSException
- in case of JMS failure- 另请参阅:
doExecuteRequest(javax.jms.Session, javax.jms.Queue, javax.jms.Message)
createConnection
protected Connection createConnection() throws JMSException
Create a new JMS Connection for this JMS invoker.- 抛出:
JMSException
createSession
protected Session createSession(Connection con) throws JMSException
Create a new JMS Session for this JMS invoker.- 抛出:
JMSException
resolveQueue
protected Queue resolveQueue(Session session) throws JMSException
Resolve this accessor's target queue.- 参数:
session
- the current JMS Session- 返回:
- the resolved target Queue
- 抛出:
JMSException
- if resolution failed
resolveQueueName
protected Queue resolveQueueName(Session session, String queueName) throws JMSException
Resolve the given queue name into a JMSQueue
, via this accessor'sDestinationResolver
.- 参数:
session
- the current JMS SessionqueueName
- the name of the queue- 返回:
- the located Queue
- 抛出:
JMSException
- if resolution failed- 另请参阅:
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.- 参数:
session
- the current JMS Sessioninvocation
- the remote invocation to send- 返回:
- the JMS Message to send
- 抛出:
JMSException
- if the message could not be created
doExecuteRequest
protected Message doExecuteRequest(Session session, Queue queue, Message requestMessage) throws JMSException
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
TemporaryQueue
for receiving the response.- 参数:
session
- the JMS Session to usequeue
- the resolved target Queue to send torequestMessage
- the JMS Message to send- 返回:
- the RemoteInvocationResult object
- 抛出:
JMSException
- in case of JMS failure
extractInvocationResult
protected RemoteInvocationResult extractInvocationResult(Message responseMessage) throws JMSException
Extract the invocation result from the response message.The default implementation expects a JMS
ObjectMessage
carrying aRemoteInvocationResult
object. If an invalid response message is encountered, theonInvalidResponse
callback gets invoked.- 参数:
responseMessage
- the response message- 返回:
- the invocation result
- 抛出:
JMSException
- is thrown if a JMS exception occurs- 另请参阅:
onInvalidResponse(javax.jms.Message)
onReceiveTimeout
protected RemoteInvocationResult onReceiveTimeout(RemoteInvocation invocation)
Callback that is invoked byexecuteRequest(org.springframework.remoting.support.RemoteInvocation)
when the receive timeout has expired for the specifiedRemoteInvocation
.By default, an
RemoteTimeoutException
is thrown. Sub-classes can choose to either throw a more dedicated exception or even return a defaultRemoteInvocationResult
as a fallback.- 参数:
invocation
- the invocation- 返回:
- a default result when the receive timeout has expired
onInvalidResponse
protected RemoteInvocationResult onInvalidResponse(Message responseMessage) throws JMSException
Callback that is invoked byextractInvocationResult(javax.jms.Message)
when it encounters an invalid response message.The default implementation throws a
MessageFormatException
.- 参数:
responseMessage
- the invalid response message- 返回:
- an alternative invocation result that should be returned to the caller (if desired)
- 抛出:
JMSException
- if the invalid response should lead to an infrastructure exception propagated to the caller- 另请参阅:
extractInvocationResult(javax.jms.Message)
recreateRemoteInvocationResult
protected Object recreateRemoteInvocationResult(RemoteInvocationResult result) throws Throwable
Recreate the invocation result contained in the givenRemoteInvocationResult
object.The default implementation calls the default
recreate()
method.Can be overridden in subclasses to provide custom recreation, potentially processing the returned result object.
- 参数:
result
- the RemoteInvocationResult to recreate- 返回:
- a return value if the invocation result is a successful return
- 抛出:
Throwable
- if the invocation result is an exception- 另请参阅:
RemoteInvocationResult.recreate()
convertJmsInvokerAccessException
protected RemoteAccessException convertJmsInvokerAccessException(JMSException ex)
Convert the given JMS invoker access exception to an appropriate SpringRemoteAccessException
.- 参数:
ex
- the exception to convert- 返回:
- the RemoteAccessException to throw