Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
53a244d4
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
53a244d4
编写于
12月 09, 2011
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
JmsInvokerClientInterceptor/FactoryBean always uses createConnection/createSession when on JMS 1.1
上级
8213d0cb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
36 deletion
+27
-36
org.springframework.jms/src/main/java/org/springframework/jms/remoting/JmsInvokerClientInterceptor.java
...ngframework/jms/remoting/JmsInvokerClientInterceptor.java
+23
-31
org.springframework.jms/src/test/java/org/springframework/jms/remoting/JmsInvokerTests.java
...ava/org/springframework/jms/remoting/JmsInvokerTests.java
+4
-5
未找到文件。
org.springframework.jms/src/main/java/org/springframework/jms/remoting/JmsInvokerClientInterceptor.java
浏览文件 @
53a244d4
/*
/*
* Copyright 2002-20
07
the original author or authors.
* Copyright 2002-20
11
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -48,6 +48,7 @@ import org.springframework.remoting.support.DefaultRemoteInvocationFactory;
...
@@ -48,6 +48,7 @@ import org.springframework.remoting.support.DefaultRemoteInvocationFactory;
import
org.springframework.remoting.support.RemoteInvocation
;
import
org.springframework.remoting.support.RemoteInvocation
;
import
org.springframework.remoting.support.RemoteInvocationFactory
;
import
org.springframework.remoting.support.RemoteInvocationFactory
;
import
org.springframework.remoting.support.RemoteInvocationResult
;
import
org.springframework.remoting.support.RemoteInvocationResult
;
import
org.springframework.util.ClassUtils
;
/**
/**
* {@link org.aopalliance.intercept.MethodInterceptor} for accessing a
* {@link org.aopalliance.intercept.MethodInterceptor} for accessing a
...
@@ -74,6 +75,8 @@ import org.springframework.remoting.support.RemoteInvocationResult;
...
@@ -74,6 +75,8 @@ import org.springframework.remoting.support.RemoteInvocationResult;
*/
*/
public
class
JmsInvokerClientInterceptor
implements
MethodInterceptor
,
InitializingBean
{
public
class
JmsInvokerClientInterceptor
implements
MethodInterceptor
,
InitializingBean
{
private
static
final
boolean
jms11Available
=
ClassUtils
.
hasMethod
(
ConnectionFactory
.
class
,
"createConnection"
);
private
ConnectionFactory
connectionFactory
;
private
ConnectionFactory
connectionFactory
;
private
Object
queue
;
private
Object
queue
;
...
@@ -193,7 +196,7 @@ public class JmsInvokerClientInterceptor implements MethodInterceptor, Initializ
...
@@ -193,7 +196,7 @@ public class JmsInvokerClientInterceptor implements MethodInterceptor, Initializ
}
}
RemoteInvocation
invocation
=
createRemoteInvocation
(
methodInvocation
);
RemoteInvocation
invocation
=
createRemoteInvocation
(
methodInvocation
);
RemoteInvocationResult
result
=
null
;
RemoteInvocationResult
result
;
try
{
try
{
result
=
executeRequest
(
invocation
);
result
=
executeRequest
(
invocation
);
}
}
...
@@ -255,39 +258,27 @@ public class JmsInvokerClientInterceptor implements MethodInterceptor, Initializ
...
@@ -255,39 +258,27 @@ public class JmsInvokerClientInterceptor implements MethodInterceptor, Initializ
}
}
/**
/**
* Create a new JMS Connection for this JMS invoker,
* Create a new JMS Connection for this JMS invoker.
* ideally a <code>javax.jms.QueueConnection</code>.
* <p>The default implementation uses the
* <code>javax.jms.QueueConnectionFactory</code> API if available,
* falling back to a standard JMS 1.1 ConnectionFactory otherwise.
* This is necessary for working with generic JMS 1.1 connection pools
* (such as ActiveMQ's <code>org.apache.activemq.pool.PooledConnectionFactory</code>).
*/
*/
protected
Connection
createConnection
()
throws
JMSException
{
protected
Connection
createConnection
()
throws
JMSException
{
ConnectionFactory
cf
=
getConnectionFactory
();
ConnectionFactory
cf
=
getConnectionFactory
();
if
(
cf
instanceof
QueueConnectionFactory
)
{
if
(
jms11Available
)
{
return
((
QueueConnectionFactory
)
cf
).
createQueu
eConnection
();
return
cf
.
creat
eConnection
();
}
}
else
{
else
{
return
cf
.
creat
eConnection
();
return
((
QueueConnectionFactory
)
cf
).
createQueu
eConnection
();
}
}
}
}
/**
/**
* Create a new JMS Session for this JMS invoker,
* Create a new JMS Session for this JMS invoker.
* ideally a <code>javax.jms.QueueSession</code>.
* <p>The default implementation uses the
* <code>javax.jms.QueueConnection</code> API if available,
* falling back to a standard JMS 1.1 Connection otherwise.
* This is necessary for working with generic JMS 1.1 connection pools
* (such as ActiveMQ's <code>org.apache.activemq.pool.PooledConnectionFactory</code>).
*/
*/
protected
Session
createSession
(
Connection
con
)
throws
JMSException
{
protected
Session
createSession
(
Connection
con
)
throws
JMSException
{
if
(
con
instanceof
QueueConnection
)
{
if
(
jms11Available
)
{
return
((
QueueConnection
)
con
).
createQueu
eSession
(
false
,
Session
.
AUTO_ACKNOWLEDGE
);
return
con
.
creat
eSession
(
false
,
Session
.
AUTO_ACKNOWLEDGE
);
}
}
else
{
else
{
return
con
.
creat
eSession
(
false
,
Session
.
AUTO_ACKNOWLEDGE
);
return
((
QueueConnection
)
con
).
createQueu
eSession
(
false
,
Session
.
AUTO_ACKNOWLEDGE
);
}
}
}
}
...
@@ -352,8 +343,17 @@ public class JmsInvokerClientInterceptor implements MethodInterceptor, Initializ
...
@@ -352,8 +343,17 @@ public class JmsInvokerClientInterceptor implements MethodInterceptor, Initializ
MessageProducer
producer
=
null
;
MessageProducer
producer
=
null
;
MessageConsumer
consumer
=
null
;
MessageConsumer
consumer
=
null
;
try
{
try
{
if
(
session
instanceof
QueueSession
)
{
if
(
jms11Available
)
{
// Standard JMS 1.1 API usage...
responseQueue
=
session
.
createTemporaryQueue
();
producer
=
session
.
createProducer
(
queue
);
consumer
=
session
.
createConsumer
(
responseQueue
);
requestMessage
.
setJMSReplyTo
(
responseQueue
);
producer
.
send
(
requestMessage
);
}
else
{
// Perform all calls on QueueSession reference for JMS 1.0.2 compatibility...
// Perform all calls on QueueSession reference for JMS 1.0.2 compatibility...
// DEPRECATED but kept around with the deprecated JmsTemplate102 etc classes for the time being.
QueueSession
queueSession
=
(
QueueSession
)
session
;
QueueSession
queueSession
=
(
QueueSession
)
session
;
responseQueue
=
queueSession
.
createTemporaryQueue
();
responseQueue
=
queueSession
.
createTemporaryQueue
();
QueueSender
sender
=
queueSession
.
createSender
(
queue
);
QueueSender
sender
=
queueSession
.
createSender
(
queue
);
...
@@ -362,14 +362,6 @@ public class JmsInvokerClientInterceptor implements MethodInterceptor, Initializ
...
@@ -362,14 +362,6 @@ public class JmsInvokerClientInterceptor implements MethodInterceptor, Initializ
requestMessage
.
setJMSReplyTo
(
responseQueue
);
requestMessage
.
setJMSReplyTo
(
responseQueue
);
sender
.
send
(
requestMessage
);
sender
.
send
(
requestMessage
);
}
}
else
{
// Standard JMS 1.1 API usage...
responseQueue
=
session
.
createTemporaryQueue
();
producer
=
session
.
createProducer
(
queue
);
consumer
=
session
.
createConsumer
(
responseQueue
);
requestMessage
.
setJMSReplyTo
(
responseQueue
);
producer
.
send
(
requestMessage
);
}
long
timeout
=
getReceiveTimeout
();
long
timeout
=
getReceiveTimeout
();
return
(
timeout
>
0
?
consumer
.
receive
(
timeout
)
:
consumer
.
receive
());
return
(
timeout
>
0
?
consumer
.
receive
(
timeout
)
:
consumer
.
receive
());
}
}
...
...
org.springframework.jms/src/test/java/org/springframework/jms/remoting/JmsInvokerTests.java
浏览文件 @
53a244d4
/*
/*
* Copyright 2002-20
07
the original author or authors.
* Copyright 2002-20
11
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -19,7 +19,6 @@ package org.springframework.jms.remoting;
...
@@ -19,7 +19,6 @@ package org.springframework.jms.remoting;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Enumeration
;
import
java.util.Enumeration
;
import
javax.jms.Destination
;
import
javax.jms.Destination
;
import
javax.jms.JMSException
;
import
javax.jms.JMSException
;
import
javax.jms.Message
;
import
javax.jms.Message
;
...
@@ -70,10 +69,10 @@ public class JmsInvokerTests extends TestCase {
...
@@ -70,10 +69,10 @@ public class JmsInvokerTests extends TestCase {
queueControl
=
MockControl
.
createControl
(
Queue
.
class
);
queueControl
=
MockControl
.
createControl
(
Queue
.
class
);
mockQueue
=
(
Queue
)
queueControl
.
getMock
();
mockQueue
=
(
Queue
)
queueControl
.
getMock
();
mockConnectionFactory
.
create
Queue
Connection
();
mockConnectionFactory
.
createConnection
();
connectionFactoryControl
.
setReturnValue
(
mockConnection
,
8
);
connectionFactoryControl
.
setReturnValue
(
mockConnection
,
8
);
mockConnection
.
create
Queue
Session
(
false
,
Session
.
AUTO_ACKNOWLEDGE
);
mockConnection
.
createSession
(
false
,
Session
.
AUTO_ACKNOWLEDGE
);
connectionControl
.
setReturnValue
(
mockSession
,
8
);
connectionControl
.
setReturnValue
(
mockSession
,
8
);
mockConnection
.
start
();
mockConnection
.
start
();
...
@@ -409,6 +408,6 @@ public class JmsInvokerTests extends TestCase {
...
@@ -409,6 +408,6 @@ public class JmsInvokerTests extends TestCase {
public
Message
toMessage
(
Object
object
,
Session
session
)
throws
JMSException
,
MessageConversionException
{
public
Message
toMessage
(
Object
object
,
Session
session
)
throws
JMSException
,
MessageConversionException
{
return
new
MockObjectMessage
((
Serializable
)
object
);
return
new
MockObjectMessage
((
Serializable
)
object
);
}
}
}
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录