language stringclasses 1
value | owner stringlengths 2 15 | repo stringlengths 2 21 | sha stringlengths 45 45 | message stringlengths 7 36.3k | path stringlengths 1 199 | patch stringlengths 15 102k | is_multipart bool 2
classes |
|---|---|---|---|---|---|---|---|
Other | spring-projects | spring-framework | 69238ba66f19279de7e1a0e2ddd69fbb9fd0de05.json | Move WebSocketExtension to top-level package | spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractStandardUpgradeStrategy.java | @@ -33,7 +33,7 @@
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.util.Assert;
-import org.springframework.web.socket.support.WebSocketExtension;
+import org.springframework.web.socket.WebSocketExtension;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.adapter.StandardWebSocketHandlerAdapter;
import org.springframework.web.socket.adapter.StandardWebSocketSession; | true |
Other | spring-projects | spring-framework | 69238ba66f19279de7e1a0e2ddd69fbb9fd0de05.json | Move WebSocketExtension to top-level package | spring-websocket/src/main/java/org/springframework/web/socket/server/support/DefaultHandshakeHandler.java | @@ -38,7 +38,7 @@
import org.springframework.web.socket.server.HandshakeHandler;
import org.springframework.web.socket.server.RequestUpgradeStrategy;
import org.springframework.web.socket.support.SubProtocolCapable;
-import org.springframework.web.socket.support.WebSocketExtension;
+import org.springframework.web.socket.WebSocketExtension;
import org.springframework.web.socket.support.WebSocketHandlerDecorator;
import org.springframework.web.socket.support.WebSocketHttpHeaders;
| true |
Other | spring-projects | spring-framework | 69238ba66f19279de7e1a0e2ddd69fbb9fd0de05.json | Move WebSocketExtension to top-level package | spring-websocket/src/main/java/org/springframework/web/socket/server/support/GlassFish40RequestUpgradeStrategy.java | @@ -26,7 +26,7 @@
import org.glassfish.tyrus.spi.SPIEndpoint;
import org.glassfish.tyrus.websockets.WebSocketApplication;
import org.springframework.util.ClassUtils;
-import org.springframework.web.socket.support.WebSocketExtension;
+import org.springframework.web.socket.WebSocketExtension;
/**
* Extension of the {@link AbstractGlassFishRequestUpgradeStrategy} that provides support | true |
Other | spring-projects | spring-framework | 69238ba66f19279de7e1a0e2ddd69fbb9fd0de05.json | Move WebSocketExtension to top-level package | spring-websocket/src/main/java/org/springframework/web/socket/server/support/JettyRequestUpgradeStrategy.java | @@ -40,7 +40,7 @@
import org.springframework.http.server.ServletServerHttpResponse;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
-import org.springframework.web.socket.support.WebSocketExtension;
+import org.springframework.web.socket.WebSocketExtension;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.adapter.JettyWebSocketHandlerAdapter;
import org.springframework.web.socket.adapter.JettyWebSocketSession; | true |
Other | spring-projects | spring-framework | 69238ba66f19279de7e1a0e2ddd69fbb9fd0de05.json | Move WebSocketExtension to top-level package | spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractHttpSockJsSession.java | @@ -37,7 +37,7 @@
import org.springframework.web.socket.sockjs.SockJsTransportFailureException;
import org.springframework.web.socket.sockjs.support.frame.SockJsFrame;
import org.springframework.web.socket.sockjs.support.frame.SockJsFrame.FrameFormat;
-import org.springframework.web.socket.support.WebSocketExtension;
+import org.springframework.web.socket.WebSocketExtension;
/**
* An abstract base class for use with HTTP transport based SockJS sessions. | true |
Other | spring-projects | spring-framework | 69238ba66f19279de7e1a0e2ddd69fbb9fd0de05.json | Move WebSocketExtension to top-level package | spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java | @@ -28,7 +28,7 @@
import org.springframework.util.StringUtils;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
-import org.springframework.web.socket.support.WebSocketExtension;
+import org.springframework.web.socket.WebSocketExtension;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.adapter.NativeWebSocketSession; | true |
Other | spring-projects | spring-framework | 69238ba66f19279de7e1a0e2ddd69fbb9fd0de05.json | Move WebSocketExtension to top-level package | spring-websocket/src/main/java/org/springframework/web/socket/support/WebSocketHttpHeaders.java | @@ -25,6 +25,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.util.CollectionUtils;
+import org.springframework.web.socket.WebSocketExtension;
/**
* An {@link org.springframework.http.HttpHeaders} variant that adds support for | true |
Other | spring-projects | spring-framework | 69238ba66f19279de7e1a0e2ddd69fbb9fd0de05.json | Move WebSocketExtension to top-level package | spring-websocket/src/test/java/org/springframework/web/socket/WebSocketExtensionTests.java | @@ -20,12 +20,11 @@
import org.hamcrest.Matchers;
import org.junit.Test;
-import org.springframework.web.socket.support.WebSocketExtension;
import static org.junit.Assert.*;
/**
- * Test fixture for {@link org.springframework.web.socket.support.WebSocketExtension}
+ * Test fixture for {@link WebSocketExtension}
* @author Brian Clozel
*/
public class WebSocketExtensionTests { | true |
Other | spring-projects | spring-framework | 69238ba66f19279de7e1a0e2ddd69fbb9fd0de05.json | Move WebSocketExtension to top-level package | spring-websocket/src/test/java/org/springframework/web/socket/server/DefaultHandshakeHandlerTests.java | @@ -28,7 +28,7 @@
import org.springframework.web.socket.AbstractHttpRequestTests;
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
import org.springframework.web.socket.support.SubProtocolCapable;
-import org.springframework.web.socket.support.WebSocketExtension;
+import org.springframework.web.socket.WebSocketExtension;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.adapter.TextWebSocketHandlerAdapter;
import org.springframework.web.socket.support.WebSocketHttpHeaders; | true |
Other | spring-projects | spring-framework | 69238ba66f19279de7e1a0e2ddd69fbb9fd0de05.json | Move WebSocketExtension to top-level package | spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/session/TestSockJsSession.java | @@ -26,7 +26,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.web.socket.CloseStatus;
-import org.springframework.web.socket.support.WebSocketExtension;
+import org.springframework.web.socket.WebSocketExtension;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.sockjs.support.frame.SockJsFrame;
| true |
Other | spring-projects | spring-framework | 69238ba66f19279de7e1a0e2ddd69fbb9fd0de05.json | Move WebSocketExtension to top-level package | spring-websocket/src/test/java/org/springframework/web/socket/support/TestWebSocketSession.java | @@ -27,6 +27,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.web.socket.CloseStatus;
+import org.springframework.web.socket.WebSocketExtension;
import org.springframework.web.socket.WebSocketMessage;
import org.springframework.web.socket.WebSocketSession;
| true |
Other | spring-projects | spring-framework | 69238ba66f19279de7e1a0e2ddd69fbb9fd0de05.json | Move WebSocketExtension to top-level package | spring-websocket/src/test/java/org/springframework/web/socket/support/WebSocketHttpHeadersTests.java | @@ -22,6 +22,7 @@
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
+import org.springframework.web.socket.WebSocketExtension;
import static org.junit.Assert.*;
| true |
Other | spring-projects | spring-framework | 92e144a8a8471b024d32459f23f4151023d2f9b1.json | Add a 'bill of materials' project for Maven users
Add 'spring-framework-bom' meta-project that contains the other projects
in a dependencyManagement section.
Issue: SPR-11138 | build.gradle | @@ -853,6 +853,41 @@ project("spring-aspects") {
}
}
+project("spring-framework-bom") {
+ description = "Spring Framework (Bill of Materials)"
+
+ configurations.archives.artifacts.clear()
+ artifacts {
+ // work around GRADLE-2406 by attaching text artifact
+ archives(file("spring-framework-bom.txt"))
+ }
+
+ install {
+ repositories.mavenInstaller {
+ pom.whenConfigured {
+ packaging = "pom"
+ withXml {
+ asNode().children().last() + {
+ delegate.dependencyManagement {
+ delegate.dependencies {
+ parent.subprojects.sort { "$it.name" }.each { p ->
+ if (p.hasProperty("merge") && p.merge.into == null && p != project) {
+ delegate.dependency {
+ delegate.groupId(p.group)
+ delegate.artifactId(p.name)
+ delegate.version(p.version)
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
configure(rootProject) {
description = "Spring Framework"
| true |
Other | spring-projects | spring-framework | 92e144a8a8471b024d32459f23f4151023d2f9b1.json | Add a 'bill of materials' project for Maven users
Add 'spring-framework-bom' meta-project that contains the other projects
in a dependencyManagement section.
Issue: SPR-11138 | settings.gradle | @@ -23,6 +23,7 @@ include "spring-webmvc"
include "spring-webmvc-portlet"
include "spring-webmvc-tiles3"
include "spring-websocket"
+include "spring-framework-bom"
// Exposes gradle buildSrc for IDE support
include "buildSrc" | true |
Other | spring-projects | spring-framework | 92e144a8a8471b024d32459f23f4151023d2f9b1.json | Add a 'bill of materials' project for Maven users
Add 'spring-framework-bom' meta-project that contains the other projects
in a dependencyManagement section.
Issue: SPR-11138 | spring-framework-bom/spring-framework-bom.txt | @@ -0,0 +1,2 @@
+This meta-project is used to generate a bill-of-materials POM that contains the other
+projects in a dependencyManagement section. | true |
Other | spring-projects | spring-framework | 079fb2db737c830da62e57a02102bf0e9d70d6cb.json | Add assert AbstractStandardRequestUpgradeStrategy | spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractStandardUpgradeStrategy.java | @@ -32,6 +32,7 @@
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.http.server.ServletServerHttpRequest;
+import org.springframework.util.Assert;
import org.springframework.web.socket.support.WebSocketExtension;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.adapter.StandardWebSocketHandlerAdapter;
@@ -64,7 +65,11 @@ public List<WebSocketExtension> getSupportedExtensions(ServerHttpRequest request
protected ServerContainer getContainer(HttpServletRequest request) {
ServletContext servletContext = request.getServletContext();
- return (ServerContainer) servletContext.getAttribute("javax.websocket.server.ServerContainer");
+ String attrName = "javax.websocket.server.ServerContainer";
+ ServerContainer container = (ServerContainer) servletContext.getAttribute(attrName);
+ Assert.notNull(container, "No 'javax.websocket.server.ServerContainer' ServletContext attribute. " +
+ "Are you running in a Servlet container that supports JSR-356?");
+ return container;
}
protected List<WebSocketExtension> getInstalledExtensions(WebSocketContainer container) { | false |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | build.gradle | @@ -598,6 +598,8 @@ project("spring-websocket") {
testCompile("org.apache.tomcat.embed:tomcat-embed-core:8.0.0-RC5")
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
testCompile("log4j:log4j:1.2.17")
+ testCompile("org.projectreactor:reactor-core:1.0.0.RELEASE")
+ testCompile("org.projectreactor:reactor-tcp:1.0.0.RELEASE")
}
}
| true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractBrokerRegistration.java | @@ -22,6 +22,7 @@
import java.util.List;
import org.springframework.messaging.MessageChannel;
+import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.simp.handler.AbstractBrokerMessageHandler;
import org.springframework.util.Assert;
@@ -33,19 +34,31 @@
*/
public abstract class AbstractBrokerRegistration {
+ private final SubscribableChannel clientInboundChannel;
+
private final MessageChannel clientOutboundChannel;
private final List<String> destinationPrefixes;
- public AbstractBrokerRegistration(MessageChannel clientOutboundChannel, String[] destinationPrefixes) {
+ public AbstractBrokerRegistration(SubscribableChannel clientInboundChannel,
+ MessageChannel clientOutboundChannel, String[] destinationPrefixes) {
+
+ Assert.notNull(clientOutboundChannel, "'clientInboundChannel' must not be null");
Assert.notNull(clientOutboundChannel, "'clientOutboundChannel' must not be null");
+
+ this.clientInboundChannel = clientInboundChannel;
this.clientOutboundChannel = clientOutboundChannel;
+
this.destinationPrefixes = (destinationPrefixes != null)
? Arrays.<String>asList(destinationPrefixes) : Collections.<String>emptyList();
}
+ protected SubscribableChannel getClientInboundChannel() {
+ return this.clientInboundChannel;
+ }
+
protected MessageChannel getClientOutboundChannel() {
return this.clientOutboundChannel;
}
@@ -54,6 +67,6 @@ protected Collection<String> getDestinationPrefixes() {
return this.destinationPrefixes;
}
- protected abstract AbstractBrokerMessageHandler getMessageHandler();
+ protected abstract AbstractBrokerMessageHandler getMessageHandler(SubscribableChannel brokerChannel);
} | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java | @@ -47,7 +47,7 @@
* into any application component to send messages.
* <p>
* Sub-classes are responsible for the part of the configuration that feed messages
- * to and from the client inbound/outbound channels (e.g. STOMP over WebSokcet).
+ * to and from the client inbound/outbound channels (e.g. STOMP over WebSocket).
*
* @author Rossen Stoyanchev
* @since 4.0
@@ -86,7 +86,7 @@ public AbstractSubscribableChannel clientInboundChannel() {
public ThreadPoolTaskExecutor clientInboundChannelExecutor() {
TaskExecutorRegistration r = getClientInboundChannelRegistration().getTaskExecutorRegistration();
ThreadPoolTaskExecutor executor = (r != null) ? r.getTaskExecutor() : new ThreadPoolTaskExecutor();
- executor.setThreadNamePrefix("ClientInboundChannel-");
+ executor.setThreadNamePrefix("clientInboundChannel-");
return executor;
}
@@ -121,7 +121,7 @@ public AbstractSubscribableChannel clientOutboundChannel() {
public ThreadPoolTaskExecutor clientOutboundChannelExecutor() {
TaskExecutorRegistration r = getClientOutboundChannelRegistration().getTaskExecutorRegistration();
ThreadPoolTaskExecutor executor = (r != null) ? r.getTaskExecutor() : new ThreadPoolTaskExecutor();
- executor.setThreadNamePrefix("ClientOutboundChannel-");
+ executor.setThreadNamePrefix("clientOutboundChannel-");
return executor;
}
@@ -160,7 +160,7 @@ public AbstractSubscribableChannel brokerChannel() {
public ThreadPoolTaskExecutor brokerChannelExecutor() {
TaskExecutorRegistration r = getBrokerRegistry().getBrokerChannelRegistration().getTaskExecutorRegistration();
ThreadPoolTaskExecutor executor = (r != null) ? r.getTaskExecutor() : new ThreadPoolTaskExecutor();
- executor.setThreadNamePrefix("BrokerChannel-");
+ executor.setThreadNamePrefix("brokerChannel-");
return executor;
}
@@ -170,7 +170,7 @@ public ThreadPoolTaskExecutor brokerChannelExecutor() {
*/
protected final MessageBrokerRegistry getBrokerRegistry() {
if (this.brokerRegistry == null) {
- MessageBrokerRegistry registry = new MessageBrokerRegistry(clientOutboundChannel());
+ MessageBrokerRegistry registry = new MessageBrokerRegistry(clientInboundChannel(), clientOutboundChannel());
configureMessageBroker(registry);
this.brokerRegistry = registry;
}
@@ -187,45 +187,30 @@ protected final MessageBrokerRegistry getBrokerRegistry() {
@Bean
public SimpAnnotationMethodMessageHandler simpAnnotationMethodMessageHandler() {
- SimpAnnotationMethodMessageHandler handler =
- new SimpAnnotationMethodMessageHandler(brokerMessagingTemplate(), clientOutboundChannel());
+ SimpAnnotationMethodMessageHandler handler = new SimpAnnotationMethodMessageHandler(
+ clientInboundChannel(), clientOutboundChannel(), brokerMessagingTemplate());
handler.setDestinationPrefixes(getBrokerRegistry().getApplicationDestinationPrefixes());
handler.setMessageConverter(brokerMessageConverter());
- clientInboundChannel().subscribe(handler);
return handler;
}
@Bean
public AbstractBrokerMessageHandler simpleBrokerMessageHandler() {
- SimpleBrokerMessageHandler handler = getBrokerRegistry().getSimpleBroker();
- if (handler != null) {
- clientInboundChannel().subscribe(handler);
- brokerChannel().subscribe(handler);
- return handler;
- }
- return noopBroker;
+ SimpleBrokerMessageHandler handler = getBrokerRegistry().getSimpleBroker(brokerChannel());
+ return (handler != null) ? handler : noopBroker;
}
@Bean
public AbstractBrokerMessageHandler stompBrokerRelayMessageHandler() {
- AbstractBrokerMessageHandler handler = getBrokerRegistry().getStompBrokerRelay();
- if (handler != null) {
- clientInboundChannel().subscribe(handler);
- brokerChannel().subscribe(handler);
- return handler;
- }
- return noopBroker;
+ AbstractBrokerMessageHandler handler = getBrokerRegistry().getStompBrokerRelay(brokerChannel());
+ return (handler != null) ? handler : noopBroker;
}
@Bean
public UserDestinationMessageHandler userDestinationMessageHandler() {
-
UserDestinationMessageHandler handler = new UserDestinationMessageHandler(
- brokerMessagingTemplate(), userDestinationResolver());
-
- clientInboundChannel().subscribe(handler);
- brokerChannel().subscribe(handler);
+ clientInboundChannel(), clientOutboundChannel(), brokerChannel(), userDestinationResolver());
return handler;
}
| true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-messaging/src/main/java/org/springframework/messaging/simp/config/MessageBrokerRegistry.java | @@ -20,6 +20,7 @@
import java.util.Collection;
import org.springframework.messaging.MessageChannel;
+import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.simp.handler.SimpleBrokerMessageHandler;
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
import org.springframework.util.Assert;
@@ -32,11 +33,13 @@
*/
public class MessageBrokerRegistry {
+ private final SubscribableChannel clientInboundChannel;
+
private final MessageChannel clientOutboundChannel;
- private SimpleBrokerRegistration simpleBroker;
+ private SimpleBrokerRegistration simpleBrokerRegistration;
- private StompBrokerRelayRegistration stompRelay;
+ private StompBrokerRelayRegistration brokerRelayRegistration;
private String[] applicationDestinationPrefixes;
@@ -45,8 +48,10 @@ public class MessageBrokerRegistry {
private ChannelRegistration brokerChannelRegistration = new ChannelRegistration();
- public MessageBrokerRegistry(MessageChannel clientOutboundChannel) {
+ public MessageBrokerRegistry(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel) {
+ Assert.notNull(clientInboundChannel);
Assert.notNull(clientOutboundChannel);
+ this.clientInboundChannel = clientInboundChannel;
this.clientOutboundChannel = clientOutboundChannel;
}
@@ -55,8 +60,9 @@ public MessageBrokerRegistry(MessageChannel clientOutboundChannel) {
* destinations targeting the broker (e.g. destinations prefixed with "/topic").
*/
public SimpleBrokerRegistration enableSimpleBroker(String... destinationPrefixes) {
- this.simpleBroker = new SimpleBrokerRegistration(this.clientOutboundChannel, destinationPrefixes);
- return this.simpleBroker;
+ this.simpleBrokerRegistration = new SimpleBrokerRegistration(
+ this.clientInboundChannel, this.clientOutboundChannel, destinationPrefixes);
+ return this.simpleBrokerRegistration;
}
/**
@@ -65,8 +71,9 @@ public SimpleBrokerRegistration enableSimpleBroker(String... destinationPrefixes
* destinations.
*/
public StompBrokerRelayRegistration enableStompBrokerRelay(String... destinationPrefixes) {
- this.stompRelay = new StompBrokerRelayRegistration(this.clientOutboundChannel, destinationPrefixes);
- return this.stompRelay;
+ this.brokerRelayRegistration = new StompBrokerRelayRegistration(
+ this.clientInboundChannel, this.clientOutboundChannel, destinationPrefixes);
+ return this.brokerRelayRegistration;
}
/**
@@ -113,19 +120,21 @@ public ChannelRegistration configureBrokerChannel() {
}
- protected SimpleBrokerMessageHandler getSimpleBroker() {
- initSimpleBrokerIfNecessary();
- return (this.simpleBroker != null) ? this.simpleBroker.getMessageHandler() : null;
- }
-
- protected void initSimpleBrokerIfNecessary() {
- if ((this.simpleBroker == null) && (this.stompRelay == null)) {
- this.simpleBroker = new SimpleBrokerRegistration(this.clientOutboundChannel, null);
+ protected SimpleBrokerMessageHandler getSimpleBroker(SubscribableChannel brokerChannel) {
+ if ((this.simpleBrokerRegistration == null) && (this.brokerRelayRegistration == null)) {
+ enableSimpleBroker();
}
+ if (this.simpleBrokerRegistration != null) {
+ return this.simpleBrokerRegistration.getMessageHandler(brokerChannel);
+ }
+ return null;
}
- protected StompBrokerRelayMessageHandler getStompBrokerRelay() {
- return (this.stompRelay != null) ? this.stompRelay.getMessageHandler() : null;
+ protected StompBrokerRelayMessageHandler getStompBrokerRelay(SubscribableChannel brokerChannel) {
+ if (this.brokerRelayRegistration != null) {
+ return this.brokerRelayRegistration.getMessageHandler(brokerChannel);
+ }
+ return null;
}
protected Collection<String> getApplicationDestinationPrefixes() { | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-messaging/src/main/java/org/springframework/messaging/simp/config/SimpleBrokerRegistration.java | @@ -17,6 +17,7 @@
package org.springframework.messaging.simp.config;
import org.springframework.messaging.MessageChannel;
+import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.simp.handler.SimpleBrokerMessageHandler;
/**
@@ -28,14 +29,17 @@
public class SimpleBrokerRegistration extends AbstractBrokerRegistration {
- public SimpleBrokerRegistration(MessageChannel clientOutboundChannel, String[] destinationPrefixes) {
- super(clientOutboundChannel, destinationPrefixes);
+ public SimpleBrokerRegistration(SubscribableChannel clientInboundChannel,
+ MessageChannel clientOutboundChannel, String[] destinationPrefixes) {
+
+ super(clientInboundChannel, clientOutboundChannel, destinationPrefixes);
}
@Override
- protected SimpleBrokerMessageHandler getMessageHandler() {
- return new SimpleBrokerMessageHandler(getClientOutboundChannel(), getDestinationPrefixes());
+ protected SimpleBrokerMessageHandler getMessageHandler(SubscribableChannel brokerChannel) {
+ return new SimpleBrokerMessageHandler(getClientInboundChannel(),
+ getClientOutboundChannel(), brokerChannel, getDestinationPrefixes());
}
} | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-messaging/src/main/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistration.java | @@ -17,6 +17,7 @@
package org.springframework.messaging.simp.config;
import org.springframework.messaging.MessageChannel;
+import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
import org.springframework.util.Assert;
@@ -43,8 +44,10 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration {
private boolean autoStartup = true;
- public StompBrokerRelayRegistration(MessageChannel clientOutboundChannel, String[] destinationPrefixes) {
- super(clientOutboundChannel, destinationPrefixes);
+ public StompBrokerRelayRegistration(SubscribableChannel clientInboundChannel,
+ MessageChannel clientOutboundChannel, String[] destinationPrefixes) {
+
+ super(clientInboundChannel, clientOutboundChannel, destinationPrefixes);
}
@@ -119,10 +122,10 @@ public StompBrokerRelayRegistration setAutoStartup(boolean autoStartup) {
}
- protected StompBrokerRelayMessageHandler getMessageHandler() {
+ protected StompBrokerRelayMessageHandler getMessageHandler(SubscribableChannel brokerChannel) {
- StompBrokerRelayMessageHandler handler =
- new StompBrokerRelayMessageHandler(getClientOutboundChannel(), getDestinationPrefixes());
+ StompBrokerRelayMessageHandler handler = new StompBrokerRelayMessageHandler(getClientInboundChannel(),
+ getClientOutboundChannel(), brokerChannel, getDestinationPrefixes());
handler.setRelayHost(this.relayHost);
handler.setRelayPort(this.relayPort); | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-messaging/src/main/java/org/springframework/messaging/simp/handler/SimpAnnotationMethodMessageHandler.java | @@ -27,11 +27,13 @@
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.SmartLifecycle;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.convert.ConversionService;
import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
+import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.core.AbstractMessageSendingTemplate;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.support.AnnotationExceptionHandlerMethodResolver;
@@ -54,6 +56,7 @@
import org.springframework.messaging.simp.annotation.support.SendToMethodReturnValueHandler;
import org.springframework.messaging.simp.annotation.support.SubscriptionMethodReturnValueHandler;
import org.springframework.messaging.support.MessageBuilder;
+import org.springframework.messaging.support.channel.AbstractSubscribableChannel;
import org.springframework.messaging.support.converter.ByteArrayMessageConverter;
import org.springframework.messaging.support.converter.CompositeMessageConverter;
import org.springframework.messaging.support.converter.MessageConverter;
@@ -74,30 +77,44 @@
* @author Brian Clozel
* @since 4.0
*/
-public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHandler<SimpMessageMappingInfo> {
+public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHandler<SimpMessageMappingInfo>
+ implements SmartLifecycle {
- private final SimpMessageSendingOperations brokerTemplate;
+ private final SubscribableChannel clientInboundChannel;
private final SimpMessageSendingOperations clientMessagingTemplate;
+ private final SimpMessageSendingOperations brokerTemplate;
+
private MessageConverter messageConverter;
private ConversionService conversionService = new DefaultFormattingConversionService();
private PathMatcher pathMatcher = new AntPathMatcher();
+ private Object lifecycleMonitor = new Object();
+
+ private volatile boolean running = false;
+
/**
- * @param brokerTemplate a messaging template to send application messages to the broker
+ * Create an instance of SimpAnnotationMethodMessageHandler with the given
+ * message channels and broker messaging template.
+ *
+ * @param clientInboundChannel the channel for receiving messages from clients (e.g. WebSocket clients)
* @param clientOutboundChannel the channel for messages to clients (e.g. WebSocket clients)
+ * @param brokerTemplate a messaging template to send application messages to the broker
*/
- public SimpAnnotationMethodMessageHandler(SimpMessageSendingOperations brokerTemplate,
- MessageChannel clientOutboundChannel) {
+ public SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel,
+ MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate) {
- Assert.notNull(brokerTemplate, "BrokerTemplate must not be null");
- Assert.notNull(clientOutboundChannel, "ClientOutboundChannel must not be null");
- this.brokerTemplate = brokerTemplate;
+ Assert.notNull(clientInboundChannel, "clientInboundChannel must not be null");
+ Assert.notNull(clientOutboundChannel, "clientOutboundChannel must not be null");
+ Assert.notNull(brokerTemplate, "brokerTemplate must not be null");
+
+ this.clientInboundChannel = clientInboundChannel;
this.clientMessagingTemplate = new SimpMessagingTemplate(clientOutboundChannel);
+ this.brokerTemplate = brokerTemplate;
Collection<MessageConverter> converters = new ArrayList<MessageConverter>();
converters.add(new StringMessageConverter());
@@ -159,6 +176,46 @@ public PathMatcher getPathMatcher() {
return this.pathMatcher;
}
+ @Override
+ public boolean isAutoStartup() {
+ return true;
+ }
+
+ @Override
+ public int getPhase() {
+ return Integer.MAX_VALUE;
+ }
+
+ @Override
+ public final boolean isRunning() {
+ synchronized (this.lifecycleMonitor) {
+ return this.running;
+ }
+ }
+
+ @Override
+ public final void start() {
+ synchronized (this.lifecycleMonitor) {
+ this.clientInboundChannel.subscribe(this);
+ this.running = true;
+ }
+ }
+
+ @Override
+ public final void stop() {
+ synchronized (this.lifecycleMonitor) {
+ this.running = false;
+ this.clientInboundChannel.unsubscribe(this);
+ }
+ }
+
+ @Override
+ public final void stop(Runnable callback) {
+ synchronized (this.lifecycleMonitor) {
+ stop();
+ callback.run();
+ }
+ }
protected List<HandlerMethodArgumentResolver> initArgumentResolvers() {
| true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-messaging/src/main/java/org/springframework/messaging/simp/handler/SimpleBrokerMessageHandler.java | @@ -20,6 +20,7 @@
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
+import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.support.MessageBuilder;
@@ -34,23 +35,49 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler {
private static final byte[] EMPTY_PAYLOAD = new byte[0];
- private final MessageChannel messageChannel;
+ private final SubscribableChannel clientInboundChannel;
+
+ private final MessageChannel clientOutboundChannel;
+
+ private final SubscribableChannel brokerChannel;
private SubscriptionRegistry subscriptionRegistry = new DefaultSubscriptionRegistry();
/**
- * @param messageChannel the channel to broadcast messages to
+ * Create a SimpleBrokerMessageHandler instance with the given message channels
+ * and destination prefixes.
+ *
+ * @param clientInboundChannel the channel for receiving messages from clients (e.g. WebSocket clients)
+ * @param clientOutboundChannel the channel for sending messages to clients (e.g. WebSocket clients)
+ * @param brokerChannel the channel for the application to send messages to the broker
*/
- public SimpleBrokerMessageHandler(MessageChannel messageChannel, Collection<String> destinationPrefixes) {
+ public SimpleBrokerMessageHandler(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel,
+ SubscribableChannel brokerChannel, Collection<String> destinationPrefixes) {
+
super(destinationPrefixes);
- Assert.notNull(messageChannel, "MessageChannel must not be null");
- this.messageChannel = messageChannel;
+
+ Assert.notNull(clientInboundChannel, "'clientInboundChannel' must not be null");
+ Assert.notNull(clientOutboundChannel, "'clientOutboundChannel' must not be null");
+ Assert.notNull(brokerChannel, "'brokerChannel' must not be null");
+
+
+ this.clientInboundChannel = clientInboundChannel;
+ this.clientOutboundChannel = clientOutboundChannel;
+ this.brokerChannel = brokerChannel;
}
- public MessageChannel getMessageChannel() {
- return this.messageChannel;
+ public SubscribableChannel getClientInboundChannel() {
+ return this.clientInboundChannel;
+ }
+
+ public MessageChannel getClientOutboundChannel() {
+ return this.clientOutboundChannel;
+ }
+
+ public SubscribableChannel getBrokerChannel() {
+ return this.brokerChannel;
}
public void setSubscriptionRegistry(SubscriptionRegistry subscriptionRegistry) {
@@ -66,11 +93,15 @@ public SubscriptionRegistry getSubscriptionRegistry() {
@Override
public void startInternal() {
publishBrokerAvailableEvent();
+ this.clientInboundChannel.subscribe(this);
+ this.brokerChannel.subscribe(this);
}
@Override
public void stopInternal() {
publishBrokerUnavailableEvent();
+ this.clientInboundChannel.unsubscribe(this);
+ this.brokerChannel.unsubscribe(this);
}
@Override
@@ -106,7 +137,7 @@ else if (SimpMessageType.CONNECT.equals(messageType)) {
replyHeaders.setHeader(SimpMessageHeaderAccessor.CONNECT_MESSAGE_HEADER, message);
Message<byte[]> connectAck = MessageBuilder.withPayload(EMPTY_PAYLOAD).setHeaders(replyHeaders).build();
- this.messageChannel.send(connectAck);
+ this.clientOutboundChannel.send(connectAck);
}
}
@@ -124,7 +155,7 @@ protected void sendMessageToSubscribers(String destination, Message<?> message)
Object payload = message.getPayload();
Message<?> clientMessage = MessageBuilder.withPayload(payload).setHeaders(headers).build();
try {
- this.messageChannel.send(clientMessage);
+ this.clientOutboundChannel.send(clientMessage);
}
catch (Throwable ex) {
logger.error("Failed to send message to destination=" + destination + | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-messaging/src/main/java/org/springframework/messaging/simp/handler/UserDestinationMessageHandler.java | @@ -20,10 +20,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.springframework.messaging.Message;
-import org.springframework.messaging.MessageHandler;
-import org.springframework.messaging.MessagingException;
+import org.springframework.context.SmartLifecycle;
+import org.springframework.messaging.*;
import org.springframework.messaging.core.MessageSendingOperations;
+import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
@@ -37,28 +37,46 @@
* @author Rossen Stoyanchev
* @since 4.0
*/
-public class UserDestinationMessageHandler implements MessageHandler {
+public class UserDestinationMessageHandler implements MessageHandler, SmartLifecycle {
private static final Log logger = LogFactory.getLog(UserDestinationMessageHandler.class);
- private final MessageSendingOperations<String> messagingTemplate;
+ private final SubscribableChannel clientInboundChannel;
+
+ private final MessageChannel clientOutboundChannel;
+
+ private final SubscribableChannel brokerChannel;
+
+ private final MessageSendingOperations<String> brokerMessagingTemplate;
private final UserDestinationResolver userDestinationResolver;
+ private Object lifecycleMonitor = new Object();
+
+ private volatile boolean running = false;
+
/**
* Create an instance of the handler with the given messaging template and a
* user destination resolver.
- * @param messagingTemplate a messaging template to use for sending messages
- * with translated user destinations
+ * @param clientInChannel the channel for receiving messages from clients (e.g. WebSocket clients)
+ * @param clientOutChannel the channel for sending messages to clients (e.g. WebSocket clients)
+ * @param brokerChannel the channel for sending messages with translated user destinations
* @param userDestinationResolver the resolver to use to find queue suffixes for a user
*/
- public UserDestinationMessageHandler(MessageSendingOperations<String> messagingTemplate,
- UserDestinationResolver userDestinationResolver) {
- Assert.notNull(messagingTemplate, "MessagingTemplate must not be null");
+ public UserDestinationMessageHandler(SubscribableChannel clientInChannel, MessageChannel clientOutChannel,
+ SubscribableChannel brokerChannel, UserDestinationResolver userDestinationResolver) {
+
+ Assert.notNull(clientInChannel, "'clientInChannel' must not be null");
+ Assert.notNull(clientOutChannel, "'clientOutChannel' must not be null");
+ Assert.notNull(brokerChannel, "'brokerChannel' must not be null");
Assert.notNull(userDestinationResolver, "DestinationResolver must not be null");
- this.messagingTemplate = messagingTemplate;
+
+ this.clientInboundChannel = clientInChannel;
+ this.clientOutboundChannel = clientOutChannel;
+ this.brokerChannel = brokerChannel;
+ this.brokerMessagingTemplate = new SimpMessagingTemplate(brokerChannel);
this.userDestinationResolver = userDestinationResolver;
}
@@ -73,10 +91,52 @@ public UserDestinationResolver getUserDestinationResolver() {
* Return the configured messaging template for sending messages with
* translated destinations.
*/
- public MessageSendingOperations<String> getMessagingTemplate() {
- return this.messagingTemplate;
+ public MessageSendingOperations<String> getBrokerMessagingTemplate() {
+ return this.brokerMessagingTemplate;
+ }
+
+ @Override
+ public boolean isAutoStartup() {
+ return true;
+ }
+
+ @Override
+ public int getPhase() {
+ return Integer.MAX_VALUE;
+ }
+
+ @Override
+ public final boolean isRunning() {
+ synchronized (this.lifecycleMonitor) {
+ return this.running;
+ }
+ }
+
+ @Override
+ public final void start() {
+ synchronized (this.lifecycleMonitor) {
+ this.clientInboundChannel.subscribe(this);
+ this.brokerChannel.subscribe(this);
+ this.running = true;
+ }
}
+ @Override
+ public final void stop() {
+ synchronized (this.lifecycleMonitor) {
+ this.running = false;
+ this.clientInboundChannel.unsubscribe(this);
+ this.brokerChannel.unsubscribe(this);
+ }
+ }
+
+ @Override
+ public final void stop(Runnable callback) {
+ synchronized (this.lifecycleMonitor) {
+ stop();
+ callback.run();
+ }
+ }
@Override
public void handleMessage(Message<?> message) throws MessagingException {
@@ -90,7 +150,7 @@ public void handleMessage(Message<?> message) throws MessagingException {
if (logger.isDebugEnabled()) {
logger.debug("Sending message to resolved destination=" + targetDestination);
}
- this.messagingTemplate.send(targetDestination, message);
+ this.brokerMessagingTemplate.send(targetDestination, message);
}
}
| true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java | @@ -21,10 +21,7 @@
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
-import org.springframework.messaging.Message;
-import org.springframework.messaging.MessageChannel;
-import org.springframework.messaging.MessageDeliveryException;
-import org.springframework.messaging.MessageHandler;
+import org.springframework.messaging.*;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.simp.handler.AbstractBrokerMessageHandler;
@@ -77,7 +74,11 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
}
- private final MessageChannel messageChannel;
+ private final SubscribableChannel clientInboundChannel;
+
+ private final MessageChannel clientOutboundChannel;
+
+ private final SubscribableChannel brokerChannel;
private String relayHost = "127.0.0.1";
@@ -100,14 +101,28 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
/**
- * @param messageChannel the channel to send messages from the STOMP broker to
+ * Create a StompBrokerRelayMessageHandler instance with the given message channels
+ * and destination prefixes.
+ *
+ * @param clientInChannel the channel for receiving messages from clients (e.g. WebSocket clients)
+ * @param clientOutChannel the channel for sending messages to clients (e.g. WebSocket clients)
+ * @param brokerChannel the channel for the application to send messages to the broker
* @param destinationPrefixes the broker supported destination prefixes; destinations
* that do not match the given prefix are ignored.
*/
- public StompBrokerRelayMessageHandler(MessageChannel messageChannel, Collection<String> destinationPrefixes) {
+ public StompBrokerRelayMessageHandler(SubscribableChannel clientInChannel, MessageChannel clientOutChannel,
+ SubscribableChannel brokerChannel, Collection<String> destinationPrefixes) {
+
super(destinationPrefixes);
- Assert.notNull(messageChannel, "MessageChannel must not be null");
- this.messageChannel = messageChannel;
+
+ Assert.notNull(clientInChannel, "'clientInChannel' must not be null");
+ Assert.notNull(clientOutChannel, "'clientOutChannel' must not be null");
+ Assert.notNull(brokerChannel, "'brokerChannel' must not be null");
+
+
+ this.clientInboundChannel = clientInChannel;
+ this.clientOutboundChannel = clientOutChannel;
+ this.brokerChannel = brokerChannel;
}
@@ -242,6 +257,9 @@ void setTcpClient(TcpOperations<byte[]> tcpClient) {
@Override
protected void startInternal() {
+ this.clientInboundChannel.subscribe(this);
+ this.brokerChannel.subscribe(this);
+
if (this.tcpClient == null) {
this.tcpClient = new ReactorNettyTcpClient<byte[]>(this.relayHost, this.relayPort, new StompCodec());
}
@@ -265,6 +283,10 @@ protected void startInternal() {
@Override
protected void stopInternal() {
+
+ this.clientInboundChannel.unsubscribe(this);
+ this.brokerChannel.unsubscribe(this);
+
for (StompConnectionHandler handler : this.connectionHandlers.values()) {
try {
handler.resetTcpConnection();
@@ -416,7 +438,7 @@ private void sendStompErrorToClient(String errorText) {
protected void sendMessageToClient(Message<?> message) {
if (this.isRemoteClientSession) {
- StompBrokerRelayMessageHandler.this.messageChannel.send(message);
+ StompBrokerRelayMessageHandler.this.clientOutboundChannel.send(message);
}
}
| true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-messaging/src/main/java/org/springframework/messaging/support/channel/AbstractSubscribableChannel.java | @@ -43,7 +43,7 @@ public final boolean subscribe(MessageHandler handler) {
/**
* Whether the given {@link MessageHandler} is already subscribed.
*/
- protected abstract boolean hasSubscription(MessageHandler handler);
+ public abstract boolean hasSubscription(MessageHandler handler);
/**
* Subscribe the given {@link MessageHandler}. | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-messaging/src/main/java/org/springframework/messaging/support/channel/ExecutorSubscribableChannel.java | @@ -62,7 +62,7 @@ public Executor getExecutor() {
}
@Override
- protected boolean hasSubscription(MessageHandler handler) {
+ public boolean hasSubscription(MessageHandler handler) {
return this.handlers.contains(handler);
}
| true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-messaging/src/test/java/org/springframework/messaging/StubMessageChannel.java | @@ -24,10 +24,12 @@
*
* @author Rossen Stoyanchev
*/
-public class StubMessageChannel implements MessageChannel {
+public class StubMessageChannel implements SubscribableChannel {
private final List<Message<byte[]>> messages = new ArrayList<>();
+ private final List<MessageHandler> handlers = new ArrayList<>();
+
public List<Message<byte[]>> getMessages() {
return this.messages;
@@ -47,4 +49,15 @@ public boolean send(Message<?> message, long timeout) {
return true;
}
+ @Override
+ public boolean subscribe(MessageHandler handler) {
+ this.handlers.add(handler);
+ return true;
+ }
+
+ @Override
+ public boolean unsubscribe(MessageHandler handler) {
+ this.handlers.remove(handler);
+ return true;
+ }
} | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-messaging/src/test/java/org/springframework/messaging/simp/config/MessageBrokerConfigurationTests.java | @@ -46,7 +46,6 @@
import org.springframework.util.MimeTypeUtils;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.*;
@@ -319,6 +318,7 @@ protected void configureClientOutboundChannel(ChannelRegistration registration)
}
@Override
+ @Bean
public AbstractSubscribableChannel brokerChannel() {
return new TestChannel();
}
@@ -334,7 +334,7 @@ static class TestStompMessageBrokerConfig extends TestMessageBrokerConfiguration
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
- registry.enableStompBrokerRelay("/topic", "/queue").setAutoStartup(false);
+ registry.enableStompBrokerRelay("/topic", "/queue").setAutoStartup(true);
}
}
| true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-messaging/src/test/java/org/springframework/messaging/simp/handler/SimpAnnotationMethodMessageHandlerTests.java | @@ -25,6 +25,7 @@
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
+import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.MessageMapping;
@@ -53,9 +54,9 @@ public class SimpAnnotationMethodMessageHandlerTests {
@Before
public void setup() {
- MessageChannel channel = Mockito.mock(MessageChannel.class);
+ SubscribableChannel channel = Mockito.mock(SubscribableChannel.class);
SimpMessageSendingOperations brokerTemplate = new SimpMessagingTemplate(channel);
- this.messageHandler = new TestSimpAnnotationMethodMessageHandler(brokerTemplate, channel);
+ this.messageHandler = new TestSimpAnnotationMethodMessageHandler(brokerTemplate, channel, channel);
this.messageHandler.setApplicationContext(new StaticApplicationContext());
this.messageHandler.afterPropertiesSet();
@@ -145,9 +146,9 @@ public void simpleBinding() {
private static class TestSimpAnnotationMethodMessageHandler extends SimpAnnotationMethodMessageHandler {
public TestSimpAnnotationMethodMessageHandler(SimpMessageSendingOperations brokerTemplate,
- MessageChannel clientOutboundChannel) {
+ SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel) {
- super(brokerTemplate, clientOutboundChannel);
+ super(clientInboundChannel, clientOutboundChannel, brokerTemplate);
}
public void registerHandler(Object handler) { | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-messaging/src/test/java/org/springframework/messaging/simp/handler/SimpleBrokerMessageHandlerTests.java | @@ -26,6 +26,7 @@
import org.mockito.MockitoAnnotations;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
+import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.support.MessageBuilder;
@@ -43,7 +44,13 @@ public class SimpleBrokerMessageHandlerTests {
private SimpleBrokerMessageHandler messageHandler;
@Mock
- private MessageChannel clientChannel;
+ private SubscribableChannel clientInboundChannel;
+
+ @Mock
+ private MessageChannel clientOutboundChannel;
+
+ @Mock
+ private SubscribableChannel brokerChannel;
@Captor
ArgumentCaptor<Message<?>> messageCaptor;
@@ -52,7 +59,8 @@ public class SimpleBrokerMessageHandlerTests {
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
- this.messageHandler = new SimpleBrokerMessageHandler(this.clientChannel, Collections.<String>emptyList());
+ this.messageHandler = new SimpleBrokerMessageHandler(this.clientInboundChannel,
+ this.clientOutboundChannel, this.brokerChannel, Collections.<String>emptyList());
}
@@ -72,7 +80,7 @@ public void subcribePublish() {
this.messageHandler.handleMessage(createMessage("/foo", "message1"));
this.messageHandler.handleMessage(createMessage("/bar", "message2"));
- verify(this.clientChannel, times(6)).send(this.messageCaptor.capture());
+ verify(this.clientOutboundChannel, times(6)).send(this.messageCaptor.capture());
assertCapturedMessage("sess1", "sub1", "/foo");
assertCapturedMessage("sess1", "sub2", "/foo");
assertCapturedMessage("sess2", "sub1", "/foo");
@@ -105,7 +113,7 @@ public void subcribeDisconnectPublish() {
this.messageHandler.handleMessage(createMessage("/foo", "message1"));
this.messageHandler.handleMessage(createMessage("/bar", "message2"));
- verify(this.clientChannel, times(3)).send(this.messageCaptor.capture());
+ verify(this.clientOutboundChannel, times(3)).send(this.messageCaptor.capture());
assertCapturedMessage(sess2, "sub1", "/foo");
assertCapturedMessage(sess2, "sub2", "/foo");
assertCapturedMessage(sess2, "sub3", "/bar");
@@ -121,7 +129,7 @@ public void connect() {
Message<String> connectMessage = createConnectMessage(sess1);
this.messageHandler.handleMessage(connectMessage);
- verify(this.clientChannel, times(1)).send(this.messageCaptor.capture());
+ verify(this.clientOutboundChannel, times(1)).send(this.messageCaptor.capture());
Message<?> connectAckMessage = this.messageCaptor.getValue();
SimpMessageHeaderAccessor connectAckHeaders = SimpMessageHeaderAccessor.wrap(connectAckMessage); | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-messaging/src/test/java/org/springframework/messaging/simp/handler/UserDestinationMessageHandlerTests.java | @@ -16,21 +16,22 @@
package org.springframework.messaging.simp.handler;
-import org.apache.activemq.transport.stomp.Stomp;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.springframework.messaging.Message;
-import org.springframework.messaging.core.MessageSendingOperations;
+import org.springframework.messaging.StubMessageChannel;
+import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.simp.TestPrincipal;
-import org.springframework.messaging.simp.stomp.StompCommand;
-import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
import org.springframework.messaging.support.MessageBuilder;
import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.*;
/**
* Unit tests for {@link UserDestinationMessageHandler}.
@@ -39,54 +40,60 @@ public class UserDestinationMessageHandlerTests {
private UserDestinationMessageHandler messageHandler;
- private MessageSendingOperations<String> messagingTemplate;
+
+ @Mock
+ private SubscribableChannel brokerChannel;
private UserSessionRegistry registry;
@Before
public void setup() {
- this.messagingTemplate = Mockito.mock(MessageSendingOperations.class);
+ MockitoAnnotations.initMocks(this);
this.registry = new DefaultUserSessionRegistry();
DefaultUserDestinationResolver resolver = new DefaultUserDestinationResolver(this.registry);
- this.messageHandler = new UserDestinationMessageHandler(this.messagingTemplate, resolver);
+ this.messageHandler = new UserDestinationMessageHandler(new StubMessageChannel(),
+ new StubMessageChannel(), this.brokerChannel, resolver);
}
@Test
public void handleSubscribe() {
this.registry.registerSessionId("joe", "123");
+ when(this.brokerChannel.send(Mockito.any(Message.class))).thenReturn(true);
this.messageHandler.handleMessage(createMessage(SimpMessageType.SUBSCRIBE, "joe", "/user/queue/foo"));
- ArgumentCaptor<String> captor1 = ArgumentCaptor.forClass(String.class);
- ArgumentCaptor<Message> captor2 = ArgumentCaptor.forClass(Message.class);
- Mockito.verify(this.messagingTemplate).send(captor1.capture(), captor2.capture());
+ ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
+ Mockito.verify(this.brokerChannel).send(captor.capture());
- assertEquals("/queue/foo-user123", captor1.getValue());
+ assertEquals("/queue/foo-user123",
+ captor.getValue().getHeaders().get(SimpMessageHeaderAccessor.DESTINATION_HEADER));
}
@Test
public void handleUnsubscribe() {
this.registry.registerSessionId("joe", "123");
+ when(this.brokerChannel.send(Mockito.any(Message.class))).thenReturn(true);
this.messageHandler.handleMessage(createMessage(SimpMessageType.UNSUBSCRIBE, "joe", "/user/queue/foo"));
- ArgumentCaptor<String> captor1 = ArgumentCaptor.forClass(String.class);
- ArgumentCaptor<Message> captor2 = ArgumentCaptor.forClass(Message.class);
- Mockito.verify(this.messagingTemplate).send(captor1.capture(), captor2.capture());
+ ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
+ Mockito.verify(this.brokerChannel).send(captor.capture());
- assertEquals("/queue/foo-user123", captor1.getValue());
+ assertEquals("/queue/foo-user123",
+ captor.getValue().getHeaders().get(SimpMessageHeaderAccessor.DESTINATION_HEADER));
}
@Test
public void handleMessage() {
this.registry.registerSessionId("joe", "123");
+ when(this.brokerChannel.send(Mockito.any(Message.class))).thenReturn(true);
this.messageHandler.handleMessage(createMessage(SimpMessageType.MESSAGE, "joe", "/user/joe/queue/foo"));
- ArgumentCaptor<String> captor1 = ArgumentCaptor.forClass(String.class);
- ArgumentCaptor<Message> captor2 = ArgumentCaptor.forClass(Message.class);
- Mockito.verify(this.messagingTemplate).send(captor1.capture(), captor2.capture());
+ ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
+ Mockito.verify(this.brokerChannel).send(captor.capture());
- assertEquals("/queue/foo-user123", captor1.getValue());
+ assertEquals("/queue/foo-user123",
+ captor.getValue().getHeaders().get(SimpMessageHeaderAccessor.DESTINATION_HEADER));
}
@@ -95,23 +102,23 @@ public void ignoreMessage() {
// no destination
this.messageHandler.handleMessage(createMessage(SimpMessageType.MESSAGE, "joe", null));
- Mockito.verifyZeroInteractions(this.messagingTemplate);
+ Mockito.verifyZeroInteractions(this.brokerChannel);
// not a user destination
this.messageHandler.handleMessage(createMessage(SimpMessageType.MESSAGE, "joe", "/queue/foo"));
- Mockito.verifyZeroInteractions(this.messagingTemplate);
+ Mockito.verifyZeroInteractions(this.brokerChannel);
// subscribe + no user
this.messageHandler.handleMessage(createMessage(SimpMessageType.SUBSCRIBE, null, "/user/queue/foo"));
- Mockito.verifyZeroInteractions(this.messagingTemplate);
+ Mockito.verifyZeroInteractions(this.brokerChannel);
// subscribe + not a user destination
this.messageHandler.handleMessage(createMessage(SimpMessageType.SUBSCRIBE, "joe", "/queue/foo"));
- Mockito.verifyZeroInteractions(this.messagingTemplate);
+ Mockito.verifyZeroInteractions(this.brokerChannel);
// no match on message type
this.messageHandler.handleMessage(createMessage(SimpMessageType.CONNECT, "joe", "user/joe/queue/foo"));
- Mockito.verifyZeroInteractions(this.messagingTemplate);
+ Mockito.verifyZeroInteractions(this.brokerChannel);
}
| true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerIntegrationTests.java | @@ -32,10 +32,7 @@
import org.junit.Test;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
-import org.springframework.messaging.Message;
-import org.springframework.messaging.MessageDeliveryException;
-import org.springframework.messaging.MessageHandler;
-import org.springframework.messaging.MessagingException;
+import org.springframework.messaging.*;
import org.springframework.messaging.simp.BrokerAvailabilityEvent;
import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.support.MessageBuilder;
@@ -92,7 +89,8 @@ private void startActiveMqBroker() throws Exception {
}
private void createAndStartRelay() throws InterruptedException {
- this.relay = new StompBrokerRelayMessageHandler(this.responseChannel, Arrays.asList("/queue/", "/topic/"));
+ this.relay = new StompBrokerRelayMessageHandler(new StubMessageChannel(),
+ this.responseChannel, new StubMessageChannel(), Arrays.asList("/queue/", "/topic/"));
this.relay.setRelayPort(this.port);
this.relay.setApplicationEventPublisher(this.eventPublisher);
this.relay.setSystemHeartbeatReceiveInterval(0); | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerTests.java | @@ -53,7 +53,8 @@ public void setup() {
this.tcpClient = new StubTcpOperations();
- this.brokerRelay = new StompBrokerRelayMessageHandler(new StubMessageChannel(), Arrays.asList("/topic"));
+ this.brokerRelay = new StompBrokerRelayMessageHandler(new StubMessageChannel(),
+ new StubMessageChannel(), new StubMessageChannel(), Arrays.asList("/topic"));
this.brokerRelay.setTcpClient(tcpClient);
}
| true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java | @@ -21,10 +21,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.springframework.messaging.Message;
-import org.springframework.messaging.MessageChannel;
-import org.springframework.messaging.MessageHandler;
-import org.springframework.messaging.MessagingException;
+import org.springframework.context.SmartLifecycle;
+import org.springframework.messaging.*;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@@ -50,11 +48,14 @@
*
* @since 4.0
*/
-public class SubProtocolWebSocketHandler implements SubProtocolCapable, WebSocketHandler, MessageHandler {
+public class SubProtocolWebSocketHandler
+ implements SubProtocolCapable, WebSocketHandler, MessageHandler, SmartLifecycle {
private final Log logger = LogFactory.getLog(SubProtocolWebSocketHandler.class);
- private final MessageChannel clientOutboundChannel;
+ private final MessageChannel clientInboundChannel;
+
+ private final SubscribableChannel clientOutboundChannel;
private final Map<String, SubProtocolHandler> protocolHandlers =
new TreeMap<String, SubProtocolHandler>(String.CASE_INSENSITIVE_ORDER);
@@ -63,9 +64,15 @@ public class SubProtocolWebSocketHandler implements SubProtocolCapable, WebSocke
private final Map<String, WebSocketSession> sessions = new ConcurrentHashMap<String, WebSocketSession>();
+ private Object lifecycleMonitor = new Object();
+
+ private volatile boolean running = false;
- public SubProtocolWebSocketHandler(MessageChannel clientOutboundChannel) {
+
+ public SubProtocolWebSocketHandler(MessageChannel clientInboundChannel, SubscribableChannel clientOutboundChannel) {
+ Assert.notNull(clientInboundChannel, "ClientInboundChannel must not be null");
Assert.notNull(clientOutboundChannel, "ClientOutboundChannel must not be null");
+ this.clientInboundChannel = clientInboundChannel;
this.clientOutboundChannel = clientOutboundChannel;
}
@@ -82,6 +89,11 @@ public void setProtocolHandlers(List<SubProtocolHandler> protocolHandlers) {
}
}
+ public List<SubProtocolHandler> getProtocolHandlers() {
+ return new ArrayList<SubProtocolHandler>(protocolHandlers.values());
+ }
+
+
/**
* Register a sub-protocol handler.
*/
@@ -101,9 +113,9 @@ public void addProtocolHandler(SubProtocolHandler handler) {
}
/**
- * @return the configured sub-protocol handlers
+ * Return the sub-protocols keyed by protocol name.
*/
- public Map<String, SubProtocolHandler> getProtocolHandlers() {
+ public Map<String, SubProtocolHandler> getProtocolHandlerMap() {
return this.protocolHandlers;
}
@@ -133,10 +145,51 @@ public List<String> getSubProtocols() {
return new ArrayList<String>(this.protocolHandlers.keySet());
}
+ @Override
+ public boolean isAutoStartup() {
+ return true;
+ }
+
+ @Override
+ public int getPhase() {
+ return Integer.MAX_VALUE;
+ }
+
+ @Override
+ public final boolean isRunning() {
+ synchronized (this.lifecycleMonitor) {
+ return this.running;
+ }
+ }
+
+ @Override
+ public final void start() {
+ synchronized (this.lifecycleMonitor) {
+ this.clientOutboundChannel.subscribe(this);
+ this.running = true;
+ }
+ }
+
+ @Override
+ public final void stop() {
+ synchronized (this.lifecycleMonitor) {
+ this.running = false;
+ this.clientOutboundChannel.unsubscribe(this);
+ }
+ }
+
+ @Override
+ public final void stop(Runnable callback) {
+ synchronized (this.lifecycleMonitor) {
+ stop();
+ callback.run();
+ }
+ }
+
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
this.sessions.put(session.getId(), session);
- findProtocolHandler(session).afterSessionStarted(session, this.clientOutboundChannel);
+ findProtocolHandler(session).afterSessionStarted(session, this.clientInboundChannel);
}
protected final SubProtocolHandler findProtocolHandler(WebSocketSession session) {
@@ -167,7 +220,7 @@ protected final SubProtocolHandler findProtocolHandler(WebSocketSession session)
@Override
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
- findProtocolHandler(session).handleMessageFromClient(session, message, this.clientOutboundChannel);
+ findProtocolHandler(session).handleMessageFromClient(session, message, this.clientInboundChannel);
}
@Override
@@ -216,7 +269,7 @@ public void handleTransportError(WebSocketSession session, Throwable exception)
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {
this.sessions.remove(session.getId());
- findProtocolHandler(session).afterSessionEnded(session, closeStatus, this.clientOutboundChannel);
+ findProtocolHandler(session).afterSessionEnded(session, closeStatus, this.clientInboundChannel);
}
@Override | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/main/java/org/springframework/web/socket/messaging/config/WebMvcStompEndpointRegistry.java | @@ -55,8 +55,10 @@ public class WebMvcStompEndpointRegistry implements StompEndpointRegistry {
public WebMvcStompEndpointRegistry(WebSocketHandler webSocketHandler,
UserSessionRegistry userSessionRegistry, TaskScheduler defaultSockJsTaskScheduler) {
+
Assert.notNull(webSocketHandler);
Assert.notNull(userSessionRegistry);
+
this.webSocketHandler = webSocketHandler;
this.subProtocolWebSocketHandler = unwrapSubProtocolWebSocketHandler(webSocketHandler);
this.stompHandler = new StompSubProtocolHandler(); | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/main/java/org/springframework/web/socket/messaging/config/WebSocketMessageBrokerConfigurationSupport.java | @@ -53,9 +53,7 @@ public HandlerMapping stompWebSocketHandlerMapping() {
@Bean
public WebSocketHandler subProtocolWebSocketHandler() {
- SubProtocolWebSocketHandler handler = new SubProtocolWebSocketHandler(clientInboundChannel());
- clientOutboundChannel().subscribe(handler);
- return handler;
+ return new SubProtocolWebSocketHandler(clientInboundChannel(), clientOutboundChannel());
}
/** | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/main/java/org/springframework/web/socket/messaging/config/xml/MessageBrokerBeanDefinitionParser.java | @@ -0,0 +1,436 @@
+/*
+ * 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.
+ */
+
+package org.springframework.web.socket.messaging.config.xml;
+
+import org.springframework.beans.MutablePropertyValues;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.ConstructorArgumentValues;
+import org.springframework.beans.factory.config.RuntimeBeanReference;
+import org.springframework.beans.factory.parsing.BeanComponentDefinition;
+import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
+import org.springframework.beans.factory.support.ManagedList;
+import org.springframework.beans.factory.support.ManagedMap;
+import org.springframework.beans.factory.support.RootBeanDefinition;
+import org.springframework.beans.factory.xml.BeanDefinitionParser;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.messaging.simp.SimpMessagingTemplate;
+import org.springframework.messaging.simp.handler.DefaultUserDestinationResolver;
+import org.springframework.messaging.simp.handler.DefaultUserSessionRegistry;
+import org.springframework.messaging.simp.handler.SimpAnnotationMethodMessageHandler;
+import org.springframework.messaging.simp.handler.SimpleBrokerMessageHandler;
+import org.springframework.messaging.simp.handler.UserDestinationMessageHandler;
+import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
+import org.springframework.messaging.support.channel.ExecutorSubscribableChannel;
+import org.springframework.messaging.support.converter.ByteArrayMessageConverter;
+import org.springframework.messaging.support.converter.CompositeMessageConverter;
+import org.springframework.messaging.support.converter.DefaultContentTypeResolver;
+import org.springframework.messaging.support.converter.MappingJackson2MessageConverter;
+import org.springframework.messaging.support.converter.StringMessageConverter;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+import org.springframework.util.ClassUtils;
+import org.springframework.util.MimeTypeUtils;
+import org.springframework.util.StringUtils;
+import org.springframework.util.xml.DomUtils;
+import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
+import org.springframework.web.socket.messaging.StompSubProtocolHandler;
+import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler;
+import org.springframework.web.socket.server.config.xml.WebSocketNamespaceUtils;
+import org.springframework.web.socket.server.support.WebSocketHttpRequestHandler;
+import org.springframework.web.socket.sockjs.SockJsHttpRequestHandler;
+import org.w3c.dom.Element;
+
+import java.util.Arrays;
+import java.util.List;
+
+
+/**
+ * A {@link org.springframework.beans.factory.xml.BeanDefinitionParser}
+ * that provides the configuration for the
+ * {@code <websocket:message-broker/>} XML namespace element.
+ * <p>
+ * Registers a Spring MVC {@link org.springframework.web.servlet.handler.SimpleUrlHandlerMapping}
+ * with order=1 to map HTTP WebSocket handshake requests from STOMP/WebSocket clients.
+ * <p>
+ * Registers the following {@link org.springframework.messaging.MessageChannel}s:
+ * <ul>
+ * <li>"clientInboundChannel" for receiving messages from clients (e.g. WebSocket clients)
+ * <li>"clientOutboundChannel" for sending messages to clients (e.g. WebSocket clients)
+ * <li>"brokerChannel" for sending messages from within the application to the message broker
+ * </ul>
+ * <p>
+ * Registers one of the following based on the selected message broker options:
+ * <ul>
+ * <li> a {@link SimpleBrokerMessageHandler} if the <simple-broker/> is used
+ * <li> a {@link StompBrokerRelayMessageHandler} if the <stomp-broker-relay/> is used
+ * </ul>
+ * <p>
+ * Registers a {@link UserDestinationMessageHandler} for handling user destinations.
+ *
+ * @author Brian Clozel
+ * @author Rossen Stoyanchev
+ * @since 4.0
+ */
+public class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
+
+ protected static final String SOCKJS_SCHEDULER_BEAN_NAME = "messageBrokerSockJsScheduler";
+
+ private static final int DEFAULT_MAPPING_ORDER = 1;
+
+ private static final boolean jackson2Present= ClassUtils.isPresent(
+ "com.fasterxml.jackson.databind.ObjectMapper", MessageBrokerBeanDefinitionParser.class.getClassLoader());
+
+
+ @Override
+ public BeanDefinition parse(Element element, ParserContext parserCxt) {
+
+ Object source = parserCxt.extractSource(element);
+ CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
+ parserCxt.pushContainingComponent(compDefinition);
+
+ String orderAttribute = element.getAttribute("order");
+ int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute);
+
+ ManagedMap<String, Object> urlMap = new ManagedMap<String, Object>();
+ urlMap.setSource(source);
+
+ RootBeanDefinition handlerMappingDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class);
+ handlerMappingDef.getPropertyValues().add("order", order);
+ handlerMappingDef.getPropertyValues().add("urlMap", urlMap);
+
+ String channelName = "clientInboundChannel";
+ Element channelElem = DomUtils.getChildElementByTagName(element, "client-inbound-channel");
+ RuntimeBeanReference clientInChannel = getMessageChannel(channelName, channelElem, parserCxt, source);
+
+ channelName = "clientOutboundChannel";
+ channelElem = DomUtils.getChildElementByTagName(element, "client-outbound-channel");
+ RuntimeBeanReference clientOutChannel = getMessageChannel(channelName, channelElem, parserCxt, source);
+
+ RootBeanDefinition userSessionRegistryDef = new RootBeanDefinition(DefaultUserSessionRegistry.class);
+ String userSessionRegistryName = registerBeanDef(userSessionRegistryDef, parserCxt, source);
+ RuntimeBeanReference userSessionRegistry = new RuntimeBeanReference(userSessionRegistryName);
+
+ RuntimeBeanReference subProtocolWebSocketHandler = registerSubProtocolWebSocketHandler(
+ clientInChannel, clientOutChannel, userSessionRegistry, parserCxt, source);
+
+ List<Element> stompEndpointElements = DomUtils.getChildElementsByTagName(element, "stomp-endpoint");
+ for(Element stompEndpointElement : stompEndpointElements) {
+
+ RuntimeBeanReference requestHandler = registerHttpRequestHandler(
+ stompEndpointElement, subProtocolWebSocketHandler, parserCxt, source);
+
+ List<String> paths = Arrays.asList(stompEndpointElement.getAttribute("path").split(","));
+ for(String path : paths) {
+ if (DomUtils.getChildElementByTagName(stompEndpointElement, "sockjs") != null) {
+ path = path.endsWith("/") ? path + "**" : path + "/**";
+ }
+ urlMap.put(path, requestHandler);
+ }
+ }
+
+ registerBeanDef(handlerMappingDef, parserCxt, source);
+
+ channelName = "brokerChannel";
+ channelElem = DomUtils.getChildElementByTagName(element, "broker-channel");
+ RuntimeBeanReference brokerChannel = getMessageChannel(channelName, channelElem, parserCxt, source);
+ registerMessageBroker(element, clientInChannel, clientOutChannel, brokerChannel, parserCxt, source);
+
+ RuntimeBeanReference messageConverter = registerBrokerMessageConverter(parserCxt, source);
+ RuntimeBeanReference messagingTemplate = registerBrokerMessagingTemplate(element, brokerChannel,
+ messageConverter, parserCxt, source);
+
+ registerAnnotationMethodMessageHandler(element, clientInChannel, clientOutChannel,
+ messageConverter, messagingTemplate, parserCxt, source);
+
+ RuntimeBeanReference userDestinationResolver = registerUserDestinationResolver(element,
+ userSessionRegistryDef, parserCxt, source);
+
+ registerUserDestinationMessageHandler(clientInChannel, clientOutChannel, brokerChannel,
+ userDestinationResolver, parserCxt, source);
+
+ parserCxt.popAndRegisterContainingComponent();
+
+ return null;
+ }
+
+ private RuntimeBeanReference getMessageChannel(String channelName, Element channelElement,
+ ParserContext parserCxt, Object source) {
+
+ RootBeanDefinition executorDef = null;
+
+ if (channelElement != null) {
+ Element executor = DomUtils.getChildElementByTagName(channelElement, "executor");
+ if (executor != null) {
+ executorDef = new RootBeanDefinition(ThreadPoolTaskExecutor.class);
+ String attrValue = executor.getAttribute("core-pool-size");
+ if (!StringUtils.isEmpty(attrValue)) {
+ executorDef.getPropertyValues().add("corePoolSize", attrValue);
+ }
+ attrValue = executor.getAttribute("max-pool-size");
+ if (!StringUtils.isEmpty(attrValue)) {
+ executorDef.getPropertyValues().add("maxPoolSize", attrValue);
+ }
+ attrValue = executor.getAttribute("keep-alive-seconds");
+ if (!StringUtils.isEmpty(attrValue)) {
+ executorDef.getPropertyValues().add("keepAliveSeconds", attrValue);
+ }
+ attrValue = executor.getAttribute("queue-capacity");
+ if (!StringUtils.isEmpty(attrValue)) {
+ executorDef.getPropertyValues().add("queueCapacity", attrValue);
+ }
+ }
+ }
+ else if (!channelName.equals("brokerChannel")) {
+ executorDef = new RootBeanDefinition(ThreadPoolTaskExecutor.class);
+ }
+
+ ConstructorArgumentValues values = new ConstructorArgumentValues();
+ if (executorDef != null) {
+ executorDef.getPropertyValues().add("threadNamePrefix", channelName + "-");
+ String executorName = channelName + "Executor";
+ registerBeanDefByName(executorName, executorDef, parserCxt, source);
+ values.addIndexedArgumentValue(0, new RuntimeBeanReference(executorName));
+ }
+
+ RootBeanDefinition channelDef = new RootBeanDefinition(ExecutorSubscribableChannel.class, values, null);
+
+ if (channelElement != null) {
+ Element interceptorsElement = DomUtils.getChildElementByTagName(channelElement, "interceptors");
+ ManagedList<?> interceptorList = WebSocketNamespaceUtils.parseBeanSubElements(interceptorsElement, parserCxt);
+ channelDef.getPropertyValues().add("interceptors", interceptorList);
+ }
+
+ registerBeanDefByName(channelName, channelDef, parserCxt, source);
+ return new RuntimeBeanReference(channelName);
+ }
+
+ private RuntimeBeanReference registerSubProtocolWebSocketHandler(
+ RuntimeBeanReference clientInChannel, RuntimeBeanReference clientOutChannel,
+ RuntimeBeanReference userSessionRegistry, ParserContext parserCxt, Object source) {
+
+ RootBeanDefinition stompHandlerDef = new RootBeanDefinition(StompSubProtocolHandler.class);
+ stompHandlerDef.getPropertyValues().add("userSessionRegistry", userSessionRegistry);
+ registerBeanDef(stompHandlerDef, parserCxt, source);
+
+ ConstructorArgumentValues cavs = new ConstructorArgumentValues();
+ cavs.addIndexedArgumentValue(0, clientInChannel);
+ cavs.addIndexedArgumentValue(1, clientOutChannel);
+
+ RootBeanDefinition subProtocolWshDef = new RootBeanDefinition(SubProtocolWebSocketHandler.class, cavs, null);
+ subProtocolWshDef.getPropertyValues().addPropertyValue("protocolHandlers", stompHandlerDef);
+ String subProtocolWshName = registerBeanDef(subProtocolWshDef, parserCxt, source);
+ return new RuntimeBeanReference(subProtocolWshName);
+ }
+
+ private RuntimeBeanReference registerHttpRequestHandler(Element stompEndpointElement,
+ RuntimeBeanReference subProtocolWebSocketHandler, ParserContext parserCxt, Object source) {
+
+ RootBeanDefinition httpRequestHandlerDef;
+
+ RuntimeBeanReference handshakeHandler =
+ WebSocketNamespaceUtils.registerHandshakeHandler(stompEndpointElement, parserCxt, source);
+
+ RuntimeBeanReference sockJsService = WebSocketNamespaceUtils.registerSockJsService(
+ stompEndpointElement, SOCKJS_SCHEDULER_BEAN_NAME, parserCxt, source);
+
+ if (sockJsService != null) {
+ ConstructorArgumentValues cavs = new ConstructorArgumentValues();
+ cavs.addIndexedArgumentValue(0, sockJsService);
+ cavs.addIndexedArgumentValue(1, subProtocolWebSocketHandler);
+ httpRequestHandlerDef = new RootBeanDefinition(SockJsHttpRequestHandler.class, cavs, null);
+ }
+ else {
+ ConstructorArgumentValues cavs = new ConstructorArgumentValues();
+ cavs.addIndexedArgumentValue(0, subProtocolWebSocketHandler);
+ if(handshakeHandler != null) {
+ cavs.addIndexedArgumentValue(1, handshakeHandler);
+ }
+ httpRequestHandlerDef = new RootBeanDefinition(WebSocketHttpRequestHandler.class, cavs, null);
+ // TODO: httpRequestHandlerDef.getPropertyValues().add("handshakeInterceptors", ...);
+ }
+
+ String httpRequestHandlerBeanName = registerBeanDef(httpRequestHandlerDef, parserCxt, source);
+ return new RuntimeBeanReference(httpRequestHandlerBeanName);
+ }
+
+ private void registerMessageBroker(Element messageBrokerElement, RuntimeBeanReference clientInChannelDef,
+ RuntimeBeanReference clientOutChannelDef, RuntimeBeanReference brokerChannelDef,
+ ParserContext parserCxt, Object source) {
+
+ Element simpleBrokerElem = DomUtils.getChildElementByTagName(messageBrokerElement, "simple-broker");
+ Element brokerRelayElem = DomUtils.getChildElementByTagName(messageBrokerElement, "stomp-broker-relay");
+
+ ConstructorArgumentValues cavs = new ConstructorArgumentValues();
+ cavs.addIndexedArgumentValue(0, clientInChannelDef);
+ cavs.addIndexedArgumentValue(1, clientOutChannelDef);
+ cavs.addIndexedArgumentValue(2, brokerChannelDef);
+
+ if (simpleBrokerElem != null) {
+
+ String prefix = simpleBrokerElem.getAttribute("prefix");
+ cavs.addIndexedArgumentValue(3, Arrays.asList(prefix.split(",")));
+ RootBeanDefinition brokerDef = new RootBeanDefinition(SimpleBrokerMessageHandler.class, cavs, null);
+ registerBeanDef(brokerDef, parserCxt, source);
+ }
+ else if (brokerRelayElem != null) {
+
+ String prefix = brokerRelayElem.getAttribute("prefix");
+ cavs.addIndexedArgumentValue(3, Arrays.asList(prefix.split(",")));
+
+ MutablePropertyValues mpvs = new MutablePropertyValues();
+ String relayHost = brokerRelayElem.getAttribute("relay-host");
+ if(!relayHost.isEmpty()) {
+ mpvs.add("relayHost",relayHost);
+ }
+ String relayPort = brokerRelayElem.getAttribute("relay-port");
+ if(!relayPort.isEmpty()) {
+ mpvs.add("relayPort", Integer.valueOf(relayPort));
+ }
+ String systemLogin = brokerRelayElem.getAttribute("system-login");
+ if(!systemLogin.isEmpty()) {
+ mpvs.add("systemLogin",systemLogin);
+ }
+ String systemPasscode = brokerRelayElem.getAttribute("system-passcode");
+ if(!systemPasscode.isEmpty()) {
+ mpvs.add("systemPasscode",systemPasscode);
+ }
+ String systemHeartbeatSendInterval = brokerRelayElem.getAttribute("system-heartbeat-send-interval");
+ if(!systemHeartbeatSendInterval.isEmpty()) {
+ mpvs.add("systemHeartbeatSendInterval",Long.parseLong(systemHeartbeatSendInterval));
+ }
+ String systemHeartbeatReceiveInterval = brokerRelayElem.getAttribute("system-heartbeat-receive-interval");
+ if(!systemHeartbeatReceiveInterval.isEmpty()) {
+ mpvs.add("systemHeartbeatReceiveInterval",Long.parseLong(systemHeartbeatReceiveInterval));
+ }
+ String virtualHost = brokerRelayElem.getAttribute("virtual-host");
+ if(!virtualHost.isEmpty()) {
+ mpvs.add("virtualHost",virtualHost);
+ }
+
+ RootBeanDefinition messageBrokerDef = new RootBeanDefinition(StompBrokerRelayMessageHandler.class, cavs, mpvs);
+ registerBeanDef(messageBrokerDef, parserCxt, source);
+ }
+
+ }
+
+ private RuntimeBeanReference registerBrokerMessageConverter(ParserContext parserCxt, Object source) {
+
+ RootBeanDefinition contentTypeResolverDef = new RootBeanDefinition(DefaultContentTypeResolver.class);
+
+ ManagedList<RootBeanDefinition> convertersDef = new ManagedList<RootBeanDefinition>();
+ if (jackson2Present) {
+ convertersDef.add(new RootBeanDefinition(MappingJackson2MessageConverter.class));
+ contentTypeResolverDef.getPropertyValues().add("defaultMimeType", MimeTypeUtils.APPLICATION_JSON);
+ }
+ convertersDef.add(new RootBeanDefinition(StringMessageConverter.class));
+ convertersDef.add(new RootBeanDefinition(ByteArrayMessageConverter.class));
+
+ ConstructorArgumentValues cavs = new ConstructorArgumentValues();
+ cavs.addIndexedArgumentValue(0, convertersDef);
+ cavs.addIndexedArgumentValue(1, contentTypeResolverDef);
+
+ RootBeanDefinition brokerMessage = new RootBeanDefinition(CompositeMessageConverter.class, cavs, null);
+ return new RuntimeBeanReference(registerBeanDef(brokerMessage,parserCxt, source));
+ }
+
+ private RuntimeBeanReference registerBrokerMessagingTemplate(
+ Element element, RuntimeBeanReference brokerChannelDef, RuntimeBeanReference messageConverterRef,
+ ParserContext parserCxt, Object source) {
+
+ ConstructorArgumentValues cavs = new ConstructorArgumentValues();
+ cavs.addIndexedArgumentValue(0, brokerChannelDef);
+ RootBeanDefinition messagingTemplateDef = new RootBeanDefinition(SimpMessagingTemplate.class,cavs, null);
+
+ String userDestinationPrefixAttribute = element.getAttribute("user-destination-prefix");
+ if(!userDestinationPrefixAttribute.isEmpty()) {
+ messagingTemplateDef.getPropertyValues().add("userDestinationPrefix", userDestinationPrefixAttribute);
+ }
+ messagingTemplateDef.getPropertyValues().add("messageConverter", messageConverterRef);
+
+ return new RuntimeBeanReference(registerBeanDef(messagingTemplateDef,parserCxt, source));
+ }
+
+ private void registerAnnotationMethodMessageHandler(Element messageBrokerElement,
+ RuntimeBeanReference clientInChannelDef, RuntimeBeanReference clientOutChannelDef,
+ RuntimeBeanReference brokerMessageConverterRef, RuntimeBeanReference brokerMessagingTemplateRef,
+ ParserContext parserCxt, Object source) {
+
+ String applicationDestinationPrefix = messageBrokerElement.getAttribute("application-destination-prefix");
+
+ ConstructorArgumentValues cavs = new ConstructorArgumentValues();
+ cavs.addIndexedArgumentValue(0, clientInChannelDef);
+ cavs.addIndexedArgumentValue(1, clientOutChannelDef);
+ cavs.addIndexedArgumentValue(2, brokerMessagingTemplateRef);
+
+ MutablePropertyValues mpvs = new MutablePropertyValues();
+ mpvs.add("destinationPrefixes",Arrays.asList(applicationDestinationPrefix.split(",")));
+ mpvs.add("messageConverter", brokerMessageConverterRef);
+
+ RootBeanDefinition annotationMethodMessageHandlerDef =
+ new RootBeanDefinition(SimpAnnotationMethodMessageHandler.class, cavs, mpvs);
+
+ registerBeanDef(annotationMethodMessageHandlerDef, parserCxt, source);
+ }
+
+ private RuntimeBeanReference registerUserDestinationResolver(Element messageBrokerElement,
+ BeanDefinition userSessionRegistryDef, ParserContext parserCxt, Object source) {
+
+ ConstructorArgumentValues cavs = new ConstructorArgumentValues();
+ cavs.addIndexedArgumentValue(0, userSessionRegistryDef);
+ RootBeanDefinition userDestinationResolverDef =
+ new RootBeanDefinition(DefaultUserDestinationResolver.class, cavs, null);
+ String prefix = messageBrokerElement.getAttribute("user-destination-prefix");
+ if (!prefix.isEmpty()) {
+ userDestinationResolverDef.getPropertyValues().add("userDestinationPrefix", prefix);
+ }
+ String userDestinationResolverName = registerBeanDef(userDestinationResolverDef, parserCxt, source);
+ return new RuntimeBeanReference(userDestinationResolverName);
+ }
+
+ private RuntimeBeanReference registerUserDestinationMessageHandler(RuntimeBeanReference clientInChannelDef,
+ RuntimeBeanReference clientOutChannelDef, RuntimeBeanReference brokerChannelDef,
+ RuntimeBeanReference userDestinationResolverRef, ParserContext parserCxt, Object source) {
+
+ ConstructorArgumentValues cavs = new ConstructorArgumentValues();
+ cavs.addIndexedArgumentValue(0, clientInChannelDef);
+ cavs.addIndexedArgumentValue(1, clientOutChannelDef);
+ cavs.addIndexedArgumentValue(2, brokerChannelDef);
+ cavs.addIndexedArgumentValue(3, userDestinationResolverRef);
+
+ RootBeanDefinition userDestinationMessageHandlerDef =
+ new RootBeanDefinition(UserDestinationMessageHandler.class, cavs, null);
+
+ String userDestinationMessageHandleName = registerBeanDef(userDestinationMessageHandlerDef, parserCxt, source);
+ return new RuntimeBeanReference(userDestinationMessageHandleName);
+ }
+
+
+ private static String registerBeanDef(RootBeanDefinition beanDef, ParserContext parserCxt, Object source) {
+ String beanName = parserCxt.getReaderContext().generateBeanName(beanDef);
+ registerBeanDefByName(beanName, beanDef, parserCxt, source);
+ return beanName;
+ }
+
+ private static void registerBeanDefByName(String beanName, RootBeanDefinition beanDef,
+ ParserContext parserCxt, Object source) {
+
+ beanDef.setSource(source);
+ beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
+ parserCxt.getRegistry().registerBeanDefinition(beanName, beanDef);
+ parserCxt.registerComponent(new BeanComponentDefinition(beanDef, beanName));
+ }
+
+} | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/main/java/org/springframework/web/socket/messaging/config/xml/WebSocketNamespaceHandler.java | @@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+package org.springframework.web.socket.messaging.config.xml;
+
+import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
+import org.springframework.util.ClassUtils;
+import org.springframework.web.socket.server.config.xml.HandlersBeanDefinitionParser;
+
+
+/**
+ * {@link org.springframework.beans.factory.xml.NamespaceHandler} for Spring WebSocket
+ * configuration namespace.
+ *
+ * @author Brian Clozel
+ * @since 4.0
+ */
+public class WebSocketNamespaceHandler extends NamespaceHandlerSupport {
+
+ private static boolean isSpringMessagingPresent = ClassUtils.isPresent(
+ "org.springframework.messaging.Message", WebSocketNamespaceHandler.class.getClassLoader());
+
+
+ @Override
+ public void init() {
+ registerBeanDefinitionParser("handlers", new HandlersBeanDefinitionParser());
+ if (isSpringMessagingPresent) {
+ registerBeanDefinitionParser("message-broker", new MessageBrokerBeanDefinitionParser());
+ }
+ }
+} | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/main/java/org/springframework/web/socket/messaging/config/xml/package-info.java | @@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Support for the {@code <websocket:message-broker>} XML namespace element.
+ */
+package org.springframework.web.socket.messaging.config.xml;
\ No newline at end of file | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/main/java/org/springframework/web/socket/server/config/xml/HandlersBeanDefinitionParser.java | @@ -0,0 +1,194 @@
+/*
+ * 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.
+ */
+
+package org.springframework.web.socket.server.config.xml;
+
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.ConstructorArgumentValues;
+import org.springframework.beans.factory.config.RuntimeBeanReference;
+import org.springframework.beans.factory.parsing.BeanComponentDefinition;
+import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
+import org.springframework.beans.factory.support.ManagedList;
+import org.springframework.beans.factory.support.ManagedMap;
+import org.springframework.beans.factory.support.RootBeanDefinition;
+import org.springframework.beans.factory.xml.BeanDefinitionParser;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.util.xml.DomUtils;
+import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
+import org.springframework.web.socket.server.support.WebSocketHttpRequestHandler;
+import org.springframework.web.socket.sockjs.SockJsHttpRequestHandler;
+import org.w3c.dom.Element;
+
+import java.util.Arrays;
+import java.util.List;
+
+
+/**
+ * A {@link BeanDefinitionParser} that provides the configuration for the
+ * {@code <websocket:handlers/>} namespace element. It registers a Spring MVC
+ * {@link org.springframework.web.servlet.handler.SimpleUrlHandlerMapping}
+ * to map HTTP WebSocket handshake requests to
+ * {@link org.springframework.web.socket.WebSocketHandler}s.
+ *
+ * @author Brian Clozel
+ * @since 4.0
+ */
+public class HandlersBeanDefinitionParser implements BeanDefinitionParser {
+
+ private static final String SOCK_JS_SCHEDULER_NAME = "SockJsScheduler";
+
+ private static final int DEFAULT_MAPPING_ORDER = 1;
+
+
+ @Override
+ public BeanDefinition parse(Element element, ParserContext parserCxt) {
+
+ Object source = parserCxt.extractSource(element);
+ CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
+ parserCxt.pushContainingComponent(compDefinition);
+
+ String orderAttribute = element.getAttribute("order");
+ int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute);
+
+ RootBeanDefinition handlerMappingDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class);
+ handlerMappingDef.setSource(source);
+ handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
+ handlerMappingDef.getPropertyValues().add("order", order);
+ String handlerMappingName = parserCxt.getReaderContext().registerWithGeneratedName(handlerMappingDef);
+
+ RuntimeBeanReference handshakeHandler = WebSocketNamespaceUtils.registerHandshakeHandler(element, parserCxt, source);
+ Element interceptorsElement = DomUtils.getChildElementByTagName(element, "handshake-interceptors");
+ ManagedList<?> interceptors = WebSocketNamespaceUtils.parseBeanSubElements(interceptorsElement, parserCxt);
+ RuntimeBeanReference sockJsServiceRef =
+ WebSocketNamespaceUtils.registerSockJsService(element, SOCK_JS_SCHEDULER_NAME, parserCxt, source);
+
+ HandlerMappingStrategy strategy = createHandlerMappingStrategy(sockJsServiceRef, handshakeHandler, interceptors);
+
+ List<Element> mappingElements = DomUtils.getChildElementsByTagName(element, "mapping");
+ ManagedMap<String, Object> urlMap = new ManagedMap<String, Object>();
+ urlMap.setSource(source);
+
+ for(Element mappingElement : mappingElements) {
+ urlMap.putAll(strategy.createMappings(mappingElement, parserCxt));
+ }
+ handlerMappingDef.getPropertyValues().add("urlMap", urlMap);
+
+ parserCxt.registerComponent(new BeanComponentDefinition(handlerMappingDef, handlerMappingName));
+ parserCxt.popAndRegisterContainingComponent();
+ return null;
+ }
+
+
+ private interface HandlerMappingStrategy {
+
+ public ManagedMap<String, Object> createMappings(Element mappingElement, ParserContext parserContext);
+ }
+
+ private HandlerMappingStrategy createHandlerMappingStrategy(
+ RuntimeBeanReference sockJsServiceRef, RuntimeBeanReference handshakeHandlerRef,
+ ManagedList<? extends Object> interceptorsList) {
+
+ if(sockJsServiceRef != null) {
+ SockJSHandlerMappingStrategy strategy = new SockJSHandlerMappingStrategy();
+ strategy.setSockJsServiceRef(sockJsServiceRef);
+ return strategy;
+ }
+ else {
+ WebSocketHandlerMappingStrategy strategy = new WebSocketHandlerMappingStrategy();
+ strategy.setHandshakeHandlerReference(handshakeHandlerRef);
+ strategy.setInterceptorsList(interceptorsList);
+ return strategy;
+ }
+ }
+
+ private class WebSocketHandlerMappingStrategy implements HandlerMappingStrategy {
+
+ private RuntimeBeanReference handshakeHandlerReference;
+
+ private ManagedList<?> interceptorsList;
+
+ public void setHandshakeHandlerReference(RuntimeBeanReference handshakeHandlerReference) {
+ this.handshakeHandlerReference = handshakeHandlerReference;
+ }
+
+ public void setInterceptorsList(ManagedList<?> interceptorsList) { this.interceptorsList = interceptorsList; }
+
+ @Override
+ public ManagedMap<String, Object> createMappings(Element mappingElement, ParserContext parserContext) {
+
+ ManagedMap<String, Object> urlMap = new ManagedMap<String, Object>();
+ Object source = parserContext.extractSource(mappingElement);
+
+ List<String> mappings = Arrays.asList(mappingElement.getAttribute("path").split(","));
+ RuntimeBeanReference webSocketHandlerReference = new RuntimeBeanReference(mappingElement.getAttribute("handler"));
+
+ ConstructorArgumentValues cavs = new ConstructorArgumentValues();
+ cavs.addIndexedArgumentValue(0, webSocketHandlerReference);
+ if(this.handshakeHandlerReference != null) {
+ cavs.addIndexedArgumentValue(1, this.handshakeHandlerReference);
+ }
+ RootBeanDefinition requestHandlerDef = new RootBeanDefinition(WebSocketHttpRequestHandler.class, cavs, null);
+ requestHandlerDef.setSource(source);
+ requestHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
+ requestHandlerDef.getPropertyValues().add("handshakeInterceptors", this.interceptorsList);
+ String requestHandlerName = parserContext.getReaderContext().registerWithGeneratedName(requestHandlerDef);
+ RuntimeBeanReference requestHandlerRef = new RuntimeBeanReference(requestHandlerName);
+
+ for(String mapping : mappings) {
+ urlMap.put(mapping, requestHandlerRef);
+ }
+
+ return urlMap;
+ }
+ }
+
+ private class SockJSHandlerMappingStrategy implements HandlerMappingStrategy {
+
+ private RuntimeBeanReference sockJsServiceRef;
+
+ public void setSockJsServiceRef(RuntimeBeanReference sockJsServiceRef) {
+ this.sockJsServiceRef = sockJsServiceRef;
+ }
+
+ @Override
+ public ManagedMap<String, Object> createMappings(Element mappingElement, ParserContext parserContext) {
+
+ ManagedMap<String, Object> urlMap = new ManagedMap<String, Object>();
+ Object source = parserContext.extractSource(mappingElement);
+
+ List<String> mappings = Arrays.asList(mappingElement.getAttribute("path").split(","));
+ RuntimeBeanReference webSocketHandlerReference = new RuntimeBeanReference(mappingElement.getAttribute("handler"));
+
+ ConstructorArgumentValues cavs = new ConstructorArgumentValues();
+ cavs.addIndexedArgumentValue(0, this.sockJsServiceRef, "SockJsService");
+ cavs.addIndexedArgumentValue(1, webSocketHandlerReference, "WebSocketHandler");
+
+ RootBeanDefinition requestHandlerDef = new RootBeanDefinition(SockJsHttpRequestHandler.class, cavs, null);
+ requestHandlerDef.setSource(source);
+ requestHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
+ String requestHandlerName = parserContext.getReaderContext().registerWithGeneratedName(requestHandlerDef);
+ RuntimeBeanReference requestHandlerRef = new RuntimeBeanReference(requestHandlerName);
+
+ for(String path : mappings) {
+ String pathPattern = path.endsWith("/") ? path + "**" : path + "/**";
+ urlMap.put(pathPattern, requestHandlerRef);
+ }
+
+ return urlMap;
+ }
+ }
+
+} | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/main/java/org/springframework/web/socket/server/config/xml/WebSocketNamespaceUtils.java | @@ -0,0 +1,178 @@
+/*
+ * 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.
+ */
+
+package org.springframework.web.socket.server.config.xml;
+
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.ConstructorArgumentValues;
+import org.springframework.beans.factory.config.RuntimeBeanReference;
+import org.springframework.beans.factory.parsing.BeanComponentDefinition;
+import org.springframework.beans.factory.support.ManagedList;
+import org.springframework.beans.factory.support.RootBeanDefinition;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
+import org.springframework.util.xml.DomUtils;
+import org.springframework.web.socket.server.DefaultHandshakeHandler;
+import org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService;
+import org.w3c.dom.Element;
+
+import java.util.Collections;
+
+/**
+ * Provides utility methods for parsing common WebSocket XML namespace elements.
+ *
+ * @author Brian Clozel
+ * @author Rossen Stoyanchev
+ * @since 4.0
+ */
+public class WebSocketNamespaceUtils {
+
+
+ public static RuntimeBeanReference registerHandshakeHandler(Element element, ParserContext parserContext, Object source) {
+
+ RuntimeBeanReference handlerRef;
+
+ Element handlerElem = DomUtils.getChildElementByTagName(element, "handshake-handler");
+ if(handlerElem != null) {
+ handlerRef = new RuntimeBeanReference(handlerElem.getAttribute("ref"));
+ }
+ else {
+ RootBeanDefinition defaultHandlerDef = new RootBeanDefinition(DefaultHandshakeHandler.class);
+ defaultHandlerDef.setSource(source);
+ defaultHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
+ String handlerName = parserContext.getReaderContext().registerWithGeneratedName(defaultHandlerDef);
+ handlerRef = new RuntimeBeanReference(handlerName);
+ }
+
+ return handlerRef;
+ }
+
+ public static RuntimeBeanReference registerSockJsService(Element element, String sockJsSchedulerName,
+ ParserContext parserContext, Object source) {
+
+ Element sockJsElement = DomUtils.getChildElementByTagName(element, "sockjs");
+
+ if(sockJsElement != null) {
+ ConstructorArgumentValues cavs = new ConstructorArgumentValues();
+
+ // TODO: polish the way constructor arguments are set
+
+ String customTaskSchedulerName = sockJsElement.getAttribute("task-scheduler");
+ if(!customTaskSchedulerName.isEmpty()) {
+ cavs.addIndexedArgumentValue(0, new RuntimeBeanReference(customTaskSchedulerName));
+ }
+ else {
+ cavs.addIndexedArgumentValue(0, registerSockJsTaskScheduler(sockJsSchedulerName, parserContext, source));
+ }
+
+ Element transportHandlersElement = DomUtils.getChildElementByTagName(sockJsElement, "transport-handlers");
+ boolean registerDefaults = true;
+ if(transportHandlersElement != null) {
+ String registerDefaultsAttribute = transportHandlersElement.getAttribute("register-defaults");
+ registerDefaults = !registerDefaultsAttribute.equals("false");
+ }
+
+ ManagedList<?> transportHandlersList = parseBeanSubElements(transportHandlersElement, parserContext);
+
+ if(registerDefaults) {
+ cavs.addIndexedArgumentValue(1, Collections.emptyList());
+ if(transportHandlersList.isEmpty()) {
+ cavs.addIndexedArgumentValue(2, new ConstructorArgumentValues.ValueHolder(null));
+ }
+ else {
+ cavs.addIndexedArgumentValue(2, transportHandlersList);
+ }
+ }
+ else {
+ if(transportHandlersList.isEmpty()) {
+ cavs.addIndexedArgumentValue(1, new ConstructorArgumentValues.ValueHolder(null));
+ }
+ else {
+ cavs.addIndexedArgumentValue(1, transportHandlersList);
+ }
+ cavs.addIndexedArgumentValue(2, new ConstructorArgumentValues.ValueHolder(null));
+ }
+
+ RootBeanDefinition sockJsServiceDef = new RootBeanDefinition(DefaultSockJsService.class, cavs, null);
+ sockJsServiceDef.setSource(source);
+
+ String attrValue = sockJsElement.getAttribute("name");
+ if(!attrValue.isEmpty()) {
+ sockJsServiceDef.getPropertyValues().add("name", attrValue);
+ }
+ attrValue = sockJsElement.getAttribute("websocket-enabled");
+ if(!attrValue.isEmpty()) {
+ sockJsServiceDef.getPropertyValues().add("webSocketsEnabled", Boolean.valueOf(attrValue));
+ }
+ attrValue = sockJsElement.getAttribute("session-cookie-needed");
+ if(!attrValue.isEmpty()) {
+ sockJsServiceDef.getPropertyValues().add("sessionCookieNeeded", Boolean.valueOf(attrValue));
+ }
+ attrValue = sockJsElement.getAttribute("stream-bytes-limit");
+ if(!attrValue.isEmpty()) {
+ sockJsServiceDef.getPropertyValues().add("streamBytesLimit", Integer.valueOf(attrValue));
+ }
+ attrValue = sockJsElement.getAttribute("disconnect-delay");
+ if(!attrValue.isEmpty()) {
+ sockJsServiceDef.getPropertyValues().add("disconnectDelay", Long.valueOf(attrValue));
+ }
+ attrValue = sockJsElement.getAttribute("http-message-cache-size");
+ if(!attrValue.isEmpty()) {
+ sockJsServiceDef.getPropertyValues().add("httpMessageCacheSize", Integer.valueOf(attrValue));
+ }
+ attrValue = sockJsElement.getAttribute("heartbeat-time");
+ if(!attrValue.isEmpty()) {
+ sockJsServiceDef.getPropertyValues().add("heartbeatTime", Long.valueOf(attrValue));
+ }
+
+ sockJsServiceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
+ String sockJsServiceName = parserContext.getReaderContext().registerWithGeneratedName(sockJsServiceDef);
+ return new RuntimeBeanReference(sockJsServiceName);
+ }
+
+ return null;
+ }
+
+ private static RuntimeBeanReference registerSockJsTaskScheduler(String schedulerName,
+ ParserContext parserContext, Object source) {
+
+ if (!parserContext.getRegistry().containsBeanDefinition(schedulerName)) {
+ RootBeanDefinition taskSchedulerDef = new RootBeanDefinition(ThreadPoolTaskScheduler.class);
+ taskSchedulerDef.setSource(source);
+ taskSchedulerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
+ taskSchedulerDef.getPropertyValues().add("threadNamePrefix", schedulerName + "-");
+ parserContext.getRegistry().registerBeanDefinition(schedulerName, taskSchedulerDef);
+ parserContext.registerComponent(new BeanComponentDefinition(taskSchedulerDef, schedulerName));
+ }
+
+ return new RuntimeBeanReference(schedulerName);
+ }
+
+ public static ManagedList<? super Object> parseBeanSubElements(Element parentElement, ParserContext parserContext) {
+
+ ManagedList<? super Object> beans = new ManagedList<Object>();
+ if (parentElement != null) {
+ beans.setSource(parserContext.extractSource(parentElement));
+ for (Element beanElement : DomUtils.getChildElementsByTagName(parentElement, new String[] { "bean", "ref" })) {
+ Object object = parserContext.getDelegate().parsePropertySubElement(beanElement, null);
+ beans.add(object);
+ }
+ }
+
+ return beans;
+ }
+
+} | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/main/java/org/springframework/web/socket/server/config/xml/package-info.java | @@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Support for the {@code <websocket:handlers>} XML namespace element.
+ */
+package org.springframework.web.socket.server.config.xml;
\ No newline at end of file | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/main/resources/META-INF/spring.handlers | @@ -0,0 +1,17 @@
+#
+# 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.
+#
+
+http\://www.springframework.org/schema/websocket=org.springframework.web.socket.messaging.config.xml.WebSocketNamespaceHandler
\ No newline at end of file | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/main/resources/META-INF/spring.schemas | @@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+http\://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd=org/springframework/web/socket/server/config/xml/spring-websocket-4.0.xsd
+http\://www.springframework.org/schema/websocket/spring-websocket.xsd=org/springframework/web/socket/server/config/xml/spring-websocket-4.0.xsd | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/main/resources/META-INF/spring.tooling | @@ -0,0 +1,4 @@
+# Tooling related information for the mvc namespace
+http\://www.springframework.org/schema/websocket@name=websocket Namespace
+http\://www.springframework.org/schema/websocket@prefix=websocket
+http\://www.springframework.org/schema/websocket@icon=org/springframework/web/socket/server/config/xml/spring-websocket.gif | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/main/resources/org/springframework/web/socket/server/config/xml/spring-websocket-4.0.xsd | @@ -0,0 +1,217 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!--
+ ~ 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.
+ -->
+
+<xsd:schema xmlns="http://www.springframework.org/schema/websocket"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:beans="http://www.springframework.org/schema/beans"
+ targetNamespace="http://www.springframework.org/schema/websocket"
+ elementFormDefault="qualified"
+ attributeFormDefault="unqualified">
+
+ <xsd:import namespace="http://www.springframework.org/schema/beans"
+ schemaLocation="http://www.springframework.org/schema/beans/spring-beans-4.0.xsd" />
+
+ <xsd:complexType name="mapping">
+ <xsd:attribute name="path" type="xsd:string" use="required">
+ </xsd:attribute>
+ <xsd:attribute name="handler" type="xsd:string" use="required">
+ </xsd:attribute>
+ </xsd:complexType>
+
+ <xsd:complexType name="handshake-handler">
+ <xsd:attribute name="ref" type="xsd:string" use="required">
+ </xsd:attribute>
+ </xsd:complexType>
+
+ <xsd:complexType name="handshake-interceptors">
+ <xsd:sequence>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element ref="beans:bean">
+ <xsd:annotation>
+ <xsd:documentation><![CDATA[
+ An HandshakeInterceptor bean definition.
+ ]]></xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ <xsd:element ref="beans:ref">
+ <xsd:annotation>
+ <xsd:documentation><![CDATA[
+ A reference to a HandshakeInterceptor bean.
+ ]]></xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="sockjs-service">
+ <xsd:sequence>
+ <xsd:element name="transport-handlers" minOccurs="0" maxOccurs="1">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element ref="beans:bean">
+ <xsd:annotation>
+ <xsd:documentation><![CDATA[
+ An TransportHandler bean definition.
+ ]]></xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ <xsd:element ref="beans:ref">
+ <xsd:annotation>
+ <xsd:documentation><![CDATA[
+ A reference to a TransportHandler bean.
+ ]]></xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:sequence>
+ <xsd:attribute name="register-defaults" type="xsd:boolean" default="true">
+ </xsd:attribute>
+ </xsd:complexType>
+
+ </xsd:element>
+
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string">
+ </xsd:attribute>
+ <xsd:attribute name="client-library-url" type="xsd:string">
+ </xsd:attribute>
+ <xsd:attribute name="stream-bytes-limit" type="xsd:long">
+ </xsd:attribute>
+ <xsd:attribute name="session-cookie-needed" type="xsd:boolean">
+ </xsd:attribute>
+ <xsd:attribute name="heartbeat-time" type="xsd:long">
+ </xsd:attribute>
+ <xsd:attribute name="disconnect-delay" type="xsd:long">
+ </xsd:attribute>
+ <xsd:attribute name="http-message-cache-size" type="xsd:long">
+ </xsd:attribute>
+ <xsd:attribute name="websocket-enabled" type="xsd:boolean">
+ </xsd:attribute>
+ <xsd:attribute name="task-scheduler" type="xsd:string">
+ </xsd:attribute>
+ </xsd:complexType>
+
+ <xsd:complexType name="stomp-broker-relay">
+ <xsd:attribute name="prefix" type="xsd:string"></xsd:attribute>
+ <xsd:attribute name="relay-host" type="xsd:string"></xsd:attribute>
+ <xsd:attribute name="relay-port" type="xsd:integer"></xsd:attribute>
+ <xsd:attribute name="system-login" type="xsd:string"></xsd:attribute>
+ <xsd:attribute name="system-passcode" type="xsd:string"></xsd:attribute>
+ <xsd:attribute name="system-heartbeat-send-interval" type="xsd:long"></xsd:attribute>
+ <xsd:attribute name="system-heartbeat-receive-interval" type="xsd:long"></xsd:attribute>
+ <xsd:attribute name="auto-startup" type="xsd:boolean"></xsd:attribute>
+ <xsd:attribute name="virtual-host" type="xsd:string"></xsd:attribute>
+ </xsd:complexType>
+
+ <xsd:complexType name="simple-broker">
+ <xsd:attribute name="prefix" type="xsd:string"></xsd:attribute>
+ </xsd:complexType>
+
+ <xsd:complexType name="channel">
+ <xsd:sequence>
+ <xsd:element name="executor" type="channel-executor" minOccurs="0" maxOccurs="1" />
+ <xsd:element name="interceptors" type="channel-interceptors" minOccurs="0" maxOccurs="1"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="channel-executor">
+ <xsd:attribute name="core-pool-size" type="xsd:int" use="optional">
+ </xsd:attribute>
+ <xsd:attribute name="max-pool-size" type="xsd:int" use="optional">
+ </xsd:attribute>
+ <xsd:attribute name="keep-alive-seconds" type="xsd:int" use="optional">
+ </xsd:attribute>
+ <xsd:attribute name="queue-capacity" type="xsd:int" use="optional">
+ </xsd:attribute>
+ </xsd:complexType>
+
+ <xsd:complexType name="channel-interceptors">
+ <xsd:sequence>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element ref="beans:bean">
+ <xsd:annotation>
+ <xsd:documentation><![CDATA[
+ A ChannelInterceptor bean definition.
+ ]]></xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ <xsd:element ref="beans:ref">
+ <xsd:annotation>
+ <xsd:documentation><![CDATA[
+ A reference to a ChannelInterceptor bean.
+ ]]></xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <!-- Elements definitions -->
+
+ <xsd:element name="handlers">
+ <xsd:annotation>
+ <xsd:documentation><![CDATA[
+
+
+ ]]></xsd:documentation>
+ </xsd:annotation>
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="mapping" type="mapping" minOccurs="1" maxOccurs="unbounded" />
+ <xsd:element name="handshake-handler" type="handshake-handler" minOccurs="0" maxOccurs="1" />
+ <xsd:element name="handshake-interceptors" type="handshake-interceptors" minOccurs="0" maxOccurs="1"/>
+ <xsd:element name="sockjs" type="sockjs-service" minOccurs="0" maxOccurs="1"/>
+ </xsd:sequence>
+ <xsd:attribute name="order" type="xsd:integer"></xsd:attribute>
+ </xsd:complexType>
+ </xsd:element>
+
+ <xsd:element name="message-broker">
+ <xsd:annotation>
+ <xsd:documentation><![CDATA[
+
+
+ ]]></xsd:documentation>
+ </xsd:annotation>
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="stomp-endpoint" maxOccurs="unbounded">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="handshake-handler" type="handshake-handler" minOccurs="0" maxOccurs="1" />
+ <xsd:element name="sockjs" type="sockjs-service" minOccurs="0" maxOccurs="1"/>
+ </xsd:sequence>
+ <xsd:attribute name="path" type="xsd:string"></xsd:attribute>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:choice>
+ <xsd:element name="simple-broker" type="simple-broker" />
+ <xsd:element name="stomp-broker-relay" type="stomp-broker-relay" />
+ </xsd:choice>
+ <xsd:element name="client-inbound-channel" type="channel" minOccurs="0" maxOccurs="1" />
+ <xsd:element name="client-outbound-channel" type="channel" minOccurs="0" maxOccurs="1" />
+ <xsd:element name="broker-channel" type="channel" minOccurs="0" maxOccurs="1" />
+ </xsd:sequence>
+ <xsd:attribute name="application-destination-prefix" type="xsd:string" />
+ <xsd:attribute name="user-destination-prefix" type="xsd:string" />
+ <xsd:attribute name="order" type="xsd:integer" />
+ </xsd:complexType>
+ </xsd:element>
+</xsd:schema> | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/test/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandlerTests.java | @@ -23,6 +23,7 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.messaging.MessageChannel;
+import org.springframework.messaging.SubscribableChannel;
import org.springframework.web.socket.support.TestWebSocketSession;
import static org.mockito.Mockito.*;
@@ -45,14 +46,17 @@ public class SubProtocolWebSocketHandlerTests {
@Mock SubProtocolHandler defaultHandler;
- @Mock MessageChannel channel;
+ @Mock MessageChannel inClientChannel;
+
+ @Mock
+ SubscribableChannel outClientChannel;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
- this.webSocketHandler = new SubProtocolWebSocketHandler(this.channel);
+ this.webSocketHandler = new SubProtocolWebSocketHandler(this.inClientChannel, this.outClientChannel);
when(stompHandler.getSupportedProtocols()).thenReturn(Arrays.asList("v10.stomp", "v11.stomp", "v12.stomp"));
when(mqttHandler.getSupportedProtocols()).thenReturn(Arrays.asList("MQTT"));
@@ -67,8 +71,8 @@ public void subProtocolMatch() throws Exception {
this.session.setAcceptedProtocol("v12.sToMp");
this.webSocketHandler.afterConnectionEstablished(session);
- verify(this.stompHandler).afterSessionStarted(session, this.channel);
- verify(this.mqttHandler, times(0)).afterSessionStarted(session, this.channel);
+ verify(this.stompHandler).afterSessionStarted(session, this.inClientChannel);
+ verify(this.mqttHandler, times(0)).afterSessionStarted(session, this.inClientChannel);
}
@Test
@@ -77,7 +81,7 @@ public void subProtocolDefaultHandlerOnly() throws Exception {
this.session.setAcceptedProtocol("v12.sToMp");
this.webSocketHandler.afterConnectionEstablished(session);
- verify(this.stompHandler).afterSessionStarted(session, this.channel);
+ verify(this.stompHandler).afterSessionStarted(session, this.inClientChannel);
}
@Test(expected=IllegalStateException.class)
@@ -94,9 +98,9 @@ public void nullSubProtocol() throws Exception {
this.webSocketHandler.setDefaultProtocolHandler(defaultHandler);
this.webSocketHandler.afterConnectionEstablished(session);
- verify(this.defaultHandler).afterSessionStarted(session, this.channel);
- verify(this.stompHandler, times(0)).afterSessionStarted(session, this.channel);
- verify(this.mqttHandler, times(0)).afterSessionStarted(session, this.channel);
+ verify(this.defaultHandler).afterSessionStarted(session, this.inClientChannel);
+ verify(this.stompHandler, times(0)).afterSessionStarted(session, this.inClientChannel);
+ verify(this.mqttHandler, times(0)).afterSessionStarted(session, this.inClientChannel);
}
@Test
@@ -105,17 +109,17 @@ public void emptySubProtocol() throws Exception {
this.webSocketHandler.setDefaultProtocolHandler(defaultHandler);
this.webSocketHandler.afterConnectionEstablished(session);
- verify(this.defaultHandler).afterSessionStarted(session, this.channel);
- verify(this.stompHandler, times(0)).afterSessionStarted(session, this.channel);
- verify(this.mqttHandler, times(0)).afterSessionStarted(session, this.channel);
+ verify(this.defaultHandler).afterSessionStarted(session, this.inClientChannel);
+ verify(this.stompHandler, times(0)).afterSessionStarted(session, this.inClientChannel);
+ verify(this.mqttHandler, times(0)).afterSessionStarted(session, this.inClientChannel);
}
@Test
public void noSubProtocolOneHandler() throws Exception {
this.webSocketHandler.setProtocolHandlers(Arrays.asList(stompHandler));
this.webSocketHandler.afterConnectionEstablished(session);
- verify(this.stompHandler).afterSessionStarted(session, this.channel);
+ verify(this.stompHandler).afterSessionStarted(session, this.inClientChannel);
}
@Test(expected=IllegalStateException.class) | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/test/java/org/springframework/web/socket/messaging/config/WebMvcStompEndpointRegistrationTests.java | @@ -51,7 +51,8 @@ public class WebMvcStompEndpointRegistrationTests {
@Before
public void setup() {
- this.wsHandler = new SubProtocolWebSocketHandler(new ExecutorSubscribableChannel());
+ this.wsHandler = new SubProtocolWebSocketHandler(
+ new ExecutorSubscribableChannel(), new ExecutorSubscribableChannel());
this.scheduler = Mockito.mock(TaskScheduler.class);
}
| true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/test/java/org/springframework/web/socket/messaging/config/WebMvcStompEndpointRegistryTests.java | @@ -22,6 +22,7 @@
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.messaging.MessageChannel;
+import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.simp.handler.DefaultUserSessionRegistry;
import org.springframework.messaging.simp.handler.UserSessionRegistry;
import org.springframework.scheduling.TaskScheduler;
@@ -49,8 +50,9 @@ public class WebMvcStompEndpointRegistryTests {
@Before
public void setup() {
- MessageChannel channel = Mockito.mock(MessageChannel.class);
- this.webSocketHandler = new SubProtocolWebSocketHandler(channel);
+ MessageChannel inChannel = Mockito.mock(MessageChannel.class);
+ SubscribableChannel outChannel = Mockito.mock(SubscribableChannel.class);
+ this.webSocketHandler = new SubProtocolWebSocketHandler(inChannel, outChannel);
this.userSessionRegistry = new DefaultUserSessionRegistry();
TaskScheduler taskScheduler = Mockito.mock(TaskScheduler.class);
this.registry = new WebMvcStompEndpointRegistry(webSocketHandler, userSessionRegistry, taskScheduler);
@@ -62,7 +64,7 @@ public void stompProtocolHandler() {
this.registry.addEndpoint("/stomp");
- Map<String, SubProtocolHandler> protocolHandlers = webSocketHandler.getProtocolHandlers();
+ Map<String, SubProtocolHandler> protocolHandlers = webSocketHandler.getProtocolHandlerMap();
assertEquals(3, protocolHandlers.size());
assertNotNull(protocolHandlers.get("v10.stomp"));
assertNotNull(protocolHandlers.get("v11.stomp")); | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/test/java/org/springframework/web/socket/messaging/config/xml/MessageBrokerBeanDefinitionParserTests.java | @@ -0,0 +1,267 @@
+/*
+ * 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.
+ */
+
+package org.springframework.web.socket.messaging.config.xml;
+
+import org.hamcrest.Matchers;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.messaging.MessageHandler;
+import org.springframework.messaging.simp.SimpMessagingTemplate;
+import org.springframework.messaging.simp.handler.*;
+import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
+import org.springframework.messaging.support.channel.AbstractSubscribableChannel;
+import org.springframework.messaging.support.converter.CompositeMessageConverter;
+import org.springframework.messaging.support.converter.MessageConverter;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+import org.springframework.web.HttpRequestHandler;
+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.SubProtocolWebSocketHandler;
+import org.springframework.web.socket.server.support.WebSocketHttpRequestHandler;
+import org.springframework.web.socket.sockjs.SockJsHttpRequestHandler;
+import org.springframework.web.socket.support.WebSocketHandlerDecorator;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test fixture for the configuration in websocket-config-broker*.xml test files.
+ * @author Brian Clozel
+ */
+public class MessageBrokerBeanDefinitionParserTests {
+
+ private GenericWebApplicationContext appContext;
+
+ @Before
+ public void setup() {
+ this.appContext = new GenericWebApplicationContext();
+ }
+
+ @Test
+ public void simpleBroker() {
+
+ loadBeanDefinitions("websocket-config-broker-simple.xml");
+
+ HandlerMapping hm = this.appContext.getBean(HandlerMapping.class);
+ assertNotNull(hm);
+ assertThat(hm, Matchers.instanceOf(SimpleUrlHandlerMapping.class));
+
+ SimpleUrlHandlerMapping suhm = (SimpleUrlHandlerMapping) hm;
+ assertThat(suhm.getUrlMap().keySet(), Matchers.hasSize(4));
+ assertThat(suhm.getUrlMap().values(), Matchers.hasSize(4));
+
+ HttpRequestHandler httpRequestHandler = (HttpRequestHandler) suhm.getUrlMap().get("/foo");
+ assertNotNull(httpRequestHandler);
+ assertThat(httpRequestHandler, Matchers.instanceOf(WebSocketHttpRequestHandler.class));
+ WebSocketHttpRequestHandler wsHttpRequestHandler = (WebSocketHttpRequestHandler) httpRequestHandler;
+ WebSocketHandler wsHandler = unwrapWebSocketHandler(wsHttpRequestHandler.getWebSocketHandler());
+ assertNotNull(wsHandler);
+ assertThat(wsHandler, Matchers.instanceOf(SubProtocolWebSocketHandler.class));
+ SubProtocolWebSocketHandler subProtocolWsHandler = (SubProtocolWebSocketHandler) wsHandler;
+ assertEquals(Arrays.asList("v10.stomp", "v11.stomp", "v12.stomp"), subProtocolWsHandler.getSubProtocols());
+
+ httpRequestHandler = (HttpRequestHandler) suhm.getUrlMap().get("/test/**");
+ assertNotNull(httpRequestHandler);
+ assertThat(httpRequestHandler, Matchers.instanceOf(SockJsHttpRequestHandler.class));
+ SockJsHttpRequestHandler sockJsHttpRequestHandler = (SockJsHttpRequestHandler) httpRequestHandler;
+ wsHandler = unwrapWebSocketHandler(sockJsHttpRequestHandler.getWebSocketHandler());
+ assertNotNull(wsHandler);
+ assertThat(wsHandler, Matchers.instanceOf(SubProtocolWebSocketHandler.class));
+ assertNotNull(sockJsHttpRequestHandler.getSockJsService());
+
+ UserDestinationResolver userDestResolver = this.appContext.getBean(UserDestinationResolver.class);
+ assertNotNull(userDestResolver);
+ assertThat(userDestResolver, Matchers.instanceOf(DefaultUserDestinationResolver.class));
+ DefaultUserDestinationResolver defaultUserDestResolver = (DefaultUserDestinationResolver) userDestResolver;
+ assertEquals("/personal/", defaultUserDestResolver.getDestinationPrefix());
+
+ List<Class<? extends MessageHandler>> subscriberTypes =
+ Arrays.<Class<? extends MessageHandler>>asList(SimpAnnotationMethodMessageHandler.class,
+ UserDestinationMessageHandler.class, SimpleBrokerMessageHandler.class);
+ testChannel("clientInboundChannel", subscriberTypes, 0);
+ testExecutor("clientInboundChannel", 1, Integer.MAX_VALUE, 60);
+
+ subscriberTypes = Arrays.<Class<? extends MessageHandler>>asList(SubProtocolWebSocketHandler.class);
+ testChannel("clientOutboundChannel", subscriberTypes, 0);
+ testExecutor("clientOutboundChannel", 1, Integer.MAX_VALUE, 60);
+
+ subscriberTypes = Arrays.<Class<? extends MessageHandler>>asList(
+ SimpleBrokerMessageHandler.class, UserDestinationMessageHandler.class);
+ testChannel("brokerChannel", subscriberTypes, 0);
+ try {
+ this.appContext.getBean("brokerChannelExecutor", ThreadPoolTaskExecutor.class);
+ fail("expected exception");
+ }
+ catch (NoSuchBeanDefinitionException ex) {
+ // expected
+ }
+ }
+
+ @Test
+ public void stompBrokerRelay() {
+
+ loadBeanDefinitions("websocket-config-broker-relay.xml");
+
+ HandlerMapping hm = this.appContext.getBean(HandlerMapping.class);
+ assertNotNull(hm);
+ assertThat(hm, Matchers.instanceOf(SimpleUrlHandlerMapping.class));
+
+ SimpleUrlHandlerMapping suhm = (SimpleUrlHandlerMapping) hm;
+ assertThat(suhm.getUrlMap().keySet(), Matchers.hasSize(1));
+ assertThat(suhm.getUrlMap().values(), Matchers.hasSize(1));
+ assertEquals(2, suhm.getOrder());
+
+ HttpRequestHandler httpRequestHandler = (HttpRequestHandler) suhm.getUrlMap().get("/foo/**");
+ assertNotNull(httpRequestHandler);
+ assertThat(httpRequestHandler, Matchers.instanceOf(SockJsHttpRequestHandler.class));
+ SockJsHttpRequestHandler sockJsHttpRequestHandler = (SockJsHttpRequestHandler) httpRequestHandler;
+ WebSocketHandler wsHandler = unwrapWebSocketHandler(sockJsHttpRequestHandler.getWebSocketHandler());
+ assertNotNull(wsHandler);
+ assertThat(wsHandler, Matchers.instanceOf(SubProtocolWebSocketHandler.class));
+ assertNotNull(sockJsHttpRequestHandler.getSockJsService());
+
+ UserDestinationResolver userDestResolver = this.appContext.getBean(UserDestinationResolver.class);
+ assertNotNull(userDestResolver);
+ assertThat(userDestResolver, Matchers.instanceOf(DefaultUserDestinationResolver.class));
+ DefaultUserDestinationResolver defaultUserDestResolver = (DefaultUserDestinationResolver) userDestResolver;
+ assertEquals("/user/", defaultUserDestResolver.getDestinationPrefix());
+
+ StompBrokerRelayMessageHandler messageBroker = this.appContext.getBean(StompBrokerRelayMessageHandler.class);
+ assertNotNull(messageBroker);
+ assertEquals("login", messageBroker.getSystemLogin());
+ assertEquals("pass", messageBroker.getSystemPasscode());
+ assertEquals("relayhost", messageBroker.getRelayHost());
+ assertEquals(1234, messageBroker.getRelayPort());
+ assertEquals("spring.io", messageBroker.getVirtualHost());
+ assertEquals(5000, messageBroker.getSystemHeartbeatReceiveInterval());
+ assertEquals(5000, messageBroker.getSystemHeartbeatSendInterval());
+ assertThat(messageBroker.getDestinationPrefixes(), Matchers.containsInAnyOrder("/topic","/queue"));
+
+ List<Class<? extends MessageHandler>> subscriberTypes =
+ Arrays.<Class<? extends MessageHandler>>asList(SimpAnnotationMethodMessageHandler.class,
+ UserDestinationMessageHandler.class, StompBrokerRelayMessageHandler.class);
+ testChannel("clientInboundChannel", subscriberTypes, 0);
+ testExecutor("clientInboundChannel", 1, Integer.MAX_VALUE, 60);
+
+ subscriberTypes = Arrays.<Class<? extends MessageHandler>>asList(SubProtocolWebSocketHandler.class);
+ testChannel("clientOutboundChannel", subscriberTypes, 0);
+ testExecutor("clientOutboundChannel", 1, Integer.MAX_VALUE, 60);
+
+ subscriberTypes = Arrays.<Class<? extends MessageHandler>>asList(
+ StompBrokerRelayMessageHandler.class, UserDestinationMessageHandler.class);
+ testChannel("brokerChannel", subscriberTypes, 0);
+ try {
+ this.appContext.getBean("brokerChannelExecutor", ThreadPoolTaskExecutor.class);
+ fail("expected exception");
+ }
+ catch (NoSuchBeanDefinitionException ex) {
+ // expected
+ }
+ }
+
+ @Test
+ public void annotationMethodMessageHandler() {
+
+ loadBeanDefinitions("websocket-config-broker-simple.xml");
+
+ SimpAnnotationMethodMessageHandler annotationMethodMessageHandler =
+ this.appContext.getBean(SimpAnnotationMethodMessageHandler.class);
+
+ assertNotNull(annotationMethodMessageHandler);
+ MessageConverter messageConverter = annotationMethodMessageHandler.getMessageConverter();
+ assertNotNull(messageConverter);
+ assertTrue(messageConverter instanceof CompositeMessageConverter);
+
+
+ CompositeMessageConverter compositeMessageConverter = this.appContext.getBean(CompositeMessageConverter.class);
+ assertNotNull(compositeMessageConverter);
+
+ SimpMessagingTemplate simpMessagingTemplate = this.appContext.getBean(SimpMessagingTemplate.class);
+ assertNotNull(simpMessagingTemplate);
+ assertEquals("/personal", simpMessagingTemplate.getUserDestinationPrefix());
+
+ }
+
+ @Test
+ public void customChannels() {
+
+ loadBeanDefinitions("websocket-config-broker-customchannels.xml");
+
+ List<Class<? extends MessageHandler>> subscriberTypes =
+ Arrays.<Class<? extends MessageHandler>>asList(SimpAnnotationMethodMessageHandler.class,
+ UserDestinationMessageHandler.class, SimpleBrokerMessageHandler.class);
+
+ testChannel("clientInboundChannel", subscriberTypes, 1);
+ testExecutor("clientInboundChannel", 100, 200, 600);
+
+ subscriberTypes = Arrays.<Class<? extends MessageHandler>>asList(SubProtocolWebSocketHandler.class);
+
+ testChannel("clientOutboundChannel", subscriberTypes, 2);
+ testExecutor("clientOutboundChannel", 101, 201, 601);
+
+ subscriberTypes = Arrays.<Class<? extends MessageHandler>>asList(SimpleBrokerMessageHandler.class,
+ UserDestinationMessageHandler.class);
+
+ testChannel("brokerChannel", subscriberTypes, 0);
+ testExecutor("brokerChannel", 102, 202, 602);
+ }
+
+ private void testChannel(String channelName, List<Class<? extends MessageHandler>> subscriberTypes,
+ int interceptorCount) {
+
+ AbstractSubscribableChannel channel = this.appContext.getBean(channelName, AbstractSubscribableChannel.class);
+
+ for (Class<? extends MessageHandler> subscriberType : subscriberTypes) {
+ MessageHandler subscriber = this.appContext.getBean(subscriberType);
+ assertNotNull("No subsription for " + subscriberType, subscriber);
+ assertTrue(channel.hasSubscription(subscriber));
+ }
+
+ assertEquals(interceptorCount, channel.getInterceptors().size());
+ }
+
+ private void testExecutor(String channelName, int corePoolSize, int maxPoolSize, int keepAliveSeconds) {
+
+ ThreadPoolTaskExecutor taskExecutor =
+ this.appContext.getBean(channelName + "Executor", ThreadPoolTaskExecutor.class);
+
+ assertEquals(corePoolSize, taskExecutor.getCorePoolSize());
+ assertEquals(maxPoolSize, taskExecutor.getMaxPoolSize());
+ assertEquals(keepAliveSeconds, taskExecutor.getKeepAliveSeconds());
+ }
+
+ private void loadBeanDefinitions(String fileName) {
+ XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.appContext);
+ ClassPathResource resource = new ClassPathResource(fileName, MessageBrokerBeanDefinitionParserTests.class);
+ reader.loadBeanDefinitions(resource);
+ this.appContext.refresh();
+ }
+
+ private WebSocketHandler unwrapWebSocketHandler(WebSocketHandler handler) {
+ return (handler instanceof WebSocketHandlerDecorator) ?
+ ((WebSocketHandlerDecorator) handler).getLastHandler() : handler;
+ }
+
+}
\ No newline at end of file | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/test/java/org/springframework/web/socket/server/config/xml/HandlersBeanDefinitionParserTests.java | @@ -0,0 +1,291 @@
+/*
+ * 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.
+ */
+
+package org.springframework.web.socket.server.config.xml;
+
+import org.hamcrest.Matchers;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.beans.DirectFieldAccessor;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.http.server.ServerHttpRequest;
+import org.springframework.http.server.ServerHttpResponse;
+import org.springframework.scheduling.TaskScheduler;
+import org.springframework.scheduling.Trigger;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
+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.CloseStatus;
+import org.springframework.web.socket.WebSocketHandler;
+import org.springframework.web.socket.WebSocketMessage;
+import org.springframework.web.socket.WebSocketSession;
+import org.springframework.web.socket.server.DefaultHandshakeHandler;
+import org.springframework.web.socket.server.HandshakeFailureException;
+import org.springframework.web.socket.server.HandshakeHandler;
+import org.springframework.web.socket.server.HandshakeInterceptor;
+import org.springframework.web.socket.server.support.WebSocketHttpRequestHandler;
+import org.springframework.web.socket.sockjs.SockJsHttpRequestHandler;
+import org.springframework.web.socket.sockjs.SockJsService;
+import org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService;
+import org.springframework.web.socket.sockjs.transport.handler.EventSourceTransportHandler;
+import org.springframework.web.socket.sockjs.transport.handler.HtmlFileTransportHandler;
+import org.springframework.web.socket.sockjs.transport.handler.JsonpPollingTransportHandler;
+import org.springframework.web.socket.sockjs.transport.handler.JsonpReceivingTransportHandler;
+import org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler;
+import org.springframework.web.socket.sockjs.transport.handler.XhrPollingTransportHandler;
+import org.springframework.web.socket.sockjs.transport.handler.XhrReceivingTransportHandler;
+import org.springframework.web.socket.sockjs.transport.handler.XhrStreamingTransportHandler;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ScheduledFuture;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test fixture for HandlersBeanDefinitionParser.
+ * See test configuration files websocket-config-handlers*.xml.
+ *
+ * @author Brian Clozel
+ */
+public class HandlersBeanDefinitionParserTests {
+
+ private GenericWebApplicationContext appContext;
+
+
+ @Before
+ public void setup() {
+ appContext = new GenericWebApplicationContext();
+ }
+
+ @Test
+ public void webSocketHandlers() {
+ loadBeanDefinitions("websocket-config-handlers.xml");
+ Map<String, HandlerMapping> handlersMap = appContext.getBeansOfType(HandlerMapping.class);
+ assertNotNull(handlersMap);
+ assertThat(handlersMap.values(), Matchers.hasSize(2));
+
+ for(HandlerMapping handlerMapping : handlersMap.values()) {
+ assertTrue(handlerMapping instanceof SimpleUrlHandlerMapping);
+ SimpleUrlHandlerMapping urlHandlerMapping = (SimpleUrlHandlerMapping) handlerMapping;
+
+ if(urlHandlerMapping.getUrlMap().keySet().contains("/foo")) {
+ assertThat(urlHandlerMapping.getUrlMap().keySet(),Matchers.contains("/foo","/bar"));
+ WebSocketHttpRequestHandler handler = (WebSocketHttpRequestHandler)
+ urlHandlerMapping.getUrlMap().get("/foo");
+ assertNotNull(handler);
+ checkDelegateHandlerType(handler.getWebSocketHandler(), FooWebSocketHandler.class);
+ HandshakeHandler handshakeHandler = (HandshakeHandler)
+ new DirectFieldAccessor(handler).getPropertyValue("handshakeHandler");
+ assertNotNull(handshakeHandler);
+ assertTrue(handshakeHandler instanceof DefaultHandshakeHandler);
+ }
+ else {
+ assertThat(urlHandlerMapping.getUrlMap().keySet(),Matchers.contains("/test"));
+ WebSocketHttpRequestHandler handler = (WebSocketHttpRequestHandler)
+ urlHandlerMapping.getUrlMap().get("/test");
+ assertNotNull(handler);
+ checkDelegateHandlerType(handler.getWebSocketHandler(), TestWebSocketHandler.class);
+ HandshakeHandler handshakeHandler = (HandshakeHandler)
+ new DirectFieldAccessor(handler).getPropertyValue("handshakeHandler");
+ assertNotNull(handshakeHandler);
+ assertTrue(handshakeHandler instanceof DefaultHandshakeHandler);
+ }
+ }
+ }
+
+ @Test
+ public void websocketHandlersAttributes() {
+ loadBeanDefinitions("websocket-config-handlers-attributes.xml");
+ HandlerMapping handlerMapping = appContext.getBean(HandlerMapping.class);
+ assertNotNull(handlerMapping);
+ assertTrue(handlerMapping instanceof SimpleUrlHandlerMapping);
+
+ SimpleUrlHandlerMapping urlHandlerMapping = (SimpleUrlHandlerMapping) handlerMapping;
+ assertEquals(2, urlHandlerMapping.getOrder());
+
+ WebSocketHttpRequestHandler handler = (WebSocketHttpRequestHandler) urlHandlerMapping.getUrlMap().get("/foo");
+ assertNotNull(handler);
+ checkDelegateHandlerType(handler.getWebSocketHandler(), FooWebSocketHandler.class);
+ HandshakeHandler handshakeHandler = (HandshakeHandler)
+ new DirectFieldAccessor(handler).getPropertyValue("handshakeHandler");
+ assertNotNull(handshakeHandler);
+ assertTrue(handshakeHandler instanceof TestHandshakeHandler);
+ List<HandshakeInterceptor> handshakeInterceptorList = (List<HandshakeInterceptor>)
+ new DirectFieldAccessor(handler).getPropertyValue("interceptors");
+ assertNotNull(handshakeInterceptorList);
+ assertThat(handshakeInterceptorList, Matchers.contains(
+ Matchers.instanceOf(FooTestInterceptor.class), Matchers.instanceOf(BarTestInterceptor.class)));
+
+ handler = (WebSocketHttpRequestHandler) urlHandlerMapping.getUrlMap().get("/test");
+ assertNotNull(handler);
+ checkDelegateHandlerType(handler.getWebSocketHandler(), TestWebSocketHandler.class);
+ handshakeHandler = (HandshakeHandler) new DirectFieldAccessor(handler).getPropertyValue("handshakeHandler");
+ assertNotNull(handshakeHandler);
+ assertTrue(handshakeHandler instanceof TestHandshakeHandler);
+ handshakeInterceptorList = (List<HandshakeInterceptor>)
+ new DirectFieldAccessor(handler).getPropertyValue("interceptors");
+ assertNotNull(handshakeInterceptorList);
+ assertThat(handshakeInterceptorList, Matchers.contains(
+ Matchers.instanceOf(FooTestInterceptor.class), Matchers.instanceOf(BarTestInterceptor.class)));
+
+ }
+
+ @Test
+ public void sockJSSupport() {
+ loadBeanDefinitions("websocket-config-handlers-sockjs.xml");
+ SimpleUrlHandlerMapping handlerMapping = appContext.getBean(SimpleUrlHandlerMapping.class);
+ assertNotNull(handlerMapping);
+ SockJsHttpRequestHandler testHandler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/test/**");
+ assertNotNull(testHandler);
+ checkDelegateHandlerType(testHandler.getWebSocketHandler(), TestWebSocketHandler.class);
+ SockJsService testSockJsService = testHandler.getSockJsService();
+ SockJsHttpRequestHandler fooHandler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/foo/**");
+ assertNotNull(fooHandler);
+ checkDelegateHandlerType(fooHandler.getWebSocketHandler(), FooWebSocketHandler.class);
+
+ SockJsService sockJsService = fooHandler.getSockJsService();
+ assertNotNull(sockJsService);
+ assertEquals(testSockJsService, sockJsService);
+
+ assertThat(sockJsService, Matchers.instanceOf(DefaultSockJsService.class));
+ DefaultSockJsService defaultSockJsService = (DefaultSockJsService) sockJsService;
+ assertThat(defaultSockJsService.getTaskScheduler(), Matchers.instanceOf(ThreadPoolTaskScheduler.class));
+ assertThat(defaultSockJsService.getTransportHandlers().values(), Matchers.containsInAnyOrder(
+ Matchers.instanceOf(XhrPollingTransportHandler.class),
+ Matchers.instanceOf(XhrReceivingTransportHandler.class),
+ Matchers.instanceOf(JsonpPollingTransportHandler.class),
+ Matchers.instanceOf(JsonpReceivingTransportHandler.class),
+ Matchers.instanceOf(XhrStreamingTransportHandler.class),
+ Matchers.instanceOf(EventSourceTransportHandler.class),
+ Matchers.instanceOf(HtmlFileTransportHandler.class),
+ Matchers.instanceOf(WebSocketTransportHandler.class)));
+
+ }
+
+ @Test
+ public void sockJSAttributesSupport() {
+ loadBeanDefinitions("websocket-config-handlers-sockjs-attributes.xml");
+ SimpleUrlHandlerMapping handlerMapping = appContext.getBean(SimpleUrlHandlerMapping.class);
+ assertNotNull(handlerMapping);
+ SockJsHttpRequestHandler handler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/test/**");
+ assertNotNull(handler);
+ checkDelegateHandlerType(handler.getWebSocketHandler(), TestWebSocketHandler.class);
+ SockJsService sockJsService = handler.getSockJsService();
+ assertNotNull(sockJsService);
+ assertThat(sockJsService, Matchers.instanceOf(DefaultSockJsService.class));
+ DefaultSockJsService defaultSockJsService = (DefaultSockJsService) sockJsService;
+ assertThat(defaultSockJsService.getTaskScheduler(), Matchers.instanceOf(TestTaskScheduler.class));
+ assertThat(defaultSockJsService.getTransportHandlers().values(), Matchers.containsInAnyOrder(
+ Matchers.instanceOf(XhrPollingTransportHandler.class),
+ Matchers.instanceOf(XhrStreamingTransportHandler.class)));
+
+ assertEquals("testSockJsService", defaultSockJsService.getName());
+ assertFalse(defaultSockJsService.isWebSocketEnabled());
+ assertFalse(defaultSockJsService.isSessionCookieNeeded());
+ assertEquals(2048, defaultSockJsService.getStreamBytesLimit());
+ assertEquals(256, defaultSockJsService.getDisconnectDelay());
+ assertEquals(1024, defaultSockJsService.getHttpMessageCacheSize());
+ assertEquals(20, defaultSockJsService.getHeartbeatTime());
+ }
+
+ private void loadBeanDefinitions(String fileName) {
+ XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
+ ClassPathResource resource = new ClassPathResource(fileName, HandlersBeanDefinitionParserTests.class);
+ reader.loadBeanDefinitions(resource);
+ appContext.refresh();
+ }
+
+ private void checkDelegateHandlerType(WebSocketHandler handler, Class<?> handlerClass) {
+ do {
+ handler = (WebSocketHandler) new DirectFieldAccessor(handler).getPropertyValue("delegate");
+ }
+ while (new DirectFieldAccessor(handler).isReadableProperty("delegate"));
+ assertTrue(handlerClass.isInstance(handler));
+ }
+
+}
+
+class TestWebSocketHandler implements WebSocketHandler {
+ @Override
+ public void afterConnectionEstablished(WebSocketSession session) throws Exception {}
+
+ @Override
+ public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {}
+
+ @Override
+ public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {}
+
+ @Override
+ public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception {}
+
+ @Override
+ public boolean supportsPartialMessages() { return false; }
+}
+
+class FooWebSocketHandler extends TestWebSocketHandler { }
+
+class TestHandshakeHandler implements HandshakeHandler {
+ @Override
+ public boolean doHandshake(ServerHttpRequest request, ServerHttpResponse response,
+ WebSocketHandler wsHandler, Map<String, Object> attributes)
+ throws HandshakeFailureException {
+ return false;
+ }
+}
+
+class FooTestInterceptor implements HandshakeInterceptor {
+ @Override
+ public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response,
+ WebSocketHandler wsHandler, Map<String, Object> attributes)
+ throws Exception {
+ return false;
+ }
+
+ @Override
+ public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response,
+ WebSocketHandler wsHandler, Exception exception) {
+ }
+}
+
+class BarTestInterceptor extends FooTestInterceptor {}
+
+class TestTaskScheduler implements TaskScheduler {
+ @Override
+ public ScheduledFuture schedule(Runnable task, Trigger trigger) { return null; }
+
+ @Override
+ public ScheduledFuture schedule(Runnable task, Date startTime) { return null; }
+
+ @Override
+ public ScheduledFuture scheduleAtFixedRate(Runnable task, Date startTime, long period) { return null; }
+
+ @Override
+ public ScheduledFuture scheduleAtFixedRate(Runnable task, long period) { return null; }
+
+ @Override
+ public ScheduledFuture scheduleWithFixedDelay(Runnable task, Date startTime, long delay) { return null; }
+
+ @Override
+ public ScheduledFuture scheduleWithFixedDelay(Runnable task, long delay) { return null; }
+}
\ No newline at end of file | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/test/resources/org/springframework/web/socket/messaging/config/xml/websocket-config-broker-customchannels.xml | @@ -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> | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/test/resources/org/springframework/web/socket/messaging/config/xml/websocket-config-broker-relay.xml | @@ -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> | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/test/resources/org/springframework/web/socket/messaging/config/xml/websocket-config-broker-simple.xml | @@ -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> | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/test/resources/org/springframework/web/socket/server/config/xml/websocket-config-handlers-attributes.xml | @@ -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> | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/test/resources/org/springframework/web/socket/server/config/xml/websocket-config-handlers-sockjs-attributes.xml | @@ -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> | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/test/resources/org/springframework/web/socket/server/config/xml/websocket-config-handlers-sockjs.xml | @@ -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> | true |
Other | spring-projects | spring-framework | 10f5d96a783f85fcdba2ce9b846c751a40bd7fe0.json | 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 | spring-websocket/src/test/resources/org/springframework/web/socket/server/config/xml/websocket-config-handlers.xml | @@ -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> | true |
Other | spring-projects | spring-framework | b0b40dade132577533bfbab34dbe8e03d9c613b6.json | Detect cache hit with multiple @Cachables
Fix CacheAspectSupport to consider a cache hit from any of the multiple
@Cachables that may have been specified using the @Caching annotation.
Prior to this commit the following scenario would never produce a hit:
@Caching(cacheable = {
@Cacheable(value = "c1", unless = "#result.size() < 4"),
@Cacheable(value = "c2", unless = "#result.size() > 3")
})
Issue: SPR-11124 | spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java | @@ -261,7 +261,7 @@ private void collectPutRequests(Collection<CacheOperationContext> contexts,
for (CacheOperationContext context : contexts) {
if (isConditionPassing(context, result)) {
Object key = generateKey(context, result);
- if (!whenNotInCache || findInCaches(context, key) == null) {
+ if (!whenNotInCache || findInAnyCaches(contexts, key) == null) {
putRequests.add(new CachePutRequest(context, key));
}
}
@@ -280,6 +280,16 @@ private Cache.ValueWrapper findCachedResult(Collection<CacheOperationContext> co
return result;
}
+ private Cache.ValueWrapper findInAnyCaches(Collection<CacheOperationContext> contexts, Object key) {
+ for (CacheOperationContext context : contexts) {
+ ValueWrapper wrapper = findInCaches(context, key);
+ if (wrapper != null) {
+ return wrapper;
+ }
+ }
+ return null;
+ }
+
private Cache.ValueWrapper findInCaches(CacheOperationContext context, Object key) {
for (Cache cache : context.getCaches()) {
Cache.ValueWrapper wrapper = cache.get(key); | true |
Other | spring-projects | spring-framework | b0b40dade132577533bfbab34dbe8e03d9c613b6.json | Detect cache hit with multiple @Cachables
Fix CacheAspectSupport to consider a cache hit from any of the multiple
@Cachables that may have been specified using the @Caching annotation.
Prior to this commit the following scenario would never produce a hit:
@Caching(cacheable = {
@Cacheable(value = "c1", unless = "#result.size() < 4"),
@Cacheable(value = "c2", unless = "#result.size() > 3")
})
Issue: SPR-11124 | spring-context/src/test/java/org/springframework/cache/CacheReproTests.java | @@ -0,0 +1,104 @@
+/*
+ * 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.
+ */
+
+package org.springframework.cache;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.cache.annotation.Caching;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests to reproduce raised caching issues.
+ *
+ * @author Phillip Webb
+ */
+public class CacheReproTests {
+
+ @Test
+ public void spr11124() throws Exception {
+ AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
+ Spr11124Config.class);
+ Spr11124Service bean = context.getBean(Spr11124Service.class);
+ bean.single(2);
+ bean.single(2);
+ bean.multiple(2);
+ bean.multiple(2);
+ context.close();
+ }
+
+ @Configuration
+ @EnableCaching
+ public static class Spr11124Config {
+
+ @Bean
+ public CacheManager cacheManager() {
+ return new ConcurrentMapCacheManager();
+ }
+
+ @Bean
+ public Spr11124Service service() {
+ return new Spr11124ServiceImpl();
+ }
+
+ }
+
+ public interface Spr11124Service {
+
+ public List<String> single(int id);
+
+ public List<String> multiple(int id);
+
+ }
+
+ public static class Spr11124ServiceImpl implements Spr11124Service {
+
+ private int multipleCount = 0;
+
+ @Override
+ @Cacheable(value = "smallCache")
+ public List<String> single(int id) {
+ if (this.multipleCount > 0) {
+ fail("Called too many times");
+ }
+ this.multipleCount++;
+ return Collections.emptyList();
+ }
+
+ @Override
+ @Caching(cacheable = {
+ @Cacheable(value = "bigCache", unless = "#result.size() < 4"),
+ @Cacheable(value = "smallCache", unless = "#result.size() > 3") })
+ public List<String> multiple(int id) {
+ if (this.multipleCount > 0) {
+ fail("Called too many times");
+ }
+ this.multipleCount++;
+ return Collections.emptyList();
+ }
+
+ }
+
+} | true |
Other | spring-projects | spring-framework | 690051f46cad97e4fcfb5073be63ea06e02ac01c.json | Add ability to customize message channels
@EnableWebSocketMessageBroker message channel configuration can now be
customized via WebSocketMessageBrokerConfigurer. It is necessary to
make this easy and even required as part of the basic configuration
since by default the message channels are backed by a thread pool of
size 1, not suitable for production use.
Issue: SPR-11023 | spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java | @@ -59,6 +59,10 @@ public abstract class AbstractMessageBrokerConfiguration {
"com.fasterxml.jackson.databind.ObjectMapper", AbstractMessageBrokerConfiguration.class.getClassLoader());
+ private ChannelRegistration clientInboundChannelRegistration;
+
+ private ChannelRegistration clientOutboundChannelRegistration;
+
private MessageBrokerRegistry brokerRegistry;
@@ -69,55 +73,117 @@ protected AbstractMessageBrokerConfiguration() {
}
- /**
- * An accessor for the {@link MessageBrokerRegistry} that ensures its one-time creation
- * and initialization through {@link #configureMessageBroker(MessageBrokerRegistry)}.
- */
- protected final MessageBrokerRegistry getBrokerRegistry() {
- if (this.brokerRegistry == null) {
- MessageBrokerRegistry registry = new MessageBrokerRegistry(clientOutboundChannel());
- configureMessageBroker(registry);
- this.brokerRegistry = registry;
- }
- return this.brokerRegistry;
- }
-
- /**
- * A hook for sub-classes to customize message broker configuration through the
- * provided {@link MessageBrokerRegistry} instance.
- */
- protected abstract void configureMessageBroker(MessageBrokerRegistry registry);
-
-
@Bean
public AbstractSubscribableChannel clientInboundChannel() {
- return new ExecutorSubscribableChannel(clientInboundChannelExecutor());
+ ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(clientInboundChannelExecutor());
+ ChannelRegistration r = getClientInboundChannelRegistration();
+ if (r.hasInterceptors()) {
+ channel.setInterceptors(r.getInterceptors());
+ }
+ return channel;
}
@Bean
public ThreadPoolTaskExecutor clientInboundChannelExecutor() {
- ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+ TaskExecutorRegistration r = getClientInboundChannelRegistration().getTaskExecutorRegistration();
+ ThreadPoolTaskExecutor executor = (r != null) ? r.getTaskExecutor() : new ThreadPoolTaskExecutor();
executor.setThreadNamePrefix("ClientInboundChannel-");
return executor;
}
+ protected final ChannelRegistration getClientInboundChannelRegistration() {
+ if (this.clientInboundChannelRegistration == null) {
+ ChannelRegistration registration = new ChannelRegistration();
+ configureClientInboundChannel(registration);
+ this.clientInboundChannelRegistration = registration;
+ }
+ return this.clientInboundChannelRegistration;
+ }
+
+
+ /**
+ * A hook for sub-classes to customize the message channel for inbound messages
+ * from WebSocket clients.
+ */
+ protected abstract void configureClientInboundChannel(ChannelRegistration registration);
+
+
@Bean
public AbstractSubscribableChannel clientOutboundChannel() {
- return new ExecutorSubscribableChannel(clientOutboundChannelExecutor());
+ ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(clientOutboundChannelExecutor());
+ ChannelRegistration r = getClientOutboundChannelRegistration();
+ if (r.hasInterceptors()) {
+ channel.setInterceptors(r.getInterceptors());
+ }
+ return channel;
}
@Bean
public ThreadPoolTaskExecutor clientOutboundChannelExecutor() {
- ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+ TaskExecutorRegistration r = getClientOutboundChannelRegistration().getTaskExecutorRegistration();
+ ThreadPoolTaskExecutor executor = (r != null) ? r.getTaskExecutor() : new ThreadPoolTaskExecutor();
executor.setThreadNamePrefix("ClientOutboundChannel-");
return executor;
}
+ protected final ChannelRegistration getClientOutboundChannelRegistration() {
+ if (this.clientOutboundChannelRegistration == null) {
+ ChannelRegistration registration = new ChannelRegistration();
+ configureClientOutboundChannel(registration);
+ this.clientOutboundChannelRegistration = registration;
+ }
+ return this.clientOutboundChannelRegistration;
+ }
+
+ /**
+ * A hook for sub-classes to customize the message channel for messages from
+ * the application or message broker to WebSocket clients.
+ */
+ protected abstract void configureClientOutboundChannel(ChannelRegistration registration);
+
@Bean
public AbstractSubscribableChannel brokerChannel() {
- return new ExecutorSubscribableChannel(); // synchronous
+ ChannelRegistration r = getBrokerRegistry().getBrokerChannelRegistration();
+ ExecutorSubscribableChannel channel;
+ if (r.hasTaskExecutor()) {
+ channel = new ExecutorSubscribableChannel(); // synchronous by default
+ }
+ else {
+ channel = new ExecutorSubscribableChannel(brokerChannelExecutor());
+ }
+ if (r.hasInterceptors()) {
+ channel.setInterceptors(r.getInterceptors());
+ }
+ return channel;
+ }
+
+ @Bean
+ public ThreadPoolTaskExecutor brokerChannelExecutor() {
+ TaskExecutorRegistration r = getBrokerRegistry().getBrokerChannelRegistration().getTaskExecutorRegistration();
+ ThreadPoolTaskExecutor executor = (r != null) ? r.getTaskExecutor() : new ThreadPoolTaskExecutor();
+ executor.setThreadNamePrefix("BrokerChannel-");
+ return executor;
+ }
+
+ /**
+ * An accessor for the {@link MessageBrokerRegistry} that ensures its one-time creation
+ * and initialization through {@link #configureMessageBroker(MessageBrokerRegistry)}.
+ */
+ protected final MessageBrokerRegistry getBrokerRegistry() {
+ if (this.brokerRegistry == null) {
+ MessageBrokerRegistry registry = new MessageBrokerRegistry(clientOutboundChannel());
+ configureMessageBroker(registry);
+ this.brokerRegistry = registry;
+ }
+ return this.brokerRegistry;
}
+ /**
+ * A hook for sub-classes to customize message broker configuration through the
+ * provided {@link MessageBrokerRegistry} instance.
+ */
+ protected abstract void configureMessageBroker(MessageBrokerRegistry registry);
+
@Bean
public SimpAnnotationMethodMessageHandler simpAnnotationMethodMessageHandler() { | true |
Other | spring-projects | spring-framework | 690051f46cad97e4fcfb5073be63ea06e02ac01c.json | Add ability to customize message channels
@EnableWebSocketMessageBroker message channel configuration can now be
customized via WebSocketMessageBrokerConfigurer. It is necessary to
make this easy and even required as part of the basic configuration
since by default the message channels are backed by a thread pool of
size 1, not suitable for production use.
Issue: SPR-11023 | spring-messaging/src/main/java/org/springframework/messaging/simp/config/ChannelRegistration.java | @@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+package org.springframework.messaging.simp.config;
+
+import org.springframework.messaging.support.channel.ChannelInterceptor;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+
+/**
+ * A registration class for customizing the configuration for a
+ * {@link org.springframework.messaging.MessageChannel}.
+ *
+ * @author Rossen Stoyanchev
+ * @since 4.0
+ */
+public class ChannelRegistration {
+
+ private TaskExecutorRegistration taskExecutorRegistration;
+
+ private List<ChannelInterceptor> interceptors = new ArrayList<ChannelInterceptor>();
+
+
+ /**
+ * Configure properties of the ThreadPoolTaskExecutor backing the message channel.
+ */
+ public TaskExecutorRegistration taskExecutor() {
+ this.taskExecutorRegistration = new TaskExecutorRegistration();
+ return this.taskExecutorRegistration;
+ }
+
+ /**
+ * Configure interceptors for the message channel.
+ */
+ public ChannelRegistration setInterceptors(ChannelInterceptor... interceptors) {
+ if (interceptors != null) {
+ this.interceptors.addAll(Arrays.asList(interceptors));
+ }
+ return this;
+ }
+
+
+ protected boolean hasTaskExecutor() {
+ return (this.taskExecutorRegistration != null);
+ }
+
+ protected TaskExecutorRegistration getTaskExecutorRegistration() {
+ return this.taskExecutorRegistration;
+ }
+
+ protected boolean hasInterceptors() {
+ return !this.interceptors.isEmpty();
+ }
+
+ protected List<ChannelInterceptor> getInterceptors() {
+ return this.interceptors;
+ }
+} | true |
Other | spring-projects | spring-framework | 690051f46cad97e4fcfb5073be63ea06e02ac01c.json | Add ability to customize message channels
@EnableWebSocketMessageBroker message channel configuration can now be
customized via WebSocketMessageBrokerConfigurer. It is necessary to
make this easy and even required as part of the basic configuration
since by default the message channels are backed by a thread pool of
size 1, not suitable for production use.
Issue: SPR-11023 | spring-messaging/src/main/java/org/springframework/messaging/simp/config/MessageBrokerRegistry.java | @@ -42,6 +42,8 @@ public class MessageBrokerRegistry {
private String userDestinationPrefix;
+ private ChannelRegistration brokerChannelRegistration = new ChannelRegistration();
+
public MessageBrokerRegistry(MessageChannel clientOutboundChannel) {
Assert.notNull(clientOutboundChannel);
@@ -103,6 +105,17 @@ public MessageBrokerRegistry setUserDestinationPrefix(String destinationPrefix)
return this;
}
+ /**
+ * Customize the channel used to send messages from the application to the message
+ * broker. By default messages from the application to the message broker are sent
+ * synchronously, which means application code sending a message will find out
+ * if the message cannot be sent through an exception. However, this can be changed
+ * if the broker channel is configured here with task executor properties.
+ */
+ public ChannelRegistration configureBrokerChannel() {
+ return this.brokerChannelRegistration;
+ }
+
protected SimpleBrokerMessageHandler getSimpleBroker() {
initSimpleBrokerIfNecessary();
@@ -127,4 +140,8 @@ protected Collection<String> getApplicationDestinationPrefixes() {
protected String getUserDestinationPrefix() {
return this.userDestinationPrefix;
}
+
+ protected ChannelRegistration getBrokerChannelRegistration() {
+ return this.brokerChannelRegistration;
+ }
} | true |
Other | spring-projects | spring-framework | 690051f46cad97e4fcfb5073be63ea06e02ac01c.json | Add ability to customize message channels
@EnableWebSocketMessageBroker message channel configuration can now be
customized via WebSocketMessageBrokerConfigurer. It is necessary to
make this easy and even required as part of the basic configuration
since by default the message channels are backed by a thread pool of
size 1, not suitable for production use.
Issue: SPR-11023 | spring-messaging/src/main/java/org/springframework/messaging/simp/config/TaskExecutorRegistration.java | @@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+
+package org.springframework.messaging.simp.config;
+
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+/**
+ * A registration class for customizing the properties of {@link ThreadPoolTaskExecutor}.
+ *
+ * @author Rossen Stoyanchev
+ * @since 4.0
+ */
+public class TaskExecutorRegistration {
+
+ private int corePoolSize = 1;
+
+ private int maxPoolSize = Integer.MAX_VALUE;
+
+ private int keepAliveSeconds = 60;
+
+ private int queueCapacity = Integer.MAX_VALUE;
+
+
+ /**
+ * Set the ThreadPoolExecutor's core pool size.
+ * Default is 1.
+ */
+ public TaskExecutorRegistration corePoolSize(int corePoolSize) {
+ this.corePoolSize = corePoolSize;
+ return this;
+ }
+
+ /**
+ * Set the ThreadPoolExecutor's maximum pool size.
+ * Default is {@code Integer.MAX_VALUE}.
+ */
+ public TaskExecutorRegistration maxPoolSize(int maxPoolSize) {
+ this.maxPoolSize = maxPoolSize;
+ return this;
+ }
+
+ /**
+ * Set the ThreadPoolExecutor's keep-alive seconds.
+ * Default is 60.
+ */
+ public TaskExecutorRegistration keepAliveSeconds(int keepAliveSeconds) {
+ this.keepAliveSeconds = keepAliveSeconds;
+ return this;
+ }
+
+ /**
+ * Set the capacity for the ThreadPoolExecutor's BlockingQueue.
+ * Default is {@code Integer.MAX_VALUE}.
+ * <p>Any positive value will lead to a LinkedBlockingQueue instance;
+ * any other value will lead to a SynchronousQueue instance.
+ * @see java.util.concurrent.LinkedBlockingQueue
+ * @see java.util.concurrent.SynchronousQueue
+ */
+ public TaskExecutorRegistration queueCapacity(int queueCapacity) {
+ this.queueCapacity = queueCapacity;
+ return this;
+ }
+
+ protected ThreadPoolTaskExecutor getTaskExecutor() {
+ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+ executor.setCorePoolSize(this.corePoolSize);
+ executor.setMaxPoolSize(this.maxPoolSize);
+ executor.setKeepAliveSeconds(this.keepAliveSeconds);
+ executor.setQueueCapacity(this.queueCapacity);
+ return executor;
+ }
+
+} | true |
Other | spring-projects | spring-framework | 690051f46cad97e4fcfb5073be63ea06e02ac01c.json | Add ability to customize message channels
@EnableWebSocketMessageBroker message channel configuration can now be
customized via WebSocketMessageBrokerConfigurer. It is necessary to
make this easy and even required as part of the basic configuration
since by default the message channels are backed by a thread pool of
size 1, not suitable for production use.
Issue: SPR-11023 | spring-messaging/src/main/java/org/springframework/messaging/support/channel/ExecutorSubscribableChannel.java | @@ -57,6 +57,10 @@ public ExecutorSubscribableChannel(Executor executor) {
}
+ public Executor getExecutor() {
+ return this.executor;
+ }
+
@Override
protected boolean hasSubscription(MessageHandler handler) {
return this.handlers.contains(handler); | true |
Other | spring-projects | spring-framework | 690051f46cad97e4fcfb5073be63ea06e02ac01c.json | Add ability to customize message channels
@EnableWebSocketMessageBroker message channel configuration can now be
customized via WebSocketMessageBrokerConfigurer. It is necessary to
make this easy and even required as part of the basic configuration
since by default the message channels are backed by a thread pool of
size 1, not suitable for production use.
Issue: SPR-11023 | spring-messaging/src/test/java/org/springframework/messaging/simp/config/MessageBrokerConfigurationTests.java | @@ -36,13 +36,17 @@
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.messaging.support.channel.AbstractSubscribableChannel;
+import org.springframework.messaging.support.channel.ChannelInterceptor;
+import org.springframework.messaging.support.channel.ChannelInterceptorAdapter;
import org.springframework.messaging.support.channel.ExecutorSubscribableChannel;
import org.springframework.messaging.support.converter.CompositeMessageConverter;
import org.springframework.messaging.support.converter.DefaultContentTypeResolver;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Controller;
import org.springframework.util.MimeTypeUtils;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.*;
@@ -59,6 +63,8 @@ public class MessageBrokerConfigurationTests {
private AnnotationConfigApplicationContext cxtStompBroker;
+ private AnnotationConfigApplicationContext cxtCustomizedChannelConfig;
+
@Before
public void setupOnce() {
@@ -70,6 +76,10 @@ public void setupOnce() {
this.cxtStompBroker = new AnnotationConfigApplicationContext();
this.cxtStompBroker.register(TestStompMessageBrokerConfig.class);
this.cxtStompBroker.refresh();
+
+ this.cxtCustomizedChannelConfig = new AnnotationConfigApplicationContext();
+ this.cxtCustomizedChannelConfig.register(CustomizedChannelConfig.class);
+ this.cxtCustomizedChannelConfig.refresh();
}
@@ -96,6 +106,22 @@ public void clientInboundChannelWithStompBroker() {
assertTrue(values.contains(cxtStompBroker.getBean(StompBrokerRelayMessageHandler.class)));
}
+ @Test
+ public void clientInboundChannelCustomized() {
+
+ AbstractSubscribableChannel channel = this.cxtCustomizedChannelConfig.getBean(
+ "clientInboundChannel", AbstractSubscribableChannel.class);
+
+ assertEquals(1, channel.getInterceptors().size());
+
+ ThreadPoolTaskExecutor taskExecutor = this.cxtCustomizedChannelConfig.getBean(
+ "clientInboundChannelExecutor", ThreadPoolTaskExecutor.class);
+
+ assertEquals(11, taskExecutor.getCorePoolSize());
+ assertEquals(12, taskExecutor.getMaxPoolSize());
+ assertEquals(13, taskExecutor.getKeepAliveSeconds());
+ }
+
@Test
public void clientOutboundChannelUsedByAnnotatedMethod() {
@@ -148,6 +174,22 @@ public void clientOutboundChannelUsedBySimpleBroker() {
assertEquals("bar", new String((byte[]) message.getPayload()));
}
+ @Test
+ public void clientOutboundChannelCustomized() {
+
+ AbstractSubscribableChannel channel = this.cxtCustomizedChannelConfig.getBean(
+ "clientOutboundChannel", AbstractSubscribableChannel.class);
+
+ assertEquals(2, channel.getInterceptors().size());
+
+ ThreadPoolTaskExecutor taskExecutor = this.cxtCustomizedChannelConfig.getBean(
+ "clientOutboundChannelExecutor", ThreadPoolTaskExecutor.class);
+
+ assertEquals(21, taskExecutor.getCorePoolSize());
+ assertEquals(22, taskExecutor.getMaxPoolSize());
+ assertEquals(23, taskExecutor.getKeepAliveSeconds());
+ }
+
@Test
public void brokerChannel() {
TestChannel channel = this.cxtSimpleBroker.getBean("brokerChannel", TestChannel.class);
@@ -207,6 +249,22 @@ public void brokerChannelUsedByUserDestinationMessageHandler() {
assertEquals("/foo-users1", headers.getDestination());
}
+ @Test
+ public void brokerChannelCustomized() {
+
+ AbstractSubscribableChannel channel = this.cxtCustomizedChannelConfig.getBean(
+ "brokerChannel", AbstractSubscribableChannel.class);
+
+ assertEquals(3, channel.getInterceptors().size());
+
+ ThreadPoolTaskExecutor taskExecutor = this.cxtCustomizedChannelConfig.getBean(
+ "brokerChannelExecutor", ThreadPoolTaskExecutor.class);
+
+ assertEquals(31, taskExecutor.getCorePoolSize());
+ assertEquals(32, taskExecutor.getMaxPoolSize());
+ assertEquals(33, taskExecutor.getKeepAliveSeconds());
+ }
+
@Test
public void messageConverter() {
CompositeMessageConverter messageConverter = this.cxtStompBroker.getBean(
@@ -240,26 +298,36 @@ public TestController subscriptionController() {
return new TestController();
}
- @Override
- protected void configureMessageBroker(MessageBrokerRegistry registry) {
- }
@Override
@Bean
public AbstractSubscribableChannel clientInboundChannel() {
return new TestChannel();
}
+ @Override
+ protected void configureClientInboundChannel(ChannelRegistration registration) {
+ }
+
@Override
@Bean
public AbstractSubscribableChannel clientOutboundChannel() {
return new TestChannel();
}
+ @Override
+ protected void configureClientOutboundChannel(ChannelRegistration registration) {
+ }
+
@Override
public AbstractSubscribableChannel brokerChannel() {
return new TestChannel();
}
+
+ @Override
+ protected void configureMessageBroker(MessageBrokerRegistry registry) {
+ }
+
}
@Configuration
@@ -271,6 +339,32 @@ public void configureMessageBroker(MessageBrokerRegistry registry) {
}
}
+ @Configuration
+ static class CustomizedChannelConfig extends AbstractMessageBrokerConfiguration {
+
+ private ChannelInterceptor interceptor = new ChannelInterceptorAdapter();
+
+
+ @Override
+ protected void configureClientInboundChannel(ChannelRegistration registration) {
+ registration.setInterceptors(this.interceptor);
+ registration.taskExecutor().corePoolSize(11).maxPoolSize(12).keepAliveSeconds(13).queueCapacity(14);
+ }
+
+ @Override
+ protected void configureClientOutboundChannel(ChannelRegistration registration) {
+ registration.setInterceptors(this.interceptor, this.interceptor);
+ registration.taskExecutor().corePoolSize(21).maxPoolSize(22).keepAliveSeconds(23).queueCapacity(24);
+ }
+
+ @Override
+ protected void configureMessageBroker(MessageBrokerRegistry registry) {
+ registry.configureBrokerChannel().setInterceptors(this.interceptor, this.interceptor, this.interceptor);
+ registry.configureBrokerChannel().taskExecutor()
+ .corePoolSize(31).maxPoolSize(32).keepAliveSeconds(33).queueCapacity(34);
+ }
+ }
+
private static class TestChannel extends ExecutorSubscribableChannel {
| true |
Other | spring-projects | spring-framework | 690051f46cad97e4fcfb5073be63ea06e02ac01c.json | Add ability to customize message channels
@EnableWebSocketMessageBroker message channel configuration can now be
customized via WebSocketMessageBrokerConfigurer. It is necessary to
make this easy and even required as part of the basic configuration
since by default the message channels are backed by a thread pool of
size 1, not suitable for production use.
Issue: SPR-11023 | spring-websocket/src/main/java/org/springframework/web/socket/messaging/config/DelegatingWebSocketMessageBrokerConfiguration.java | @@ -21,6 +21,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
+import org.springframework.messaging.simp.config.ChannelRegistration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.util.CollectionUtils;
@@ -58,6 +59,20 @@ protected void registerStompEndpoints(StompEndpointRegistry registry) {
}
}
+ @Override
+ protected void configureClientInboundChannel(ChannelRegistration registration) {
+ for (WebSocketMessageBrokerConfigurer c : this.configurers) {
+ c.configureClientInboundChannel(registration);
+ }
+ }
+
+ @Override
+ protected void configureClientOutboundChannel(ChannelRegistration registration) {
+ for (WebSocketMessageBrokerConfigurer c : this.configurers) {
+ c.configureClientOutboundChannel(registration);
+ }
+ }
+
@Override
protected void configureMessageBroker(MessageBrokerRegistry registry) {
for (WebSocketMessageBrokerConfigurer c : this.configurers) { | true |
Other | spring-projects | spring-framework | 690051f46cad97e4fcfb5073be63ea06e02ac01c.json | Add ability to customize message channels
@EnableWebSocketMessageBroker message channel configuration can now be
customized via WebSocketMessageBrokerConfigurer. It is necessary to
make this easy and even required as part of the basic configuration
since by default the message channels are backed by a thread pool of
size 1, not suitable for production use.
Issue: SPR-11023 | spring-websocket/src/main/java/org/springframework/web/socket/messaging/config/WebSocketMessageBrokerConfigurer.java | @@ -17,6 +17,7 @@
package org.springframework.web.socket.messaging.config;
+import org.springframework.messaging.simp.config.ChannelRegistration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
/**
@@ -35,6 +36,22 @@ public interface WebSocketMessageBrokerConfigurer {
*/
void registerStompEndpoints(StompEndpointRegistry registry);
+ /**
+ * Configure the {@link org.springframework.messaging.MessageChannel} used for
+ * incoming messages from WebSocket clients. By default the channel is backed
+ * by a thread pool of size 1. It is recommended to customize thread pool
+ * settings for production use.
+ */
+ void configureClientInboundChannel(ChannelRegistration registration);
+
+ /**
+ * Configure the {@link org.springframework.messaging.MessageChannel} used for
+ * incoming messages from WebSocket clients. By default the channel is backed
+ * by a thread pool of size 1. It is recommended to customize thread pool
+ * settings for production use.
+ */
+ void configureClientOutboundChannel(ChannelRegistration registration);
+
/**
* Configure message broker options.
*/ | true |
Other | spring-projects | spring-framework | 690051f46cad97e4fcfb5073be63ea06e02ac01c.json | Add ability to customize message channels
@EnableWebSocketMessageBroker message channel configuration can now be
customized via WebSocketMessageBrokerConfigurer. It is necessary to
make this easy and even required as part of the basic configuration
since by default the message channels are backed by a thread pool of
size 1, not suitable for production use.
Issue: SPR-11023 | spring-websocket/src/test/java/org/springframework/web/socket/messaging/SimpAnnotationMethodIntegrationTests.java | @@ -36,6 +36,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.handler.annotation.MessageExceptionHandler;
import org.springframework.messaging.handler.annotation.MessageMapping;
+import org.springframework.messaging.simp.config.ChannelRegistration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.messaging.simp.stomp.StompCommand;
import org.springframework.messaging.support.channel.AbstractSubscribableChannel;
@@ -215,6 +216,14 @@ public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws").setHandshakeHandler(this.handshakeHandler);
}
+ @Override
+ public void configureClientInboundChannel(ChannelRegistration registration) {
+ }
+
+ @Override
+ public void configureClientOutboundChannel(ChannelRegistration registration) {
+ }
+
@Override
public void configureMessageBroker(MessageBrokerRegistry configurer) {
configurer.setApplicationDestinationPrefixes("/app"); | true |
Other | spring-projects | spring-framework | 690051f46cad97e4fcfb5073be63ea06e02ac01c.json | Add ability to customize message channels
@EnableWebSocketMessageBroker message channel configuration can now be
customized via WebSocketMessageBrokerConfigurer. It is necessary to
make this easy and even required as part of the basic configuration
since by default the message channels are backed by a thread pool of
size 1, not suitable for production use.
Issue: SPR-11023 | spring-websocket/src/test/java/org/springframework/web/socket/messaging/config/WebSocketMessageBrokerConfigurationSupportTests.java | @@ -27,6 +27,7 @@
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.simp.annotation.SubscribeMapping;
+import org.springframework.messaging.simp.config.ChannelRegistration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.messaging.simp.stomp.StompCommand;
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
@@ -119,20 +120,29 @@ public String handleMessage() {
@Configuration
static class TestSimpleMessageBrokerConfig implements WebSocketMessageBrokerConfigurer {
+ @Bean
+ public TestController subscriptionController() {
+ return new TestController();
+ }
+
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/simpleBroker");
}
@Override
- public void configureMessageBroker(MessageBrokerRegistry configurer) {
- // SimpleBroker used by default
+ public void configureClientInboundChannel(ChannelRegistration registration) {
}
- @Bean
- public TestController subscriptionController() {
- return new TestController();
+ @Override
+ public void configureClientOutboundChannel(ChannelRegistration registration) {
}
+
+ @Override
+ public void configureMessageBroker(MessageBrokerRegistry registry) {
+ // SimpleBroker used by default
+ }
+
}
@Configuration | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | build.gradle | @@ -93,8 +93,9 @@ configure(allprojects) { project ->
"http://www.eclipse.org/aspectj/doc/released/aspectj5rt-api/",
"http://ehcache.org/apidocs/",
"http://quartz-scheduler.org/api/2.1.7/",
- "http://jackson.codehaus.org/1.9.12/javadoc/",
- "http://fasterxml.github.com/jackson-core/javadoc/2.2.2/",
+ "http://jackson.codehaus.org/1.9.4/javadoc/",
+ "http://fasterxml.github.com/jackson-core/javadoc/2.2.0/",
+ "http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs"
] as String[]
}
| true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-beans/src/main/java/org/springframework/beans/factory/config/CustomEditorConfigurer.java | @@ -91,8 +91,6 @@
* @see ConfigurableBeanFactory#addPropertyEditorRegistrar
* @see ConfigurableBeanFactory#registerCustomEditor
* @see org.springframework.validation.DataBinder#registerCustomEditor
- * @see org.springframework.web.servlet.mvc.BaseCommandController#setPropertyEditorRegistrars
- * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder
*/
public class CustomEditorConfigurer implements BeanFactoryPostProcessor, Ordered {
| true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomBooleanEditor.java | @@ -29,13 +29,11 @@
* them in the UI form.
*
* <p>In web MVC code, this editor will typically be registered with
- * {@code binder.registerCustomEditor} calls in an implementation
- * of BaseCommandController's {@code initBinder} method.
+ * {@code binder.registerCustomEditor} calls.
*
* @author Juergen Hoeller
* @since 10.06.2003
* @see org.springframework.validation.DataBinder#registerCustomEditor
- * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder
*/
public class CustomBooleanEditor extends PropertyEditorSupport {
| true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomDateEditor.java | @@ -33,15 +33,13 @@
* and rendering them in the UI form.
*
* <p>In web MVC code, this editor will typically be registered with
- * {@code binder.registerCustomEditor} calls in a custom
- * {@code initBinder} method.
+ * {@code binder.registerCustomEditor}.
*
* @author Juergen Hoeller
* @since 28.04.2003
* @see java.util.Date
* @see java.text.DateFormat
* @see org.springframework.validation.DataBinder#registerCustomEditor
- * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder
*/
public class CustomDateEditor extends PropertyEditorSupport {
| true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomNumberEditor.java | @@ -34,15 +34,13 @@
* and rendering them in the UI form.
*
* <p>In web MVC code, this editor will typically be registered with
- * {@code binder.registerCustomEditor} calls in a custom
- * {@code initBinder} method.
+ * {@code binder.registerCustomEditor} calls.
*
* @author Juergen Hoeller
* @since 06.06.2003
* @see Number
* @see java.text.NumberFormat
* @see org.springframework.validation.DataBinder#registerCustomEditor
- * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder
*/
public class CustomNumberEditor extends PropertyEditorSupport {
| true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringTrimmerEditor.java | @@ -28,7 +28,6 @@
*
* @author Juergen Hoeller
* @see org.springframework.validation.DataBinder#registerCustomEditor
- * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder
*/
public class StringTrimmerEditor extends PropertyEditorSupport {
| true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-beans/src/main/java/org/springframework/beans/support/MutableSortDefinition.java | @@ -146,7 +146,7 @@ public void setToggleAscendingOnProperty(boolean toggleAscendingOnProperty) {
/**
* Return whether to toggle the ascending flag if the same property gets set again
- * (that is, {@link #setProperty} gets called with already set property name again).
+ * (that is, {@code setProperty} gets called with already set property name again).
*/
public boolean isToggleAscendingOnProperty() {
return this.toggleAscendingOnProperty; | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java | @@ -194,7 +194,6 @@ public void setTemplateLoaderPath(String templateLoaderPath) {
* @see org.springframework.context.ApplicationContext#getResource
* @see freemarker.template.Configuration#setDirectoryForTemplateLoading
* @see SpringTemplateLoader
- * @see #setTemplateLoaders
*/
public void setTemplateLoaderPaths(String... templateLoaderPaths) {
this.templateLoaderPaths = templateLoaderPaths; | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-context-support/src/main/java/org/springframework/ui/velocity/VelocityEngineFactory.java | @@ -53,8 +53,8 @@
* to the Spring application context.
*
* <p>If "overrideLogging" is true (the default), the VelocityEngine will be
- * configured to log via Commons Logging, that is, using the Spring-provided
- * {@link CommonsLoggingLogSystem} as log system.
+ * configured to log via Commons Logging, that is, using
+ * {@link CommonsLogLogChute} as log system.
*
* <p>The simplest way to use this class is to specify a
* {@link #setResourceLoaderPath(String) "resourceLoaderPath"}; the
@@ -66,7 +66,6 @@
* @see #setResourceLoaderPath
* @see #setOverrideLogging
* @see #createVelocityEngine
- * @see CommonsLoggingLogSystem
* @see VelocityEngineFactoryBean
* @see org.springframework.web.servlet.view.velocity.VelocityConfigurer
* @see org.apache.velocity.app.VelocityEngine | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-context/src/main/java/org/springframework/context/annotation/LoadTimeWeavingConfiguration.java | @@ -34,7 +34,7 @@
* {@code @Configuration} class that registers a {@link LoadTimeWeaver} bean.
*
* <p>This configuration class is automatically imported when using the
- * @{@link EnableLoadTimeWeaving} annotation. See {@code @EnableLoadTimeWeaving}
+ * {@link EnableLoadTimeWeaving} annotation. See {@code @EnableLoadTimeWeaving}
* javadoc for complete usage details.
*
* @author Chris Beams | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-context/src/main/java/org/springframework/context/annotation/MBeanExportConfiguration.java | @@ -39,7 +39,7 @@
* {@code @Configuration} class that registers a {@link AnnotationMBeanExporter} bean.
*
* <p>This configuration class is automatically imported when using the
- * @{@link EnableMBeanExport} annotation. See its javadoc for complete usage details.
+ * {@link EnableMBeanExport} annotation. See its javadoc for complete usage details.
*
* @author Phillip Webb
* @author Chris Beams | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-context/src/main/java/org/springframework/instrument/classloading/glassfish/GlassFishLoadTimeWeaver.java | @@ -26,7 +26,7 @@
/**
* {@link LoadTimeWeaver} implementation for GlassFish's
- * {@link org.glassfish.api.deployment.InstrumentableClassLoader InstrumentableClassLoader}.
+ * {@code org.glassfish.api.deployment.InstrumentableClassLoader InstrumentableClassLoader}.
*
* <p>As of Spring 4.0, this weaver supports GlassFish V3 and V4.
* | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-context/src/main/java/org/springframework/instrument/classloading/tomcat/package-info.java | @@ -1,8 +1,5 @@
-
/**
- *
* Support for class instrumentation on Tomcat.
- *
*/
package org.springframework.instrument.classloading.tomcat;
| true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-context/src/main/java/org/springframework/validation/AbstractBindingResult.java | @@ -262,15 +262,11 @@ public Class<?> getFieldType(String field) {
* Adding things to the map and then re-calling this method will not work.
* <p>The attributes in the model Map returned by this method are usually
* included in the ModelAndView for a form view that uses Spring's bind tag,
- * which needs access to the Errors instance. Spring's SimpleFormController
- * will do this for you when rendering its form or success view. When
- * building the ModelAndView yourself, you need to include the attributes
- * from the model Map returned by this method yourself.
+ * which needs access to the Errors instance.
* @see #getObjectName
* @see #MODEL_KEY_PREFIX
* @see org.springframework.web.servlet.ModelAndView
* @see org.springframework.web.servlet.tags.BindTag
- * @see org.springframework.web.servlet.mvc.SimpleFormController
*/
@Override
public Map<String, Object> getModel() { | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-context/src/main/java/org/springframework/validation/BindingResult.java | @@ -73,7 +73,6 @@ public interface BindingResult extends Errors {
* @see #MODEL_KEY_PREFIX
* @see org.springframework.web.servlet.ModelAndView
* @see org.springframework.web.servlet.tags.BindTag
- * @see org.springframework.web.servlet.mvc.SimpleFormController
*/
Map<String, Object> getModel();
| true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-core/src/main/java/org/springframework/asm/Label.java | @@ -35,7 +35,7 @@
* designates the <i>instruction</i> that is just after. Note however that there
* can be other elements between a label and the instruction it designates (such
* as other labels, stack map frames, line numbers, etc.).
- *
+ *
* @author Eric Bruneton
*/
public class Label {
@@ -111,13 +111,13 @@ public class Label {
* Field used to associate user information to a label. Warning: this field
* is used by the ASM tree package. In order to use it with the ASM tree
* package you must override the
- * {@link org.objectweb.asm.tree.MethodNode#getLabelNode} method.
+ * {@code org.objectweb.asm.tree.MethodNode#getLabelNode} method.
*/
public Object info;
/**
* Flags that indicate the status of this label.
- *
+ *
* @see #DEBUG
* @see #RESOLVED
* @see #RESIZED
@@ -170,7 +170,7 @@ public class Label {
* represented by the Label object that corresponds to the first instruction
* of this basic block. Each node also stores the list of its successors in
* the graph, as a linked list of Edge objects.
- *
+ *
* The control flow analysis algorithms used to compute the maximum stack
* size or the stack map frames are similar and use two steps. The first
* step, during the visit of each instruction, builds information about the
@@ -182,7 +182,7 @@ public class Label {
* information about the input frame of each basic block, from the input
* state of the first basic block (known from the method signature), and by
* the using the previously computed relative output frames.
- *
+ *
* The algorithm used to compute the maximum stack size only computes the
* relative output and absolute input stack heights, while the algorithm
* used to compute stack map frames computes relative output frames and
@@ -192,10 +192,10 @@ public class Label {
/**
* Start of the output stack relatively to the input stack. The exact
* semantics of this field depends on the algorithm that is used.
- *
+ *
* When only the maximum stack size is computed, this field is the number of
* elements in the input stack.
- *
+ *
* When the stack map frames are completely computed, this field is the
* offset of the first output stack element relatively to the top of the
* input stack. This offset is always negative or null. A null offset means
@@ -240,7 +240,7 @@ public class Label {
* main loop of the fix point algorithm used in the second step of the
* control flow analysis algorithms. It is also used in
* {@link #visitSubroutine} to avoid using a recursive method.
- *
+ *
* @see MethodWriter#visitMaxs
*/
Label next;
@@ -264,7 +264,7 @@ public Label() {
* from the start of the method's bytecode. <i>This method is intended for
* {@link Attribute} sub classes, and is normally not needed by class
* generators or adapters.</i>
- *
+ *
* @return the offset corresponding to this label.
* @throws IllegalStateException
* if this label is not resolved yet.
@@ -282,7 +282,7 @@ public int getOffset() {
* position of the label is known, the offset is computed and written
* directly. Otherwise, a null offset is written and a new forward reference
* is declared for this label.
- *
+ *
* @param owner
* the code writer that calls this method.
* @param out
@@ -320,7 +320,7 @@ void put(final MethodWriter owner, final ByteVector out, final int source,
* for a true forward reference, i.e. only if this label is not resolved
* yet. For backward references, the offset of the reference can be, and
* must be, computed and stored directly.
- *
+ *
* @param sourcePosition
* the position of the referencing instruction. This position
* will be used to compute the offset of this forward reference.
@@ -348,7 +348,7 @@ private void addReference(final int sourcePosition,
* when this label is added to the bytecode of the method, i.e. when its
* position becomes known. This method fills in the blanks that where left
* in the bytecode by each forward reference previously added to this label.
- *
+ *
* @param owner
* the code writer that calls this method.
* @param position
@@ -416,7 +416,7 @@ boolean resolve(final MethodWriter owner, final int position,
* isolated label or for the first label in a series of successive labels,
* this method returns the label itself. For other labels it returns the
* first label of the series.
- *
+ *
* @return the first label of the series to which this label belongs.
*/
Label getFirst() {
@@ -429,7 +429,7 @@ Label getFirst() {
/**
* Returns true is this basic block belongs to the given subroutine.
- *
+ *
* @param id
* a subroutine id.
* @return true is this basic block belongs to the given subroutine.
@@ -444,7 +444,7 @@ boolean inSubroutine(final long id) {
/**
* Returns true if this basic block and the given one belong to a common
* subroutine.
- *
+ *
* @param block
* another basic block.
* @return true if this basic block and the given one belong to a common
@@ -464,7 +464,7 @@ boolean inSameSubroutine(final Label block) {
/**
* Marks this basic block as belonging to the given subroutine.
- *
+ *
* @param id
* a subroutine id.
* @param nbSubroutines
@@ -483,7 +483,7 @@ void addToSubroutine(final long id, final int nbSubroutines) {
* blocks as belonging to this subroutine. This method follows the control
* flow graph to find all the blocks that are reachable from the current
* block WITHOUT following any JSR target.
- *
+ *
* @param JSR
* a JSR block that jumps to this subroutine. If this JSR is not
* null it is added to the successor of the RET blocks found in
@@ -550,7 +550,7 @@ void visitSubroutine(final Label JSR, final long id, final int nbSubroutines) {
/**
* Returns a string representation of this label.
- *
+ *
* @return a string representation of this label.
*/
@Override | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-core/src/main/java/org/springframework/core/ResolvableType.java | @@ -103,7 +103,7 @@ public final class ResolvableType implements Serializable {
private TypeProvider typeProvider;
/**
- * The {@link VariableResolver} to use or {@code null} if no resolver is available.
+ * The {@code VariableResolver} to use or {@code null} if no resolver is available.
*/
private final VariableResolver variableResolver;
| true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-core/src/main/java/org/springframework/util/AntPathMatcher.java | @@ -261,8 +261,8 @@ private boolean matchStrings(String pattern, String str, Map<String, String> uri
/**
* Build or retrieve an {@link AntPathStringMatcher} for the given pattern.
* <p>The default implementation checks this AntPathMatcher's internal cache
- * (see {@link #setCachePatterns}, creating a new AntPathStringMatcher instance
- * through {@link AntPathStringMatcher#AntPathStringMatcher(String)} if none found.
+ * (see {@link #setCachePatterns}), creating a new AntPathStringMatcher instance
+ * if no cached copy is found.
* When encountering too many patterns to cache at runtime (the threshold is 65536),
* it turns the default cache off, assuming that arbitrary permutations of patterns
* are coming in, with little chance for encountering a reoccurring pattern. | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-core/src/main/java/org/springframework/util/InvalidMimeTypeException.java | @@ -17,7 +17,7 @@
package org.springframework.util;
/**
- * Exception thrown from {@link MediaType#parseMimeType(String)} in case of
+ * Exception thrown from {@link MimeTypeUtils#parseMimeType(String)} in case of
* encountering an invalid content type specification String.
*
* @author Juergen Hoeller | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-core/src/main/java/org/springframework/util/MimeType.java | @@ -33,17 +33,15 @@
* other Internet protocols including HTTP. This class however does not contain support
* the q-parameters used in HTTP content negotiation. Those can be found in the sub-class
* {@code org.springframework.http.MediaType} in the {@code spring-web} module.
- * <p>
- * Consists of a {@linkplain #getType() type} and a {@linkplain #getSubtype() subtype}.
+ *
+ * <p>Consists of a {@linkplain #getType() type} and a {@linkplain #getSubtype() subtype}.
* Also has functionality to parse media types from a string using
- * {@link #parseMimeType(String)}, or multiple comma-separated media types using
- * {@link #parseMimeTypes(String)}.
+ * {@link #valueOf(String)}. For more parsing options see {@link MimeTypeUtils}.
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @author Rossen Stoyanchev
* @since 4.0
- *
* @see MimeTypeUtils
*/
public class MimeType implements Comparable<MimeType>, Serializable {
@@ -324,10 +322,12 @@ else if (getType().equals(other.getType())) {
/**
* Indicate whether this {@code MediaType} is compatible with the given media type.
- * <p>For instance, {@code text/*} is compatible with {@code text/plain}, {@code text/html}, and vice versa.
- * In effect, this method is similar to {@link #includes(MediaType)}, except that it <b>is</b> symmetric.
+ * <p>For instance, {@code text/*} is compatible with {@code text/plain},
+ * {@code text/html}, and vice versa. In effect, this method is similar to
+ * {@link #includes}, except that it <b>is</b> symmetric.
* @param other the reference media type with which to compare
- * @return {@code true} if this media type is compatible with the given media type; {@code false} otherwise
+ * @return {@code true} if this media type is compatible with the given media type;
+ * {@code false} otherwise
*/
public boolean isCompatibleWith(MimeType other) {
if (other == null) {
@@ -369,7 +369,7 @@ else if (thisPlusIdx != -1 && otherPlusIdx != -1) {
/**
* Compares this {@code MediaType} to another alphabetically.
* @param other media type to compare to
- * @see #sortBySpecificity(List)
+ * @see MimeTypeUtils#sortBySpecificity(List)
*/
@Override
public int compareTo(MimeType other) {
@@ -459,7 +459,7 @@ private void appendTo(Map<String, String> map, StringBuilder builder) {
* Parse the given String value into a {@code MimeType} object,
* with this method name following the 'valueOf' naming convention
* (as supported by {@link org.springframework.core.convert.ConversionService}.
- * @see #parseMimeType(String)
+ * @see MimeTypeUtils#parseMimeType(String)
*/
public static MimeType valueOf(String value) {
return MimeTypeUtils.parseMimeType(value); | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java | @@ -28,23 +28,21 @@
import org.springframework.util.MimeType.SpecificityComparator;
-
-
/**
*
* @author Arjen Poutsma
* @author Rossen Stoyanchev
* @since 4.0
*/
-public class MimeTypeUtils {
+public abstract class MimeTypeUtils {
/**
* Public constant mime type that includes all media ranges (i.e. "*/*").
*/
public static final MimeType ALL;
/**
- * A String equivalent of {@link MediaType#ALL}.
+ * A String equivalent of {@link MimeTypeUtils#ALL}.
*/
public static final String ALL_VALUE = "*/*";
@@ -54,7 +52,7 @@ public class MimeTypeUtils {
public final static MimeType APPLICATION_ATOM_XML;
/**
- * A String equivalent of {@link MimeType#APPLICATION_ATOM_XML}.
+ * A String equivalent of {@link MimeTypeUtils#APPLICATION_ATOM_XML}.
*/
public final static String APPLICATION_ATOM_XML_VALUE = "application/atom+xml";
@@ -64,7 +62,7 @@ public class MimeTypeUtils {
public final static MimeType APPLICATION_FORM_URLENCODED;
/**
- * A String equivalent of {@link MimeType#APPLICATION_FORM_URLENCODED}.
+ * A String equivalent of {@link MimeTypeUtils#APPLICATION_FORM_URLENCODED}.
*/
public final static String APPLICATION_FORM_URLENCODED_VALUE = "application/x-www-form-urlencoded";
@@ -74,7 +72,7 @@ public class MimeTypeUtils {
public final static MimeType APPLICATION_JSON;
/**
- * A String equivalent of {@link MimeType#APPLICATION_JSON}.
+ * A String equivalent of {@link MimeTypeUtils#APPLICATION_JSON}.
*/
public final static String APPLICATION_JSON_VALUE = "application/json";
@@ -84,7 +82,7 @@ public class MimeTypeUtils {
public final static MimeType APPLICATION_OCTET_STREAM;
/**
- * A String equivalent of {@link MimeType#APPLICATION_OCTET_STREAM}.
+ * A String equivalent of {@link MimeTypeUtils#APPLICATION_OCTET_STREAM}.
*/
public final static String APPLICATION_OCTET_STREAM_VALUE = "application/octet-stream";
@@ -94,7 +92,7 @@ public class MimeTypeUtils {
public final static MimeType APPLICATION_XHTML_XML;
/**
- * A String equivalent of {@link MimeType#APPLICATION_XHTML_XML}.
+ * A String equivalent of {@link MimeTypeUtils#APPLICATION_XHTML_XML}.
*/
public final static String APPLICATION_XHTML_XML_VALUE = "application/xhtml+xml";
@@ -104,7 +102,7 @@ public class MimeTypeUtils {
public final static MimeType APPLICATION_XML;
/**
- * A String equivalent of {@link MimeType#APPLICATION_XML}.
+ * A String equivalent of {@link MimeTypeUtils#APPLICATION_XML}.
*/
public final static String APPLICATION_XML_VALUE = "application/xml";
@@ -114,7 +112,7 @@ public class MimeTypeUtils {
public final static MimeType IMAGE_GIF;
/**
- * A String equivalent of {@link MimeType#IMAGE_GIF}.
+ * A String equivalent of {@link MimeTypeUtils#IMAGE_GIF}.
*/
public final static String IMAGE_GIF_VALUE = "image/gif";
@@ -124,7 +122,7 @@ public class MimeTypeUtils {
public final static MimeType IMAGE_JPEG;
/**
- * A String equivalent of {@link MimeType#IMAGE_JPEG}.
+ * A String equivalent of {@link MimeTypeUtils#IMAGE_JPEG}.
*/
public final static String IMAGE_JPEG_VALUE = "image/jpeg";
@@ -134,7 +132,7 @@ public class MimeTypeUtils {
public final static MimeType IMAGE_PNG;
/**
- * A String equivalent of {@link MimeType#IMAGE_PNG}.
+ * A String equivalent of {@link MimeTypeUtils#IMAGE_PNG}.
*/
public final static String IMAGE_PNG_VALUE = "image/png";
@@ -144,7 +142,7 @@ public class MimeTypeUtils {
public final static MimeType MULTIPART_FORM_DATA;
/**
- * A String equivalent of {@link MimeType#MULTIPART_FORM_DATA}.
+ * A String equivalent of {@link MimeTypeUtils#MULTIPART_FORM_DATA}.
*/
public final static String MULTIPART_FORM_DATA_VALUE = "multipart/form-data";
@@ -154,7 +152,7 @@ public class MimeTypeUtils {
public final static MimeType TEXT_HTML;
/**
- * A String equivalent of {@link MimeType#TEXT_HTML}.
+ * A String equivalent of {@link MimeTypeUtils#TEXT_HTML}.
*/
public final static String TEXT_HTML_VALUE = "text/html";
@@ -164,7 +162,7 @@ public class MimeTypeUtils {
public final static MimeType TEXT_PLAIN;
/**
- * A String equivalent of {@link MimeType#TEXT_PLAIN}.
+ * A String equivalent of {@link MimeTypeUtils#TEXT_PLAIN}.
*/
public final static String TEXT_PLAIN_VALUE = "text/plain";
@@ -174,7 +172,7 @@ public class MimeTypeUtils {
public final static MimeType TEXT_XML;
/**
- * A String equivalent of {@link MimeType#TEXT_XML}.
+ * A String equivalent of {@link MimeTypeUtils#TEXT_XML}.
*/
public final static String TEXT_XML_VALUE = "text/xml";
@@ -294,16 +292,16 @@ public static String toString(Collection<? extends MimeType> mimeTypes) {
* <p>
* Given two mime types:
* <ol>
- * <li>if either mime type has a {@linkplain #isWildcardType() wildcard type}, then
- * the mime type without the wildcard is ordered before the other.</li>
- * <li>if the two mime types have different {@linkplain #getType() types}, then
- * they are considered equal and remain their current order.</li>
- * <li>if either mime type has a {@linkplain #isWildcardSubtype() wildcard subtype}
+ * <li>if either mime type has a {@linkplain MimeType#isWildcardType() wildcard type},
+ * then the mime type without the wildcard is ordered before the other.</li>
+ * <li>if the two mime types have different {@linkplain MimeType#getType() types},
+ * then they are considered equal and remain their current order.</li>
+ * <li>if either mime type has a {@linkplain MimeType#isWildcardSubtype() wildcard subtype}
* , then the mime type without the wildcard is sorted before the other.</li>
- * <li>if the two mime types have different {@linkplain #getSubtype() subtypes},
+ * <li>if the two mime types have different {@linkplain MimeType#getSubtype() subtypes},
* then they are considered equal and remain their current order.</li>
* <li>if the two mime types have a different amount of
- * {@linkplain #getParameter(String) parameters}, then the mime type with the most
+ * {@linkplain MimeType#getParameter(String) parameters}, then the mime type with the most
* parameters is ordered before the other.</li>
* </ol>
* <p> | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-core/src/main/java/org/springframework/util/concurrent/FutureAdapter.java | @@ -26,7 +26,7 @@
/**
* Abstract class that adapts a {@link Future} parameterized over S into a {@code
* Future} parameterized over T. All methods are delegated to the adaptee, where {@link
- * #get()} and {@link #get(long, TimeUnit)} call {@@link #adapt(Object)} on the adaptee's
+ * #get()} and {@link #get(long, TimeUnit)} call {@link #adapt(Object)} on the adaptee's
* result.
*
* @param <T> the type of this {@code Future} | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-core/src/main/java/org/springframework/util/concurrent/ListenableFuture.java | @@ -22,7 +22,7 @@
* Extends the {@link Future} interface with the capability to accept completion
* callbacks. If the future has already completed when the callback is added, the
* callback will be triggered immediately.
- * <p>Inspired by {@link com.google.common.util.concurrent.ListenableFuture}.
+ * <p>Inspired by {@code com.google.common.util.concurrent.ListenableFuture}.
* @author Arjen Poutsma
* @since 4.0
@@ -33,7 +33,6 @@
* Registers the given callback to this {@code ListenableFuture}. The callback will
* be triggered when this {@code Future} is complete or, if it is already complete,
* immediately.
- *
* @param callback the callback to register
*/
void addCallback(ListenableFutureCallback<? super T> callback); | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureAdapter.java | @@ -22,7 +22,7 @@
* Abstract class that adapts a {@link ListenableFuture} parameterized over S into a
* {@code ListenableFuture} parameterized over T. All methods are delegated to the
* adaptee, where {@link #get()}, {@link #get(long, java.util.concurrent.TimeUnit)}, and
- * {@link ListenableFutureCallback#onSuccess(Object)} call {@@link #adapt(Object)} on the
+ * {@link ListenableFutureCallback#onSuccess(Object)} call {@link #adapt(Object)} on the
* adaptee's result.
*
* @param <T> the type of this {@code Future} | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java | @@ -23,7 +23,9 @@
/**
* Registry for {@link ListenableFutureCallback} instances.
- * <p>Inspired by {@link com.google.common.util.concurrent.ExecutionList}.
+ *
+ * <p>Inspired by {@code com.google.common.util.concurrent.ExecutionList}.
+ *
* @author Arjen Poutsma
* @since 4.0
*/ | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-instrument-tomcat/src/main/java/org/springframework/instrument/classloading/tomcat/package-info.java | @@ -1,8 +0,0 @@
-
-/**
- *
- * Support for class instrumentation on Apache Tomcat.
- *
- */
-package org.springframework.instrument.classloading.tomcat;
- | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-jms/src/main/java/org/springframework/jms/core/JmsTemplate.java | @@ -46,8 +46,8 @@
*
* <p>If you want to use dynamic destination creation, you must specify
* the type of JMS destination to create, using the "pubSubDomain" property.
- * For other operations, this is not necessary, in contrast to when working
- * with {@link JmsTemplate102}. Point-to-Point (Queues) is the default domain.
+ * For other operations, this is not necessary. Point-to-Point (Queues) is the default
+ * domain.
*
* <p>Default settings for JMS Sessions are "not transacted" and "auto-acknowledge".
* As defined by the J2EE specification, the transaction and acknowledgement | true |
Other | spring-projects | spring-framework | a31ac882c54b9a32345274b09647b7423ecf0839.json | Fix various javadoc warnings | spring-jms/src/main/java/org/springframework/jms/core/support/JmsGatewaySupport.java | @@ -63,11 +63,10 @@ public final void setConnectionFactory(ConnectionFactory connectionFactory) {
* Create a JmsTemplate for the given ConnectionFactory.
* Only invoked if populating the gateway with a ConnectionFactory reference.
* <p>Can be overridden in subclasses to provide a JmsTemplate instance with
- * a different configuration or the JMS 1.0.2 version, JmsTemplate102.
+ * a different configuration.
* @param connectionFactory the JMS ConnectionFactory to create a JmsTemplate for
* @return the new JmsTemplate instance
* @see #setConnectionFactory
- * @see org.springframework.jms.core.JmsTemplate102
*/
protected JmsTemplate createJmsTemplate(ConnectionFactory connectionFactory) {
return new JmsTemplate(connectionFactory); | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.