Add XML namespace for WebSocket config

This commit adds an XML namespace equivalent of @EnableWebSocket and
@EnableWebSocketMessageBroker. Those are <websocket:handlers> and
<websocket:message-broker> respectively.

Examples can be found in the test suite.

This commit also alters the way MessageHandler's subscribe to their
respective MessageChannel's of interest. Rather than performing the
subscriptions in configuration code, the message channels are now
passed into MessageHandler's so they can subscribe themselves on
startup.

Issue: SPR-11063
This commit is contained in:
Brian Clozel
2013-11-26 20:04:57 +01:00
committed by Rossen Stoyanchev
parent 8f1fefc159
commit 10f5d96a78
44 changed files with 2434 additions and 171 deletions

View File

@@ -0,0 +1,50 @@
<!--
~ Copyright 2002-2013 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.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:websocket="http://www.springframework.org/schema/websocket"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
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:handshake-handler ref="myHandler" />
</websocket:stomp-endpoint>
<websocket:simple-broker prefix="/topic" />
<websocket:client-inbound-channel>
<websocket:executor core-pool-size="100" max-pool-size="200" keep-alive-seconds="600" />
<websocket:interceptors>
<ref bean="myInterceptor" />
</websocket:interceptors>
</websocket:client-inbound-channel>
<websocket:client-outbound-channel>
<websocket:executor core-pool-size="101" max-pool-size="201" keep-alive-seconds="601" />
<websocket:interceptors>
<ref bean="myInterceptor" />
<bean class="org.springframework.messaging.support.channel.ChannelInterceptorAdapter" />
</websocket:interceptors>
</websocket:client-outbound-channel>
<websocket:broker-channel>
<websocket:executor core-pool-size="102" max-pool-size="202" keep-alive-seconds="602" />
</websocket:broker-channel>
</websocket:message-broker>
<bean id="myHandler" class="org.springframework.web.socket.server.config.xml.TestHandshakeHandler" />
<bean id="myInterceptor" class="org.springframework.messaging.support.channel.ChannelInterceptorAdapter" />
</beans>

View File

@@ -0,0 +1,40 @@
<!--
~ Copyright 2002-2013 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.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:websocket="http://www.springframework.org/schema/websocket"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd">
<websocket:message-broker order="2">
<websocket:stomp-endpoint path="/foo">
<websocket:handshake-handler ref="myHandler" />
<websocket:sockjs />
</websocket:stomp-endpoint>
<websocket:stomp-broker-relay
prefix="/topic,/queue"
relay-host="relayhost"
relay-port="1234"
system-login="login"
system-passcode="pass"
system-heartbeat-send-interval="5000"
system-heartbeat-receive-interval="5000"
virtual-host="spring.io"/>
</websocket:message-broker>
<bean id="myHandler" class="org.springframework.web.socket.server.config.xml.TestWebSocketHandler" />
</beans>

View File

@@ -0,0 +1,35 @@
<!--
~ Copyright 2002-2013 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.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:websocket="http://www.springframework.org/schema/websocket"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
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:handshake-handler ref="myHandler" />
</websocket:stomp-endpoint>
<websocket:stomp-endpoint path="/test,/sockjs">
<websocket:handshake-handler ref="myHandler" />
<websocket:sockjs />
</websocket:stomp-endpoint>
<websocket:simple-broker prefix="/topic" />
</websocket:message-broker>
<bean id="myHandler" class="org.springframework.web.socket.server.config.xml.TestHandshakeHandler" />
</beans>

View File

@@ -0,0 +1,40 @@
<!--
~ Copyright 2002-2013 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.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:websocket="http://www.springframework.org/schema/websocket"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd">
<websocket:handlers order="2">
<websocket:mapping path="/foo" handler="fooHandler" />
<websocket:mapping path="/test" handler="testHandler" />
<websocket:handshake-handler ref="testHandshakeHandler" />
<websocket:handshake-interceptors>
<bean class="org.springframework.web.socket.server.config.xml.FooTestInterceptor"/>
<ref bean="barTestInterceptor" />
</websocket:handshake-interceptors>
</websocket:handlers>
<bean id="testHandler" class="org.springframework.web.socket.server.config.xml.TestWebSocketHandler" />
<bean id="fooHandler" class="org.springframework.web.socket.server.config.xml.FooWebSocketHandler" />
<bean id="barTestInterceptor" class="org.springframework.web.socket.server.config.xml.BarTestInterceptor"/>
<bean id="testHandshakeHandler" class="org.springframework.web.socket.server.config.xml.TestHandshakeHandler" />
</beans>

View File

@@ -0,0 +1,50 @@
<!--
~ Copyright 2002-2013 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.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:websocket="http://www.springframework.org/schema/websocket"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd">
<websocket:handlers >
<websocket:mapping path="/test" handler="testHandler" />
<websocket:sockjs task-scheduler="testTaskScheduler"
name="testSockJsService"
websocket-enabled="false"
session-cookie-needed="false"
stream-bytes-limit="2048"
disconnect-delay="256"
http-message-cache-size="1024"
heartbeat-time="20">
<websocket:transport-handlers register-defaults="false">
<bean class="org.springframework.web.socket.sockjs.transport.handler.XhrPollingTransportHandler"/>
<ref bean="xhrStreamingTransportHandler" />
</websocket:transport-handlers>
</websocket:sockjs>
</websocket:handlers>
<bean id="testHandler"
class="org.springframework.web.socket.server.config.xml.TestWebSocketHandler" />
<bean id="xhrStreamingTransportHandler"
class="org.springframework.web.socket.sockjs.transport.handler.XhrStreamingTransportHandler" />
<bean id="testTaskScheduler"
class="org.springframework.web.socket.server.config.xml.TestTaskScheduler" />
</beans>

View File

@@ -0,0 +1,33 @@
<!--
~ Copyright 2002-2013 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.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:websocket="http://www.springframework.org/schema/websocket"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd">
<websocket:handlers>
<websocket:mapping path="/test" handler="testHandler" />
<websocket:mapping path="/foo/" handler="fooHandler" />
<websocket:sockjs/>
</websocket:handlers>
<bean id="testHandler" class="org.springframework.web.socket.server.config.xml.TestWebSocketHandler" />
<bean id="fooHandler" class="org.springframework.web.socket.server.config.xml.FooWebSocketHandler" />
</beans>

View File

@@ -0,0 +1,35 @@
<!--
~ Copyright 2002-2013 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.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:websocket="http://www.springframework.org/schema/websocket"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd">
<websocket:handlers>
<websocket:mapping path="/foo,/bar" handler="fooHandler" />
</websocket:handlers>
<websocket:handlers>
<websocket:mapping path="/test" handler="testHandler" />
</websocket:handlers>
<bean id="testHandler" class="org.springframework.web.socket.server.config.xml.TestWebSocketHandler" />
<bean id="fooHandler" class="org.springframework.web.socket.server.config.xml.FooWebSocketHandler" />
</beans>