Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
75439c78
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 搜索 >>
提交
75439c78
编写于
3月 27, 2014
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish
上级
e3ef3fff
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
21 addition
and
29 deletion
+21
-29
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompCommand.java
...rg/springframework/messaging/simp/stomp/StompCommand.java
+5
-0
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java
...rg/springframework/messaging/simp/stomp/StompEncoder.java
+16
-29
未找到文件。
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompCommand.java
浏览文件 @
75439c78
...
...
@@ -52,6 +52,7 @@ public enum StompCommand {
private
static
Collection
<
StompCommand
>
destinationRequired
=
Arrays
.
asList
(
SEND
,
SUBSCRIBE
,
MESSAGE
);
private
static
Collection
<
StompCommand
>
subscriptionIdRequired
=
Arrays
.
asList
(
SUBSCRIBE
,
UNSUBSCRIBE
,
MESSAGE
);
private
static
Collection
<
StompCommand
>
contentLengthRequired
=
Arrays
.
asList
(
SEND
,
MESSAGE
,
ERROR
);
private
static
Collection
<
StompCommand
>
bodyAllowed
=
Arrays
.
asList
(
SEND
,
MESSAGE
,
ERROR
);
static
{
...
...
@@ -77,6 +78,10 @@ public enum StompCommand {
return
subscriptionIdRequired
.
contains
(
this
);
}
public
boolean
requiresContentLength
()
{
return
contentLengthRequired
.
contains
(
this
);
}
public
boolean
isBodyAllowed
()
{
return
bodyAllowed
.
contains
(
this
);
}
...
...
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java
浏览文件 @
75439c78
...
...
@@ -55,19 +55,21 @@ public final class StompEncoder {
*/
public
byte
[]
encode
(
Message
<
byte
[]>
message
)
{
try
{
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
(
256
);
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
(
128
+
message
.
getPayload
().
length
);
DataOutputStream
output
=
new
DataOutputStream
(
baos
);
StompHeaderAccessor
headers
=
StompHeaderAccessor
.
wrap
(
message
);
if
(
isHeartbeat
(
headers
))
{
if
(
SimpMessageType
.
HEARTBEAT
==
headers
.
getMessageType
())
{
logger
.
trace
(
"Encoded heartbeat"
);
output
.
write
(
message
.
getPayload
());
}
else
{
writeCommand
(
headers
,
output
);
output
.
write
(
headers
.
getCommand
().
toString
().
getBytes
(
UTF8_CHARSET
));
output
.
write
(
LF
);
writeHeaders
(
headers
,
message
,
output
);
output
.
write
(
LF
);
writeBody
(
message
,
output
);
output
.
write
((
byte
)
0
);
output
.
write
((
byte
)
0
);
}
return
baos
.
toByteArray
();
...
...
@@ -77,38 +79,27 @@ public final class StompEncoder {
}
}
private
boolean
isHeartbeat
(
StompHeaderAccessor
headers
)
{
return
(
headers
.
getMessageType
()
==
SimpMessageType
.
HEARTBEAT
);
}
private
void
writeCommand
(
StompHeaderAccessor
headers
,
DataOutputStream
output
)
throws
IOException
{
output
.
write
(
headers
.
getCommand
().
toString
().
getBytes
(
UTF8_CHARSET
));
output
.
write
(
LF
);
}
private
void
writeHeaders
(
StompHeaderAccessor
headers
,
Message
<
byte
[]>
message
,
DataOutputStream
output
)
throws
IOException
{
StompCommand
command
=
headers
.
getCommand
();
Map
<
String
,
List
<
String
>>
stompHeaders
=
headers
.
toStompHeaderMap
();
if
(
SimpMessageType
.
HEARTBEAT
.
equals
(
headers
.
getMessageType
()))
{
logger
.
trace
(
"Encoded heartbeat"
);
}
else
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Encoded STOMP command="
+
headers
.
getCommand
()
+
" headers="
+
stompHeaders
);
boolean
shouldEscape
=
(
command
!=
StompCommand
.
CONNECT
&&
command
!=
StompCommand
.
CONNECTED
);
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Encoded STOMP "
+
command
+
", headers="
+
stompHeaders
);
}
boolean
escapeHeaders
=
shouldEscapeHeaders
(
headers
);
for
(
Entry
<
String
,
List
<
String
>>
entry
:
stompHeaders
.
entrySet
())
{
byte
[]
key
=
toUtf8Bytes
(
entry
.
getKey
(),
escapeHeaders
);
byte
[]
key
=
encodeHeaderString
(
entry
.
getKey
(),
shouldEscape
);
for
(
String
value
:
entry
.
getValue
())
{
output
.
write
(
key
);
output
.
write
(
COLON
);
output
.
write
(
toUtf8Bytes
(
value
,
escapeHeaders
));
output
.
write
(
encodeHeaderString
(
value
,
shouldEscape
));
output
.
write
(
LF
);
}
}
if
((
headers
.
getCommand
()
==
StompCommand
.
SEND
)
||
(
headers
.
getCommand
()
==
StompCommand
.
MESSAGE
)
||
(
headers
.
getCommand
()
==
StompCommand
.
ERROR
))
{
if
(
command
.
requiresContentLength
())
{
int
contentLength
=
message
.
getPayload
().
length
;
output
.
write
(
"content-length:"
.
getBytes
(
UTF8_CHARSET
));
output
.
write
(
Integer
.
toString
(
contentLength
).
getBytes
(
UTF8_CHARSET
));
...
...
@@ -116,11 +107,7 @@ public final class StompEncoder {
}
}
private
boolean
shouldEscapeHeaders
(
StompHeaderAccessor
headers
)
{
return
(
headers
.
getCommand
()
!=
StompCommand
.
CONNECT
&&
headers
.
getCommand
()
!=
StompCommand
.
CONNECTED
);
}
private
byte
[]
toUtf8Bytes
(
String
input
,
boolean
escape
)
{
private
byte
[]
encodeHeaderString
(
String
input
,
boolean
escape
)
{
input
=
escape
?
escape
(
input
)
:
input
;
return
input
.
getBytes
(
UTF8_CHARSET
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录