Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
60517b23
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,发现更多精彩内容 >>
提交
60517b23
编写于
1月 31, 2017
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
StompSession supports custom headers for UNSUBSCRIBE
Issue: SPR-15131
上级
949bb55e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
69 addition
and
22 deletion
+69
-22
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java
...ngframework/messaging/simp/stomp/DefaultStompSession.java
+27
-20
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSession.java
...rg/springframework/messaging/simp/stomp/StompSession.java
+13
-1
spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/DefaultStompSessionTests.java
...mework/messaging/simp/stomp/DefaultStompSessionTests.java
+29
-1
未找到文件。
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java
浏览文件 @
60517b23
...
...
@@ -291,8 +291,7 @@ public class DefaultStompSession implements ConnectionHandlingStompSession {
@Override
public
Subscription
subscribe
(
StompHeaders
stompHeaders
,
StompFrameHandler
handler
)
{
String
destination
=
stompHeaders
.
getDestination
();
Assert
.
hasText
(
destination
,
"Destination header is required"
);
Assert
.
hasText
(
stompHeaders
.
getDestination
(),
"Destination header is required"
);
Assert
.
notNull
(
handler
,
"StompFrameHandler must not be null"
);
String
subscriptionId
=
stompHeaders
.
getId
();
...
...
@@ -300,8 +299,8 @@ public class DefaultStompSession implements ConnectionHandlingStompSession {
subscriptionId
=
String
.
valueOf
(
DefaultStompSession
.
this
.
subscriptionIndex
.
getAndIncrement
());
stompHeaders
.
setId
(
subscriptionId
);
}
String
receiptId
=
checkOrAddReceipt
(
stompHeaders
);
Subscription
subscription
=
new
DefaultSubscription
(
s
ubscriptionId
,
destination
,
receiptId
,
handler
);
checkOrAddReceipt
(
stompHeaders
);
Subscription
subscription
=
new
DefaultSubscription
(
s
tompHeaders
,
handler
);
StompHeaderAccessor
accessor
=
createHeaderAccessor
(
StompCommand
.
SUBSCRIBE
);
accessor
.
addNativeHeaders
(
stompHeaders
);
...
...
@@ -333,8 +332,11 @@ public class DefaultStompSession implements ConnectionHandlingStompSession {
return
receiptable
;
}
private
void
unsubscribe
(
String
id
)
{
private
void
unsubscribe
(
String
id
,
StompHeaders
stompHeaders
)
{
StompHeaderAccessor
accessor
=
createHeaderAccessor
(
StompCommand
.
UNSUBSCRIBE
);
if
(
stompHeaders
!=
null
)
{
accessor
.
addNativeHeaders
(
stompHeaders
);
}
accessor
.
setSubscriptionId
(
id
);
Message
<
byte
[]>
message
=
createMessage
(
accessor
,
EMPTY_PAYLOAD
);
execute
(
message
);
...
...
@@ -600,29 +602,27 @@ public class DefaultStompSession implements ConnectionHandlingStompSession {
private
class
DefaultSubscription
extends
ReceiptHandler
implements
Subscription
{
private
final
String
id
;
private
final
String
destination
;
private
final
StompHeaders
headers
;
private
final
StompFrameHandler
handler
;
public
DefaultSubscription
(
St
ring
id
,
String
destination
,
String
receiptId
,
StompFrameHandler
handler
)
{
super
(
receiptId
);
Assert
.
notNull
(
destination
,
"Destination must not be null"
);
public
DefaultSubscription
(
St
ompHeaders
headers
,
StompFrameHandler
handler
)
{
super
(
headers
.
getReceipt
()
);
Assert
.
notNull
(
headers
.
getDestination
()
,
"Destination must not be null"
);
Assert
.
notNull
(
handler
,
"StompFrameHandler must not be null"
);
this
.
id
=
id
;
this
.
destination
=
destination
;
this
.
headers
=
headers
;
this
.
handler
=
handler
;
DefaultStompSession
.
this
.
subscriptions
.
put
(
id
,
this
);
DefaultStompSession
.
this
.
subscriptions
.
put
(
headers
.
getId
()
,
this
);
}
@Override
public
String
getSubscriptionId
()
{
return
this
.
id
;
return
this
.
headers
.
getId
()
;
}
public
String
getDestination
()
{
return
this
.
destination
;
@Override
public
StompHeaders
getSubscriptionHeaders
()
{
return
this
.
headers
;
}
public
StompFrameHandler
getHandler
()
{
...
...
@@ -631,13 +631,20 @@ public class DefaultStompSession implements ConnectionHandlingStompSession {
@Override
public
void
unsubscribe
()
{
DefaultStompSession
.
this
.
subscriptions
.
remove
(
getSubscriptionId
());
DefaultStompSession
.
this
.
unsubscribe
(
getSubscriptionId
());
unsubscribe
(
null
);
}
@Override
public
void
unsubscribe
(
StompHeaders
stompHeaders
)
{
String
id
=
this
.
headers
.
getId
();
DefaultStompSession
.
this
.
subscriptions
.
remove
(
id
);
DefaultStompSession
.
this
.
unsubscribe
(
id
,
stompHeaders
);
}
@Override
public
String
toString
()
{
return
"Subscription [id="
+
getSubscriptionId
()
+
", destination='"
+
getDestination
()
+
return
"Subscription [id="
+
getSubscriptionId
()
+
", destination='"
+
this
.
headers
.
getDestination
()
+
"', receiptId='"
+
getReceiptId
()
+
"', handler="
+
getHandler
()
+
"]"
;
}
}
...
...
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSession.java
浏览文件 @
60517b23
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -141,10 +141,22 @@ public interface StompSession {
*/
String
getSubscriptionId
();
/**
* Return the headers used on the SUBSCRIBE frame.
*/
StompHeaders
getSubscriptionHeaders
();
/**
* Remove the subscription by sending an UNSUBSCRIBE frame.
*/
void
unsubscribe
();
/**
* Alternative to {@link #unsubscribe()} with additional custom headers
* to send to the server.
* <p><strong>Note:</strong> There is no need to set the subscription id.
*/
void
unsubscribe
(
StompHeaders
stompHeaders
);
}
}
spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/DefaultStompSessionTests.java
浏览文件 @
60517b23
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -471,6 +471,34 @@ public class DefaultStompSessionTests {
assertEquals
(
subscription
.
getSubscriptionId
(),
stompHeaders
.
getId
());
}
@Test
// SPR-15131
public
void
unsubscribeWithCustomHeader
()
throws
Exception
{
this
.
session
.
afterConnected
(
this
.
connection
);
assertTrue
(
this
.
session
.
isConnected
());
String
headerName
=
"durable-subscription-name"
;
String
headerValue
=
"123"
;
StompHeaders
subscribeHeaders
=
new
StompHeaders
();
subscribeHeaders
.
setDestination
(
"/topic/foo"
);
subscribeHeaders
.
set
(
headerName
,
headerValue
);
StompFrameHandler
frameHandler
=
mock
(
StompFrameHandler
.
class
);
Subscription
subscription
=
this
.
session
.
subscribe
(
subscribeHeaders
,
frameHandler
);
StompHeaders
unsubscribeHeaders
=
new
StompHeaders
();
unsubscribeHeaders
.
set
(
headerName
,
subscription
.
getSubscriptionHeaders
().
getFirst
(
headerName
));
subscription
.
unsubscribe
(
unsubscribeHeaders
);
Message
<
byte
[]>
message
=
this
.
messageCaptor
.
getValue
();
StompHeaderAccessor
accessor
=
MessageHeaderAccessor
.
getAccessor
(
message
,
StompHeaderAccessor
.
class
);
assertEquals
(
StompCommand
.
UNSUBSCRIBE
,
accessor
.
getCommand
());
StompHeaders
stompHeaders
=
StompHeaders
.
readOnlyStompHeaders
(
accessor
.
getNativeHeaders
());
assertEquals
(
stompHeaders
.
toString
(),
2
,
stompHeaders
.
size
());
assertEquals
(
subscription
.
getSubscriptionId
(),
stompHeaders
.
getId
());
assertEquals
(
headerValue
,
stompHeaders
.
getFirst
(
headerName
));
}
@Test
public
void
ack
()
throws
Exception
{
this
.
session
.
afterConnected
(
this
.
connection
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录