Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
c64f3994
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 搜索 >>
提交
c64f3994
编写于
9月 26, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
36f7c7a1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
57 deletion
+52
-57
spring-beans/src/main/java/org/springframework/beans/factory/config/YamlMapFactoryBean.java
...ingframework/beans/factory/config/YamlMapFactoryBean.java
+2
-3
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/BufferingStompDecoder.java
...framework/messaging/simp/stomp/BufferingStompDecoder.java
+47
-52
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java
...rg/springframework/messaging/simp/stomp/StompEncoder.java
+3
-2
未找到文件。
spring-beans/src/main/java/org/springframework/beans/factory/config/YamlMapFactoryBean.java
浏览文件 @
c64f3994
...
...
@@ -108,15 +108,14 @@ public class YamlMapFactoryBean extends YamlProcessor implements FactoryBean<Map
/**
* Template method that subclasses may override to construct the object
* returned by this factory. The default implementation returns the
* merged Map instance.
* returned by this factory.
* <p>Invoked lazily the first time {@link #getObject()} is invoked in
* case of a shared singleton; else, on each {@link #getObject()} call.
* <p>The default implementation returns the merged {@code Map} instance.
* @return the object returned by this factory
* @see #process(java.util.Map, MatchCallback)
*/
protected
Map
<
String
,
Object
>
createMap
()
{
Map
<
String
,
Object
>
result
=
new
LinkedHashMap
<>();
process
((
properties
,
map
)
->
merge
(
result
,
map
));
return
result
;
...
...
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/BufferingStompDecoder.java
浏览文件 @
c64f3994
...
...
@@ -16,7 +16,6 @@
package
org.springframework.messaging.simp.stomp
;
import
java.nio.ByteBuffer
;
import
java.util.Collections
;
import
java.util.List
;
...
...
@@ -28,7 +27,6 @@ import org.springframework.util.Assert;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
/**
* An extension of {@link org.springframework.messaging.simp.stomp.StompDecoder}
* that buffers content remaining in the input ByteBuffer after the parent
...
...
@@ -45,6 +43,7 @@ import org.springframework.util.MultiValueMap;
*
* @author Rossen Stoyanchev
* @since 4.0.3
* @see StompDecoder
*/
public
class
BufferingStompDecoder
{
...
...
@@ -52,84 +51,63 @@ public class BufferingStompDecoder {
private
final
int
bufferSizeLimit
;
private
final
Queue
<
ByteBuffer
>
chunks
=
new
LinkedBlockingQueue
<>();
private
final
Queue
<
ByteBuffer
>
chunks
=
new
LinkedBlockingQueue
<
ByteBuffer
>();
private
volatile
Integer
expectedContentLength
;
/**
* Create a new {@code BufferingStompDecoder} wrapping the given {@code StompDecoder}.
* @param stompDecoder the target decoder to wrap
* @param bufferSizeLimit the buffer size limit
*/
public
BufferingStompDecoder
(
StompDecoder
stompDecoder
,
int
bufferSizeLimit
)
{
Assert
.
notNull
(
stompDecoder
,
"
'stompDecoder'
is required"
);
Assert
.
isTrue
(
bufferSizeLimit
>
0
,
"Buffer size must be greater than 0"
);
Assert
.
notNull
(
stompDecoder
,
"
StompDecoder
is required"
);
Assert
.
isTrue
(
bufferSizeLimit
>
0
,
"Buffer size
limit
must be greater than 0"
);
this
.
stompDecoder
=
stompDecoder
;
this
.
bufferSizeLimit
=
bufferSizeLimit
;
}
/**
* Return the wrapped
* {@link org.springframework.messaging.simp.stomp.StompDecoder}.
* Return the wrapped {@link StompDecoder}.
*/
public
StompDecoder
getStompDecoder
()
{
public
final
StompDecoder
getStompDecoder
()
{
return
this
.
stompDecoder
;
}
/**
* Return the configured buffer size limit.
*/
public
int
getBufferSizeLimit
()
{
public
final
int
getBufferSizeLimit
()
{
return
this
.
bufferSizeLimit
;
}
/**
* Calculate the current buffer size.
*/
public
int
getBufferSize
()
{
int
size
=
0
;
for
(
ByteBuffer
buffer
:
this
.
chunks
)
{
size
=
size
+
buffer
.
remaining
();
}
return
size
;
}
/**
* Get the expected content length of the currently buffered, incomplete STOMP frame.
*/
public
Integer
getExpectedContentLength
()
{
return
this
.
expectedContentLength
;
}
/**
* Decodes one or more STOMP frames from the given {@code ByteBuffer} into a
* list of {@link Message}s.
*
* <p>If there was enough data to parse a "content-length" header, then the
* value is used to determine how much more data is needed before a new
* attempt to decode is made.
*
* <p>If there was not enough data to parse the "content-length", or if there
* is "content-length" header, every subsequent call to decode attempts to
* parse again with all available data. Therefore the presence of a "content-length"
* header helps to optimize the decoding of large messages.
*
* @param newBuffer a buffer containing new data to decode
*
* @return decoded messages or an empty list
* @throws StompConversionException raised in case of decoding issues
*/
public
List
<
Message
<
byte
[]>>
decode
(
ByteBuffer
newBuffer
)
{
this
.
chunks
.
add
(
newBuffer
);
checkBufferLimits
();
if
(
getExpectedContentLength
()
!=
null
&&
getBufferSize
()
<
this
.
expectedContentLength
)
{
return
Collections
.
<
Message
<
byte
[]>>
emptyList
();
if
(
this
.
expectedContentLength
!=
null
&&
getBufferSize
()
<
this
.
expectedContentLength
)
{
return
Collections
.
emptyList
();
}
ByteBuffer
bufferToDecode
=
assembleChunksAndReset
();
MultiValueMap
<
String
,
String
>
headers
=
new
LinkedMultiValueMap
<>();
MultiValueMap
<
String
,
String
>
headers
=
new
LinkedMultiValueMap
<
String
,
String
>();
List
<
Message
<
byte
[]>>
messages
=
this
.
stompDecoder
.
decode
(
bufferToDecode
,
headers
);
if
(
bufferToDecode
.
hasRemaining
())
{
...
...
@@ -140,21 +118,6 @@ public class BufferingStompDecoder {
return
messages
;
}
private
void
checkBufferLimits
()
{
if
(
getExpectedContentLength
()
!=
null
)
{
if
(
getExpectedContentLength
()
>
getBufferSizeLimit
())
{
throw
new
StompConversionException
(
"The 'content-length' header "
+
getExpectedContentLength
()
+
" exceeds the configured message buffer size limit "
+
getBufferSizeLimit
());
}
}
if
(
getBufferSize
()
>
getBufferSizeLimit
())
{
throw
new
StompConversionException
(
"The configured stomp frame buffer size limit of "
+
getBufferSizeLimit
()
+
" bytes has been exceeded"
);
}
}
private
ByteBuffer
assembleChunksAndReset
()
{
ByteBuffer
result
;
if
(
this
.
chunks
.
size
()
==
1
)
{
...
...
@@ -172,4 +135,36 @@ public class BufferingStompDecoder {
return
result
;
}
private
void
checkBufferLimits
()
{
if
(
this
.
expectedContentLength
!=
null
)
{
if
(
this
.
expectedContentLength
>
this
.
bufferSizeLimit
)
{
throw
new
StompConversionException
(
"STOMP 'content-length' header value "
+
this
.
expectedContentLength
+
" exceeds configured buffer size limit "
+
this
.
bufferSizeLimit
);
}
}
if
(
getBufferSize
()
>
this
.
bufferSizeLimit
)
{
throw
new
StompConversionException
(
"The configured STOMP buffer size limit of "
+
this
.
bufferSizeLimit
+
" bytes has been exceeded"
);
}
}
/**
* Calculate the current buffer size.
*/
public
int
getBufferSize
()
{
int
size
=
0
;
for
(
ByteBuffer
buffer
:
this
.
chunks
)
{
size
=
size
+
buffer
.
remaining
();
}
return
size
;
}
/**
* Get the expected content length of the currently buffered, incomplete STOMP frame.
*/
public
Integer
getExpectedContentLength
()
{
return
this
.
expectedContentLength
;
}
}
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java
浏览文件 @
c64f3994
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -40,8 +40,9 @@ import org.springframework.util.Assert;
* @author Andy Wilkinson
* @author Rossen Stoyanchev
* @since 4.0
* @see StompDecoder
*/
public
final
class
StompEncoder
{
public
class
StompEncoder
{
private
static
final
byte
LF
=
'\n'
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录