Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
47ef45d1
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 搜索 >>
提交
47ef45d1
编写于
12月 02, 2013
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish websocket xml namespace
Issue: SPR-11063
上级
92e144a8
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
54 addition
and
25 deletion
+54
-25
spring-messaging/src/main/java/org/springframework/messaging/simp/handler/DefaultUserDestinationResolver.java
...essaging/simp/handler/DefaultUserDestinationResolver.java
+7
-0
spring-websocket/src/main/java/org/springframework/web/socket/messaging/config/xml/MessageBrokerBeanDefinitionParser.java
...ssaging/config/xml/MessageBrokerBeanDefinitionParser.java
+27
-21
spring-websocket/src/main/resources/org/springframework/web/socket/server/config/xml/spring-websocket-4.0.xsd
...ork/web/socket/server/config/xml/spring-websocket-4.0.xsd
+1
-1
spring-websocket/src/test/java/org/springframework/web/socket/messaging/config/xml/MessageBrokerBeanDefinitionParserTests.java
...ng/config/xml/MessageBrokerBeanDefinitionParserTests.java
+16
-1
spring-websocket/src/test/java/org/springframework/web/socket/server/config/xml/HandlersBeanDefinitionParserTests.java
.../server/config/xml/HandlersBeanDefinitionParserTests.java
+2
-1
spring-websocket/src/test/resources/org/springframework/web/socket/messaging/config/xml/websocket-config-broker-simple.xml
...t/messaging/config/xml/websocket-config-broker-simple.xml
+1
-1
未找到文件。
spring-messaging/src/main/java/org/springframework/messaging/simp/handler/DefaultUserDestinationResolver.java
浏览文件 @
47ef45d1
...
...
@@ -90,6 +90,13 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver {
return
this
.
subscriptionDestinationPrefix
;
}
/**
* Return the configured {@link UserSessionRegistry}.
*/
public
UserSessionRegistry
getUserSessionRegistry
()
{
return
this
.
userSessionRegistry
;
}
@Override
public
Set
<
String
>
resolveDestination
(
Message
<?>
message
)
{
...
...
spring-websocket/src/main/java/org/springframework/web/socket/messaging/config/xml/MessageBrokerBeanDefinitionParser.java
浏览文件 @
47ef45d1
...
...
@@ -41,6 +41,7 @@ import org.springframework.messaging.support.converter.DefaultContentTypeResolve
import
org.springframework.messaging.support.converter.MappingJackson2MessageConverter
;
import
org.springframework.messaging.support.converter.StringMessageConverter
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.MimeTypeUtils
;
import
org.springframework.util.StringUtils
;
...
...
@@ -111,41 +112,45 @@ public class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
handlerMappingDef
.
getPropertyValues
().
add
(
"order"
,
order
);
handlerMappingDef
.
getPropertyValues
().
add
(
"urlMap"
,
urlMap
);
String
channel
Name
=
"clientInboundChannel"
;
String
bean
Name
=
"clientInboundChannel"
;
Element
channelElem
=
DomUtils
.
getChildElementByTagName
(
element
,
"client-inbound-channel"
);
RuntimeBeanReference
clientInChannel
=
getMessageChannel
(
channel
Name
,
channelElem
,
parserCxt
,
source
);
RuntimeBeanReference
clientInChannel
=
getMessageChannel
(
bean
Name
,
channelElem
,
parserCxt
,
source
);
channel
Name
=
"clientOutboundChannel"
;
bean
Name
=
"clientOutboundChannel"
;
channelElem
=
DomUtils
.
getChildElementByTagName
(
element
,
"client-outbound-channel"
);
RuntimeBeanReference
clientOutChannel
=
getMessageChannel
(
channel
Name
,
channelElem
,
parserCxt
,
source
);
RuntimeBeanReference
clientOutChannel
=
getMessageChannel
(
bean
Name
,
channelElem
,
parserCxt
,
source
);
RootBeanDefinition
userSessionRegistry
Def
=
new
RootBeanDefinition
(
DefaultUserSessionRegistry
.
class
);
String
userSessionRegistryName
=
registerBeanDef
(
userSessionRegistry
Def
,
parserCxt
,
source
);
RuntimeBeanReference
userSessionRegistry
=
new
RuntimeBeanReference
(
userSessionRegistry
Name
);
RootBeanDefinition
bean
Def
=
new
RootBeanDefinition
(
DefaultUserSessionRegistry
.
class
);
beanName
=
registerBeanDef
(
bean
Def
,
parserCxt
,
source
);
RuntimeBeanReference
userSessionRegistry
=
new
RuntimeBeanReference
(
bean
Name
);
RuntimeBeanReference
subProtocolW
ebSocket
Handler
=
registerSubProtocolWebSocketHandler
(
RuntimeBeanReference
subProtocolW
s
Handler
=
registerSubProtocolWebSocketHandler
(
clientInChannel
,
clientOutChannel
,
userSessionRegistry
,
parserCxt
,
source
);
List
<
Element
>
stompEndpointElements
=
DomUtils
.
getChildElementsByTagName
(
element
,
"stomp-endpoint"
);
for
(
Element
stompEndpointElement
:
stompEndpointElements
)
{
for
(
Element
stompEndpointElem
:
DomUtils
.
getChildElementsByTagName
(
element
,
"stomp-endpoint"
))
{
RuntimeBeanReference
r
equestHandler
=
registerHttpRequestHandler
(
stompEndpointElem
ent
,
subProtocolWebSocket
Handler
,
parserCxt
,
source
);
RuntimeBeanReference
httpR
equestHandler
=
registerHttpRequestHandler
(
stompEndpointElem
,
subProtocolWs
Handler
,
parserCxt
,
source
);
List
<
String
>
paths
=
Arrays
.
asList
(
stompEndpointElement
.
getAttribute
(
"path"
).
split
(
","
));
String
pathAttribute
=
stompEndpointElem
.
getAttribute
(
"path"
);
Assert
.
state
(
StringUtils
.
hasText
(
pathAttribute
),
"Invalid <stomp-endpoint> (no path mapping)"
);
List
<
String
>
paths
=
Arrays
.
asList
(
pathAttribute
.
split
(
","
));
for
(
String
path
:
paths
)
{
if
(
DomUtils
.
getChildElementByTagName
(
stompEndpointElement
,
"sockjs"
)
!=
null
)
{
path
=
path
.
trim
();
Assert
.
state
(
StringUtils
.
hasText
(
path
),
"Invalid <stomp-endpoint> path attribute: "
+
pathAttribute
);
if
(
DomUtils
.
getChildElementByTagName
(
stompEndpointElem
,
"sockjs"
)
!=
null
)
{
path
=
path
.
endsWith
(
"/"
)
?
path
+
"**"
:
path
+
"/**"
;
}
urlMap
.
put
(
path
,
r
equestHandler
);
urlMap
.
put
(
path
,
httpR
equestHandler
);
}
}
registerBeanDef
(
handlerMappingDef
,
parserCxt
,
source
);
channel
Name
=
"brokerChannel"
;
bean
Name
=
"brokerChannel"
;
channelElem
=
DomUtils
.
getChildElementByTagName
(
element
,
"broker-channel"
);
RuntimeBeanReference
brokerChannel
=
getMessageChannel
(
channel
Name
,
channelElem
,
parserCxt
,
source
);
RuntimeBeanReference
brokerChannel
=
getMessageChannel
(
bean
Name
,
channelElem
,
parserCxt
,
source
);
registerMessageBroker
(
element
,
clientInChannel
,
clientOutChannel
,
brokerChannel
,
parserCxt
,
source
);
RuntimeBeanReference
messageConverter
=
registerBrokerMessageConverter
(
parserCxt
,
source
);
...
...
@@ -156,7 +161,7 @@ public class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
messageConverter
,
messagingTemplate
,
parserCxt
,
source
);
RuntimeBeanReference
userDestinationResolver
=
registerUserDestinationResolver
(
element
,
userSessionRegistry
Def
,
parserCxt
,
source
);
userSessionRegistry
,
parserCxt
,
source
);
registerUserDestinationMessageHandler
(
clientInChannel
,
clientOutChannel
,
brokerChannel
,
userDestinationResolver
,
parserCxt
,
source
);
...
...
@@ -320,7 +325,8 @@ public class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
mpvs
.
add
(
"virtualHost"
,
virtualHost
);
}
RootBeanDefinition
messageBrokerDef
=
new
RootBeanDefinition
(
StompBrokerRelayMessageHandler
.
class
,
cavs
,
mpvs
);
Class
<?>
handlerType
=
StompBrokerRelayMessageHandler
.
class
;
RootBeanDefinition
messageBrokerDef
=
new
RootBeanDefinition
(
handlerType
,
cavs
,
mpvs
);
registerBeanDef
(
messageBrokerDef
,
parserCxt
,
source
);
}
...
...
@@ -386,10 +392,10 @@ public class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
}
private
RuntimeBeanReference
registerUserDestinationResolver
(
Element
messageBrokerElement
,
BeanDefinition
userSessionRegistryDef
,
ParserContext
parserCxt
,
Object
source
)
{
RuntimeBeanReference
userSessionRegistry
,
ParserContext
parserCxt
,
Object
source
)
{
ConstructorArgumentValues
cavs
=
new
ConstructorArgumentValues
();
cavs
.
addIndexedArgumentValue
(
0
,
userSessionRegistry
Def
);
cavs
.
addIndexedArgumentValue
(
0
,
userSessionRegistry
);
RootBeanDefinition
userDestinationResolverDef
=
new
RootBeanDefinition
(
DefaultUserDestinationResolver
.
class
,
cavs
,
null
);
String
prefix
=
messageBrokerElement
.
getAttribute
(
"user-destination-prefix"
);
...
...
spring-websocket/src/main/resources/org/springframework/web/socket/server/config/xml/spring-websocket-4.0.xsd
浏览文件 @
47ef45d1
...
...
@@ -192,7 +192,7 @@
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element
name=
"stomp-endpoint"
maxOccurs=
"unbounded"
>
<xsd:element
name=
"stomp-endpoint"
m
inOccurs=
"1"
m
axOccurs=
"unbounded"
>
<xsd:complexType>
<xsd:sequence>
<xsd:element
name=
"handshake-handler"
type=
"handshake-handler"
minOccurs=
"0"
maxOccurs=
"1"
/>
...
...
spring-websocket/src/test/java/org/springframework/web/socket/messaging/config/xml/MessageBrokerBeanDefinitionParserTests.java
浏览文件 @
47ef45d1
...
...
@@ -35,6 +35,7 @@ import org.springframework.web.context.support.GenericWebApplicationContext;
import
org.springframework.web.servlet.HandlerMapping
;
import
org.springframework.web.servlet.handler.SimpleUrlHandlerMapping
;
import
org.springframework.web.socket.WebSocketHandler
;
import
org.springframework.web.socket.messaging.StompSubProtocolHandler
;
import
org.springframework.web.socket.messaging.SubProtocolWebSocketHandler
;
import
org.springframework.web.socket.server.support.WebSocketHttpRequestHandler
;
import
org.springframework.web.socket.sockjs.SockJsHttpRequestHandler
;
...
...
@@ -47,7 +48,9 @@ import java.util.Map;
import
static
org
.
junit
.
Assert
.*;
/**
* Test fixture for the configuration in websocket-config-broker*.xml test files.
* Test fixture for MessageBrokerBeanDefinitionParser.
* See test configuration files websocket-config-broker-*.xml.
*
* @author Brian Clozel
*/
public
class
MessageBrokerBeanDefinitionParserTests
{
...
...
@@ -82,6 +85,10 @@ public class MessageBrokerBeanDefinitionParserTests {
SubProtocolWebSocketHandler
subProtocolWsHandler
=
(
SubProtocolWebSocketHandler
)
wsHandler
;
assertEquals
(
Arrays
.
asList
(
"v10.stomp"
,
"v11.stomp"
,
"v12.stomp"
),
subProtocolWsHandler
.
getSubProtocols
());
StompSubProtocolHandler
stompHandler
=
(
StompSubProtocolHandler
)
subProtocolWsHandler
.
getProtocolHandlerMap
().
get
(
"v12.stomp"
);
assertNotNull
(
stompHandler
);
httpRequestHandler
=
(
HttpRequestHandler
)
suhm
.
getUrlMap
().
get
(
"/test/**"
);
assertNotNull
(
httpRequestHandler
);
assertThat
(
httpRequestHandler
,
Matchers
.
instanceOf
(
SockJsHttpRequestHandler
.
class
));
...
...
@@ -91,12 +98,20 @@ public class MessageBrokerBeanDefinitionParserTests {
assertThat
(
wsHandler
,
Matchers
.
instanceOf
(
SubProtocolWebSocketHandler
.
class
));
assertNotNull
(
sockJsHttpRequestHandler
.
getSockJsService
());
UserSessionRegistry
userSessionRegistry
=
this
.
appContext
.
getBean
(
UserSessionRegistry
.
class
);
assertNotNull
(
userSessionRegistry
);
UserDestinationResolver
userDestResolver
=
this
.
appContext
.
getBean
(
UserDestinationResolver
.
class
);
assertNotNull
(
userDestResolver
);
assertThat
(
userDestResolver
,
Matchers
.
instanceOf
(
DefaultUserDestinationResolver
.
class
));
DefaultUserDestinationResolver
defaultUserDestResolver
=
(
DefaultUserDestinationResolver
)
userDestResolver
;
assertEquals
(
"/personal/"
,
defaultUserDestResolver
.
getDestinationPrefix
());
assertSame
(
stompHandler
.
getUserSessionRegistry
(),
defaultUserDestResolver
.
getUserSessionRegistry
());
UserDestinationMessageHandler
userDestHandler
=
this
.
appContext
.
getBean
(
UserDestinationMessageHandler
.
class
);
assertNotNull
(
userDestHandler
);
List
<
Class
<?
extends
MessageHandler
>>
subscriberTypes
=
Arrays
.<
Class
<?
extends
MessageHandler
>>
asList
(
SimpAnnotationMethodMessageHandler
.
class
,
UserDestinationMessageHandler
.
class
,
SimpleBrokerMessageHandler
.
class
);
...
...
spring-websocket/src/test/java/org/springframework/web/socket/server/config/xml/HandlersBeanDefinitionParserTests.java
浏览文件 @
47ef45d1
...
...
@@ -64,7 +64,7 @@ import static org.junit.Assert.assertTrue;
/**
* Test fixture for HandlersBeanDefinitionParser.
* See test configuration files websocket-config-handlers*.xml.
* See test configuration files websocket-config-handlers
-
*.xml.
*
* @author Brian Clozel
*/
...
...
@@ -227,6 +227,7 @@ public class HandlersBeanDefinitionParserTests {
}
class
TestWebSocketHandler
implements
WebSocketHandler
{
@Override
public
void
afterConnectionEstablished
(
WebSocketSession
session
)
throws
Exception
{}
...
...
spring-websocket/src/test/resources/org/springframework/web/socket/messaging/config/xml/websocket-config-broker-simple.xml
浏览文件 @
47ef45d1
...
...
@@ -21,7 +21,7 @@
http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd"
>
<websocket:message-broker
application-destination-prefix=
"/app"
user-destination-prefix=
"/personal"
>
<websocket:stomp-endpoint
path=
"/foo,/bar"
>
<websocket:stomp-endpoint
path=
"
/foo,/bar"
>
<websocket:handshake-handler
ref=
"myHandler"
/>
</websocket:stomp-endpoint>
<websocket:stomp-endpoint
path=
"/test,/sockjs"
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录