Commit Graph

575 Commits

Author SHA1 Message Date
Rossen Stoyanchev ae06c3a6ab Use DestinationUserNameProvider with @SendTo
Issue: SPR-11327
2014-01-21 12:32:35 -05:00
Rossen Stoyanchev e4ad2b352e Add DestinationUserNameProvider interface
The interface is to be implemented in addition to
java.security.Principal when Principal.getName() is not globally unique
enough for use in user destinations.

Issue: SPR-11327
2014-01-21 12:12:05 -05:00
Rossen Stoyanchev c376ee92cd Allow setting Cookie header
Issue: SPR-11332
2014-01-20 13:25:57 -05:00
Rossen Stoyanchev e2feed494b Move "handlers" field to AbstractSubscribableChannel
Move the management of subscribers to the abstract parent class where
it belongs.
2014-01-17 11:24:28 -05:00
Rossen Stoyanchev c1f3da082c Write prelude on successive SockJS streaming requests
sockjs-client expects a prelude to be written on every request with
streaming transports. The protocol tests don't make this clear and
don't expose this issue.

The test case for SPR-11183 (writing 20K messages in succession) did
expose the issue and this commit addresses it.

Issue: SPR-11183
2014-01-16 12:27:14 -05:00
Juergen Hoeller 6051ea8ae3 Polishing 2014-01-16 16:54:49 +01:00
Rossen Stoyanchev 5f2106046c Add UpgradeRequestStrategy for WildFly/Undertow
Issue: SPR-11237
2014-01-14 16:45:18 -05:00
Rossen Stoyanchev ea0825c0a6 Trim tokenized strings in websocket namespace
Issue: SPR-11307
2014-01-14 12:45:47 -05:00
Rossen Stoyanchev a5c3143512 Allow hook to associate user with WebSocket session
This change adds a protected method to DefaultHandshakeHandler to
determine the user for the WebSocket session. By default it's
implemeted to obtain it from the request.

Issue: SPR-11228
2014-01-13 16:39:37 -05:00
Rossen Stoyanchev 6265bc1df7 Fall back on user in the Jetty UpgradeRequest
The Jetty ServletWebUpgradeRequest implements getUserPrincipal to
return the Principal from the HttpServletRequest on the upgrade.
This change ensures we can fall back on that.

However the JettyRequestUpgradeStrategy still passes the user from
HttpServletRequest from the upgrade, in order to work with Jetty
9.0.x and avoid running into this 9.1.x issue:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=423118
2014-01-13 16:39:37 -05:00
Rossen Stoyanchev 4342497305 Add support for custom message converters
The Java and XML config for STOMP WebSocket applications now supports
configuring message converters.

Issue: SPR-11184
2014-01-07 16:16:29 -05:00
Rossen Stoyanchev d0556e61f9 Log stack trace on failure to send message to client
Issue: SPR-11201
2014-01-03 16:44:01 -05:00
Rossen Stoyanchev ef13dbfcdd Handle bad STOMP messages in StompSubProtocolHandler
Issue: SPR-11277
2014-01-02 12:27:59 -05:00
Rossen Stoyanchev 4e5e700213 Add client login/passcode to broker relay
Issue: SPR-11154
2013-12-23 21:40:27 -05:00
Juergen Hoeller 1f9b833c4d Introduced SockJsSession interface and moved SockJsSessionFactory and SockJsServiceConfig to sockjs.transport; added initialize(SockJsServiceConfig) method to TransportHandler interface; extracted TransportHandlingSockJsService from DefaultSockJsService; moved sockjs.support.frame to sockjs.frame and extracted (Default)SockJsFrameFormat from SockJsFrame; moved SockJsHttpRequestHandler to sockjs.support; removed Jackson 1.x support 2013-12-08 01:25:52 +01:00
Rossen Stoyanchev 307bf4bede Add messaging.simp.user package 2013-12-06 17:05:29 -05:00
Rossen Stoyanchev 89455c00f6 Create messaging.simp.broker package 2013-12-06 16:24:04 -05:00
Juergen Hoeller c4163c7475 Moved messaging.support.converter to messaging.converter; moved messaging.support.tcp to messaging.tcp; moved messaging.support.channel to messaging.support itself; moved handler.condition to handler itself; reworked handler.method into handler.support 2013-12-06 18:24:38 +01:00
Juergen Hoeller edeb11c556 Polishing 2013-12-04 23:58:05 +01:00
Rossen Stoyanchev 8f569264da Fix issue in GlassfishRequestUpgradeStrategy
The observed behavior was that the client does not get a response from
the WebSocket HTTP handshake. On the server the handshake actually
succeeds, the response is set correctly to status 101, and the
WebSocketHandler gets notified of the successfully established
connection.

This change flushes the ServletResponse just before returning from the
GlassfishRequestUpgradeStrategy. This is actually what Glassfish's own
TyrusServletFilter does as well at the end along with a comment that it
is a possible bug.
2013-12-03 14:42:55 -05:00
Brian Clozel 3ac14e7cd8 Document websocket XML namespace
Issue: SPR-11063
2013-12-03 18:15:21 +01:00
Rossen Stoyanchev 14468e80f3 Add principal in GlassfishRequestUpgradeStrategy 2013-12-03 12:02:41 -05:00
Juergen Hoeller 1dff45c38a Consistent ".jetty" and ".standard" subpackages; consolidated GlassFishRequestUpgradeStrategy implementation; renamed Text/BinaryWebSocketHandler and moved them to web.socket.support 2013-12-03 17:18:24 +01:00
Rossen Stoyanchev bb5a53f7f7 Update websocket xml namespace attributes 2013-12-02 21:55:44 -05:00
Rossen Stoyanchev cea049b791 Move websocket config tests to annotation package 2013-12-02 21:32:06 -05:00
Juergen Hoeller e62cd84ca2 Merged web.socket.messaging.config into web.socket.config and introduced web.socket.config.annotation 2013-12-02 23:54:38 +01:00
Rossen Stoyanchev 69238ba66f Move WebSocketExtension to top-level package 2013-12-02 16:53:11 -05:00
Juergen Hoeller e3e1c1bcec Rearranged web.socket.server subpackages and introduced web.socket.config 2013-12-02 22:32:32 +01:00
Rossen Stoyanchev 47ef45d152 Polish websocket xml namespace
Issue: SPR-11063
2013-12-02 15:25:49 -05:00
Rossen Stoyanchev 079fb2db73 Add assert AbstractStandardRequestUpgradeStrategy 2013-12-02 13:59:17 -05:00
Brian Clozel 10f5d96a78 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
2013-12-02 12:18:33 -05:00
Phillip Webb 043a41e382 Consistent whitespace after imports
Update code to have a consistent number of new-line characters after
import statements.
2013-11-26 15:14:43 -08:00
Phillip Webb 15698860e1 General polish of new 4.0 classes
Apply consistent styling to new classes introduced in Spring 4.0.

- Javadoc line wrapping, whitespace and formatting
- General code whitespace
- Consistent Assert.notNull messages
2013-11-26 15:11:18 -08:00
Rossen Stoyanchev 690051f46c 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
2013-11-26 16:51:14 -05:00
Rossen Stoyanchev e764c8d897 Fix synchronization issue in StompSubProtocolHandler
Two concurrent threads should not send a message on a single WebSocket
session at the same time, for example see:
http://docs.oracle.com/javaee/7/api/javax/websocket/RemoteEndpoint.Basic.html

In StompSubProtocolHandler it is quite possible that multiple messages
may be broadcast to a single WebSocket client concurrently.

This change adds synchronization around the sending of a message to a
specific cilent session.

Issue: SPR-11023
2013-11-26 16:51:14 -05:00
Phillip Webb a31ac882c5 Fix various javadoc warnings 2013-11-26 13:25:37 -08:00
Eric Dahl e9f78f6043 Fix various typos
Fix a variety of typos throughout the project, primarily in
comments (javadoc or otherwise) but also in a handful of log messages
and a couple exception messages.

ISSUE: SPR-11123
2013-11-25 15:58:27 -08:00
Rossen Stoyanchev 4e82416ba9 Add SubProtocolCapable interface
The addition of SubProtocolCapable simplifies configuration since it is
no longer necessary to explicitly configure DefaultHandshakeHandler
with a list of supported sub-protocols. We will not also check if the
WebSocketHandler to use for the WebSocket request is an instance of
SubProtocolCapable and obtain the list of sub-protocols that way. The
provided SubProtocolWebSocketHandler does implement this interface.

Issue: SPR-11111
2013-11-25 18:06:01 -05:00
Phillip Webb 59002f2456 Fix remaining compiler warnings
Fix remaining Java compiler warnings, mainly around missing
generics or deprecated code.

Also add the `-Werror` compiler option to ensure that any future
warnings will fail the build.

Issue: SPR-11064
2013-11-25 12:52:42 -08:00
Rossen Stoyanchev 4de3291dc7 Consolidate websocket/messaging code
Before this change spring-messaging contained a few WebSocket-related
classes including WebSocket sub-protocol support for STOMP as well
as @EnableWebSocketMessageBroker and related configuration classes.

After this change those classes are located in the spring-websocket
module under org.springframework.web.socket.messaging.

This means the following classes in application configuration must
have their packages updated:

org.springframework.web.socket.messaging.config.EnableWebSocketMessageBroker
org.springframework.web.socket.messaging.config.StompEndpointRegistry
org.springframework.web.socket.messaging.config.WebSocketMessageBrokerConfigurer

MessageBrokerConfigurer has been renamed to MessageBrokerRegistry and
is also located in the above package.
2013-11-23 21:09:17 -05:00
Rossen Stoyanchev df5d22e120 Improve logging in spring-messaging
Before this change the amount of logging was too little or too much
with TRACE turned on. This change separates useful debugging
information and logs it under DEBUG and leaves more detailed
information to be logged under TRACE.
2013-11-12 16:34:25 -05:00
Rossen Stoyanchev 2a6c1f75e7 Simplify determination of SockJS path
The SockJS path is now passed to the SockJsService handleRequest method
thus removing the need to guess it.

Issue: SPR-11058
2013-11-07 22:28:15 -05:00
Rossen Stoyanchev 0340cc5f03 Update user destinations handling
Before this change subscribing to a user-specific destination in STOMP
required manually appending a unique queue suffix provided in a header
with the CONNECTED frame.

This change removes the need to do that. Instead STOMP clients can
subscribe to "/user/queue/error" and can then begin to receive messages
sent to "/user/{username}/queue/error" without colliding with any other
user doing the same.

Issue: SPR-11077
2013-11-07 17:37:41 -05:00
Michael Irwin 467c770b4d Handle UnsupportedOperationException from getInstalledExtensions in Glassfish 4.0 2013-11-06 08:36:28 -05:00
Juergen Hoeller 9f3b8a2430 GenericTypeResolver's resolveTypeArguments needs to return null for raw types (for backwards compatibility with 3.2)
Issue: SPR-11052
2013-10-31 15:28:20 +01:00
Sam Brannen ec24299092 Delete unused imports 2013-10-31 13:58:26 +01:00
Rossen Stoyanchev 164a9f938c Update the Jetty WebSocket adapter
This changes switches from using Jetty's WebSocketListener interface
to use Jetty's @WebSocket annotations instead. The change should be
transparent but the annnotations provide a little more controler
including handling pong frames.

This change also introduces a WebSocketMessage interface.

Issue: SPR-10877
2013-10-29 21:37:49 -04:00
Brian Clozel 397d52ad17 Upgrade to Jetty 9.1.0 .RC0
This commit upgrades Jetty to the latest available 9.1.x version while
also preserving compatibility with 9.0.x.
2013-10-29 15:02:25 -04:00
Sam Brannen 75e61cc983 Polish spring-websocket
- Removed unused imports
- Organized imports
- Deleted unused fields
- Deleted unused local variables
- Deleted unused private static classes
2013-10-29 19:39:41 +01:00
Rossen Stoyanchev 81dda069af Update WebSocket extensions change
- add WebSocketHttpHeaders
- client-side support for WebSocket extensions
- DefaultHandshakeHandler updates
- replace use of ServletAttributes in JettyRequestUpgradeStratey
- upgrade spring-web to jetty 9.0.5
2013-10-28 22:40:22 -04:00
Brian Clozel 6d00a3f0ee Add support for WebSocket Protocol Extensions
This commits adds simple, overridable WebSocket Extension
filtering during the handshake phase and adds that
information in the WebSocket session.

The actual WebSocket Extension negotiation happens
within the server implementation (Glassfish, Jetty, Tomcat...),
so one can only remove requested extensions from
the list provided by the WebSocket client.

See RFC6455 Section 9.

Issue: SPR-10843
2013-10-28 22:40:22 -04:00
Juergen Hoeller bd4c64af04 Turned ByteBufferConverter's visibility to package level 2013-10-04 22:52:14 +02:00
Rossen Stoyanchev 02cb86659d Prevent cache of sockjs known prefixes from growing
Issue: SPR-10893
2013-09-30 21:46:19 -04:00
Rossen Stoyanchev e60e8dc582 Fix issue with getting SockJS path
Issue: SPR-10923
2013-09-30 21:19:29 -04:00
Rossen Stoyanchev 9b2c041085 Fix issue in htmlfile sockjs transport
Issue: SPR-10854
2013-09-29 21:09:39 -04:00
Michael Irwin f1e929f38d Added websocket upgrade support for GlassFish 4.0
Commit 2397b21096 changed websocket
support to use GlassFish 4.0.1 nightlies, but broke support for 4.0. In
GlassFish 4.0.1, the package that TyrusEndpoint is located in changed.
This commit provides an abstract handler that does all required
GlassFish setup, but delegates to version specific upgrade handlers to
create the final TyrusEndpoint.

GlassFish 4.0 handler uses reflection to create its endpoint to prevent
dependency issues of depending on different versions of
tyrus-websocket-core and tyrus-container-servlet
2013-09-27 08:54:43 -04:00
Rossen Stoyanchev 77fa8698b3 Enable cookie_needed by default in SockJS service
Issue: SPR-10939
2013-09-26 12:52:59 -04:00
Rossen Stoyanchev a5c7018e8d Switch spring-websocket/messaging to Tomcat 8 RC3 2013-09-23 13:14:44 -04:00
Rossen Stoyanchev 62921683fd Introduce ListenableFuture to WebSocketClient
Issue: SPR-10888
2013-09-06 12:28:21 -04:00
Rossen Stoyanchev 1c47c8f35c Remove TODOs (replaced with JIRA tickets)
Issue: SPR-10703
2013-09-03 23:29:20 -04:00
Rossen Stoyanchev 0ac6998e60 Refine destination semantics for msg-handling methods
After this change, annotated message handling methods configured to use
a destination prefix (e.g. "/app") no longer have to include the prefix
in their mapping. For example if a client sends a message to "/app/foo"
the annotated methods should be mapped with @MessageMapping("/foo").
2013-09-03 11:04:00 -04:00
Rossen Stoyanchev e1a46bb57a Add tests to spring-messaging 2013-09-02 20:36:54 -04:00
Rossen Stoyanchev 79ddba5d01 Polish WebSocket integration tests 2013-09-02 09:11:26 -04:00
Rossen Stoyanchev fee3148b0f Add Tomcat WebSocket integration tests 2013-09-02 09:11:26 -04:00
Rossen Stoyanchev e21bbdd933 Polish WebSocket/STOMP Java config
Ensure configuration provided for WebSocketHandler's (eg interceptors,
or HandshakeHandler) are passed on to the SockJsService if congiured.

Better separate Servlet-specific parts of the configuration to make it
more obvious where non-Servlet alternatives could fit in.

Add more tests.

Improve WebSocket integration tests.
2013-09-02 09:11:26 -04:00
Rossen Stoyanchev 5d69700515 Remove incorrect package import
Issue: SPR-10880
2013-09-02 09:11:26 -04:00
Rossen Stoyanchev 1f897329f9 Add support for Ping and Pong WebSocket messages
Issue: SPR-10876
2013-08-29 15:11:03 -04:00
Rossen Stoyanchev 39ff1e2c53 Add StompProtocolHandler tests 2013-08-29 09:58:41 -04:00
Rossen Stoyanchev 80812d30d4 Protect STOMP passcode from showing up in logs
Issue: SRP-10868
2013-08-28 23:51:08 -04:00
Rossen Stoyanchev 1472e9795f Update SpringConfiguration to support beans by type
Issue: SPR-10605
2013-08-28 22:51:39 -04:00
Rossen Stoyanchev f0dda0e38b Add WebSocket integration tests w/ Java configuration
Issue: SPR-10835
2013-08-28 21:11:05 -04:00
Rossen Stoyanchev 467a6b9fa7 Fix failing tests and upgrade websocket to Jetty 9.0.5 2013-08-28 08:43:53 -04:00
Rossen Stoyanchev 4c0da5867a Add Java config support for WebSocket and STOMP
Issue: SPR-10835
2013-08-27 22:20:07 -04:00
Rossen Stoyanchev 4b6a9ac180 Polish WebSocketHttpRequestHandler 2013-08-27 22:20:07 -04:00
Jan Machacek c48a41ea7a Fix minor issue in JettyRequestUpgradeStrategy
Issue: SPR-10861
2013-08-27 12:34:11 -04:00
Rossen Stoyanchev cf2e1ffc65 Fix failing test
Issue: SPR-10605
2013-08-22 21:53:57 -04:00
Rossen Stoyanchev a5143057ce Add configurability for underlying WebSocket engine
Issue: SPR-10844
2013-08-22 20:35:03 -04:00
Rossen Stoyanchev a455217743 Modify how SpringConfigurator finds Endpoint singleton
First try the endpoint type name converted to property
Then try @Component value

Issue: SPR-10605
2013-08-22 16:05:44 -04:00
Rossen Stoyanchev 486a56dc1f Update TomcatRequestUpgradeStrategy for 8.0 RC1
While RC2 is not yet out, we need to support RC1 as well.
This change introduces temporary code that can be removed
once RC2 becomes available to avoid having to use Tomcat
snapshots.
2013-08-21 12:00:11 -04:00
Rossen Stoyanchev 0dcc5c048b Adjust SockJS use of ServerHttpResponse close vs flush 2013-08-21 12:00:11 -04:00
Rossen Stoyanchev 13ce20b1ca Remove IOException from HandshakeHandler 2013-08-21 12:00:11 -04:00
Rossen Stoyanchev 2397b21096 Upgrade spring-websocket to Tyrus 1.2.1
This targets currently nightly snapshots and future release
of Glassfish 4.0.1.
2013-08-21 12:00:11 -04:00
Rossen Stoyanchev e5406283c5 Polish DefaultHandshakeHandler
After this change the DefaultHandshakeHandler delegates to a
server-specific RequestUpgradeStrategy to update the HTTP response for
the handshake request and to begin the WebSocket interaction.

The DefaultHandshakeHandler however still retains the initial
validation of the WebSocket handshake including negotation of origin,
sub-protocol, etc. This allows sub-classes to override various
aspects of the negotiation independant of the WebSocket engine.
2013-08-21 12:00:11 -04:00
Rossen Stoyanchev 48996cf572 Update ServerEndpointRegistration
In addition to implementing ServerEndpointConfig, the
ServerEndpointRegistration now also extends
ServerEndpointConfig.Configurator making it easier to override
handshake customization methods without having to extend a separate
class.
2013-08-21 12:00:11 -04:00
Rossen Stoyanchev 64d45fe0a5 Make use of Tomcat's new WsServerContainer.doUpgrade
Tomcat now provides a method for initiating a WebSocket upgrade at
runtime vs relying on JSR-356 deployment at startup. This change
switches to use that latest feature. For more information on the
Tomcat change see:

https://issues.apache.org/bugzilla/show_bug.cgi?id=55314#c7
2013-08-21 12:00:11 -04:00
Rossen Stoyanchev 71dbd7bc1f Remove qetQueryParams from ServerHttpRequest 2013-08-14 11:43:37 -04:00
Rossen Stoyanchev 4c0490a070 Remove Cookie support from ServerHttpRequest
Although ServletHttpRequest provides access to Cookies, other
implementations may not. At the moment this was only needed
for SockJS to check the value of the JSESSIONID cookie. This
is now down by parsing the raw cookie values locally.

If comprehensive cookie support is to be added, we should
probably consider HttpHeaders as a potential candidate.
2013-08-14 10:15:02 -04:00
Rossen Stoyanchev 319f18dddf Add HandshakeInterceptor
A HandshakeInterceptor can be used to intercept WebSocket handshakes
(or SockJS requests where a new session is created) in order to
inspect the request and response before and after the handshake
including the ability to pass attributes to the WebSocketHandler,
which the hander can access through
WebSocketSession.getHandshakeAttributes()

An HttpSessionHandshakeInterceptor is available that can copy
attributes from the HTTP session to make them available to the
WebSocket session.

Issue: SPR-10624
2013-08-13 17:28:01 -04:00
Rossen Stoyanchev 9925d8385f Fix configuration issues in DefaultSockJsService 2013-08-13 17:28:00 -04:00
Rossen Stoyanchev 01feae0ad5 Polish WebSocketSession
Update methods available on WebSocketSession interface.
Introduce DelegatingWebSocketSession interface.
2013-08-13 17:28:00 -04:00
Rossen Stoyanchev 172a0b9f5d Add header support to WebSocketConnectionManager
Issue: SPR-10796
2013-08-07 17:07:43 -04:00
Rossen Stoyanchev 123c01908a Remove unintended dependency on Servlet API in SockJS
Add a factory method in ServerHttpRequest for creating a
ServerHttpAsyncRequestControl.
2013-08-03 11:21:02 -04:00
Rossen Stoyanchev 15a2f03459 Polish SockJS exception handling and javadoc
See javadoc in SockJsService for details.

Also remove ReadOnlyMultiValueMap, CollectionUtils has a method for
that already.
2013-08-03 11:03:27 -04:00
Rossen Stoyanchev a03517fa35 Polish ServletServerHttpRequest query param handling
The method returning query parameters now returns only query string
parameters as opposed to any Servlet request parameter.

This commit also adds a ReadOnlyMultiValueMap.
2013-08-02 17:40:08 -04:00
Rossen Stoyanchev 9700f09fad Polish async feature for ServerHttpRequest/Response
ServerHttpAsyncResponseControl wraps a ServetHttpRequest and -Response
pair and allows putting the processing of the request in async mode
so that the response remains open until explicitly closed, either from
the current or from another thread.

ServletServerHttpAsyncResponseControl provides a Serlvet-based
implementation.
2013-08-02 15:12:20 -04:00
Rossen Stoyanchev 0d5901ffb6 Polish Cookie abstraction in http packge of spring-web
A getCookies method is now available on ServerHttpRequest with one
ServletServerCookie implementation that wraps a Servlet cookie.

The SockJS service makes use of this to check for an existing session
cookie in the request.
2013-08-02 12:30:43 -04:00
Andy Wilkinson 9e20a25607 Introduce SubProtocolHandler abstraction
Add SubProtocolHandler to encapsulate the logic for using a
sub-protocol.

A SubProtocolWebSocketHandler is also provided to
delegate to the appropriate SubProtocolHandler based on the
negotiated sub-protocol value at handshake.

StompSubProtocolHandler provides handling for STOMP messages.

Issue: SPR-10786
2013-08-01 17:31:27 -04:00
Rossen Stoyanchev dcf7813de8 Fix failing test
Issue: SPR-10800
2013-07-31 22:06:15 -04:00
Rossen Stoyanchev ad40ecff4b Refactor and polish SockJS package structure
After this change the top-level sockjs package contains the main types
for use in applications.
2013-07-31 21:42:56 -04:00
Rossen Stoyanchev dad7115c23 Add SockJsMessageCodec
A SockJS message frame is an array of JSON-encoded messages and before
this change the use of the Jackson 2 library was hard-coded.

A Jackson 2 and Jackson 1.x implementations are provided and
automatically used if those libraries are present on the classpath.

Issue: SPR-10800
2013-07-31 21:42:56 -04:00
Rossen Stoyanchev 5a0e42b76e Add MultiProtocolWebSocketHandler
It makes it possible to deploy multiple WebSocketHandler's to a URL,
each supporting a different sub-protocol.

Issue: SPR-10786
2013-07-27 15:17:45 -04:00
Rossen Stoyanchev 7bb9c63963 Fix issue in TomcatRequestUpgradeStrategy
The method WsServerContainer.getServerContainer() was removed from
JSR-356 but remained in Tomcat a little while longer. Instead the
ServerContainer is obtained through a ServletContext attribute.
Tomcat has now removed this method, hence the need for this fix.
2013-07-25 13:26:03 -04:00
Rossen Stoyanchev 82ec06ad34 Fix bug in SockJS JsonpTransportHandler
Issue: SPR-10621
2013-07-18 17:53:48 -04:00
Rossen Stoyanchev 860e56ea84 Fix minor issue in WebSocketHttpRequestHandler
Issue: SPR-10721
2013-07-18 11:25:07 -04:00
Rossen Stoyanchev 6eea4ad68b Upgrade websocket module to servlet api 3.1.0 2013-07-17 22:39:51 -04:00
Rossen Stoyanchev d3cecfc6cc Create spring-messaging module
Consolidates new, messaging-related classes from spring-context and
spring-websocket into one module.
2013-07-12 13:44:41 -04:00
Rossen Stoyanchev 2803845151 Update MessageConverter and reactor dependencies 2013-07-10 16:00:40 -04:00
Rossen Stoyanchev 3a2f5e71b7 Refactor SubscriptionRegistry
The SubscriptionRegistry and implementations are now in a package
together with SimpleBrokerWebMessageHandler and primarily support
with matching subscriptions to messages. Subscriptions can contain
patterns as supported by AntPathMatcher.

StopmWebSocketHandler no longer keeps track of subscriptions and simply
ignores messages without a subscription id, since it has no way of
knowing broker-specific destination semantics for patterns.
2013-07-07 14:18:58 -04:00
Rossen Stoyanchev f25ccac1a1 Polish SessionSubscriptionRegistry types 2013-07-05 13:38:51 -04:00
Rossen Stoyanchev 96cb7c0616 Fix test failures 2013-07-05 12:21:45 -04:00
Rossen Stoyanchev 9dd7f6e5fb Update MessagingOperations hieararchy 2013-07-05 10:59:04 -04:00
Rossen Stoyanchev ef823721e5 Split AbstractMessagingTemplate across send/receive 2013-07-04 11:38:21 -04:00
Rossen Stoyanchev 078c766b80 Add new MessagingOperations ifc and class hieararchy 2013-07-04 11:23:40 -04:00
Rossen Stoyanchev e1080a0763 Merge branch 'master' into websocket-stomp 2013-07-04 09:55:00 -04:00
Rossen Stoyanchev 2a559028ad Upgrade spring-websocket to Jetty 9.0.4 2013-07-04 09:51:53 -04:00
Rossen Stoyanchev 8560582c40 Add messaging.channel package 2013-07-03 20:59:17 -04:00
Rossen Stoyanchev 0a68c9930f Add "simple" broker and SessionSubscriptionRegistry
SimpleBrokerWebMessageHandler can be used as an alternative to the
StompRelayWebMessageHandler.
2013-07-03 20:40:56 -04:00
Phillip Webb 8d6fd1ed63 ConversionService JSR-356 Encoder/Decoder adapters
Develop support class allowing JSR-356 Encoder and Decoder interfaces
to delegate to Spring's ConversionService.

Issue: SPR-10694
2013-07-01 13:12:52 -07:00
Rossen Stoyanchev 8ab5f23643 Remove PubSubMessageBuilder 2013-06-29 12:54:31 -04:00
Rossen Stoyanchev ea7622ed9a Fix import 2013-06-28 10:38:25 -04:00
Andy Wilkinson e24b71e700 Shutdown Reactor env when relay handler is stopped
The Reactor Environment (that's used by the TcpClient) manages a
number of threads. To ensure that these threads are cleaned up
Environment.shutdown() must be called when the Environment is no
longer needed.
2013-06-28 11:49:28 +01:00
Rossen Stoyanchev d650e909b2 Merge branch 'master' into websocket-stomp 2013-06-27 15:58:12 -04:00
Rossen Stoyanchev 9bdc825ded Add PayloadReturnValueHandler 2013-06-27 15:47:46 -04:00
Phillip Webb 60532cbd1e Polish spring-websocket code
Minor polish to formatting and assertion messages.
2013-06-27 09:58:58 -07:00
Rossen Stoyanchev e7d9c26a7c Make STOMP message broker host and port configurable 2013-06-27 12:43:56 -04:00
Rossen Stoyanchev ee9c46ad2e Remove PubSubChannelRegistry 2013-06-26 11:09:37 -04:00
Rossen Stoyanchev 486b4101ec Introduce MessageHeader accessor types
A new type MessageHeaderAccesssor provides read/write access to
MessageHeaders along with typed getter/setter methods along the lines
of the existing MessageBuilder methods (internally MessageBuilder
merely delegates to MessageHeaderAccessor). This class is extensible
with sub-classes expected to provide typed getter/setter methods for
specific categories of message headers.

NativeMessageHeaderAccessor is one specific sub-class that further
provides read/write access to headers from some external message
source (e.g. STOMP headers). Native headers are stored in a separate
MultiValueMap and kept under a specific key.
2013-06-25 16:31:52 -04:00
Rossen Stoyanchev ac23832e4d Fix issue in MessageReturnValueHandler 2013-06-24 11:47:59 -04:00
Rossen Stoyanchev 32cb2ca2e7 Remove generic params from Message/MessageChannel 2013-06-24 11:14:48 -04:00
Rossen Stoyanchev f7f66f2e5c Fix minor issue in ReactorMessageChannel 2013-06-24 09:59:27 -04:00
Rossen Stoyanchev 55a212d4a0 Add @MessageExceptionHandler
Similar to @ExceptionHandler but for message processing. Such a method
can send messages to both the message broker channel and the client
channel provided the client is subscribed to the target destination.
2013-06-19 22:17:59 -04:00
Rossen Stoyanchev 01c4e458c7 Add support for "system" STOMP session
The "system" STOMP session is established at startup and can be used
to send messages without a client session, e.g. to support broadcasting
from a REST/HTTP handler method.
2013-06-19 18:54:51 -04:00
Rossen Stoyanchev 44db0f815a Add MessageHolder
MessageHolder holds the currently processed message in a ThreadLocal,
which allows PubSubMessageBuilder to automatically add a session id
to messages to be sent.
2013-06-19 15:30:23 -04:00
Rossen Stoyanchev 5cfc59d76d Refactor PubSubHeaders, StompHeaders, MessageBuilder
Rename to PubSubHeaderAccessor and StompHeaderAccessor
Move the renamed classes to support packages

Remove fromPayloadAndHeaders from MessageBuilder, just use
withPayload(..).copyHeaders(..) instead.
2013-06-19 11:41:43 -04:00
Rossen Stoyanchev 5feac07738 Add getLastHandler to WebSocketHandlerDecorator 2013-06-19 09:46:21 -04:00
Rossen Stoyanchev 811bb1b0c9 Improve synchronization checks in STOMP relay session 2013-06-19 08:28:58 -04:00
Andy Wilkinson 28174744a7 Fix race when flushing messages
The use of an AtomicBoolean and no lock meant that it was possible
for a message to be queued and then never be flushed and sent to the
broker:

1. On t1, a message is received and isConnected is false. The message
   will be queued.
2. On t2, CONNECTED is received from the broker. isConnected is set
   to true, the queue is drained and the queued messages are forwarded
3. On t1, the message is added to the queue

To fix this, checking that isConnected is false (step 1 above) and the
queueing of a message (step 3 above) need to be performed as a unit
so that the flushing of the queued messages can't be interleaved. This
is achieved by synchronizing on a monitor and performing steps 1
and 3 and synchronizing on the same monitor while performing step 2.

The monitor is held while the messages are actually being forwarded
to the broker. An alternative would be to drain the queue into
a local variable, release the monitor, and then forward the messages.
The main advantage of this alternative is that the monitor is held for
less time. It also reduces the theoretical risk of deadlock by not
holding the monitor while making an alien call. The downside of the
alternative is that it may lead to messages being forwarded out of
order. For this reason the alternative approach was rejected.
2013-06-19 11:02:10 +01:00
Rossen Stoyanchev d20dabf1fb Fix issue with obtaining WebSocketContainer 2013-06-18 20:57:33 -04:00
Rossen Stoyanchev 3c6c56fe0d Fix issue with obtaining WebSocketContainer 2013-06-18 20:55:22 -04:00
Rossen Stoyanchev 3f9da6f480 Add generic parameters to MessageHandler impls 2013-06-18 20:35:15 -04:00
Andy Wilkinson f6398e14d0 Received message's destination is default for resp
When an annotated handler returns a Message from a @SubscribeEvent
or @MessageMapping method and it contains no destination in its
headers, use the received message's destination as the response
message's destination.
2013-06-17 21:04:23 -04:00
Andy Wilkinson 7bb3b824c3 Genericize PubSubChannelRegistry
Without generics, extending AbstractPubSubChannelRegistry and using
a custom Message type requires some unpleasant casting and suppression
of warnings. By genericizing PubSubChannelRegistry and
AbstractPubSubChannelRegistry these problems can be avoided.
2013-06-17 21:03:24 -04:00
Rossen Stoyanchev 426875b4f6 Refactor StompRelayPubSubMessageHandler 2013-06-17 16:29:31 -04:00
Rossen Stoyanchev 3dabe21563 Remove PubSubChannelRegistryBuilder 2013-06-17 10:22:58 -04:00
Rossen Stoyanchev 6f4cc4f170 Polish PubSubChannelRegistryBuilder 2013-06-14 22:24:03 -04:00
Rossen Stoyanchev 4f7d77f631 Add PubSubChannelRegistry and associated builder 2013-06-14 22:07:47 -04:00
Rossen Stoyanchev c5b1f02c3a Add MessageBuilder 2013-06-14 16:30:02 -04:00
Andy Wilkinson 3022f5e34f Make Message type pluggable
To improve compatibility between Spring's messaging classes and
Spring Integration, the type of Message that is created has been made
pluggable through the introduction of a factory abstraction;
MessageFactory.

By default a MessageFactory is provided that will create
org.springframework.messaging.GenericMessage instances, however this
can be replaced with an alternative implementation. For example,
Spring Integration can provide an implementation that creates
org.springframework.integration.message.GenericMessage instances.

This control over the type of Message that's created allows messages
to flow from Spring messaging code into Spring Integration code without
any need for conversion. In further support of this goal,
MessageChannel, MessageHandler, and SubscribableChannel have been
genericized to make the Message type that they deal with more
flexible.
2013-06-14 12:34:12 +01:00
Rossen Stoyanchev 641aaf4b6a Use tcp-reactor in StompRelayMessageHandler 2013-06-13 21:48:51 -04:00
Rossen Stoyanchev 78d1063e37 Replace use of PubSub header name literals 2013-06-13 15:24:49 -04:00
Andy Wilkinson 8cea9ca962 Correct the Assert imports
Import org.springframework.util.Assert rather than reactor.util.Assert
2013-06-13 15:44:01 +01:00
Rossen Stoyanchev 3712f73f38 Remove EventBus 2013-06-13 01:36:55 -04:00
Rossen Stoyanchev 3e0aac08dc Add SubscribableChannel and ReactorMessageChannel 2013-06-13 01:13:37 -04:00
Rossen Stoyanchev a1cfa3832e Polish 2013-06-13 01:13:04 -04:00
Rossen Stoyanchev c420f37137 Fix setting of message-id STOMP header 2013-06-12 13:39:35 -04:00
Rossen Stoyanchev 82dfd781d0 Consolidate STOMP WebSocketHandler class hierarchy 2013-06-12 09:43:40 -04:00
Rossen Stoyanchev ad41f095a1 Refactor STOMP and PubSub header message support 2013-06-11 17:07:48 -04:00
Rossen Stoyanchev e7dde941b7 Update STOMP MESSAGE frames with messageId 2013-06-11 10:49:31 -04:00
Rossen Stoyanchev d26b9d60e5 Refactor approach to working with STOMP headers 2013-06-11 01:52:32 -04:00
Rossen Stoyanchev 547167e8b4 Remove remaining Reactor event wrapping 2013-06-10 13:59:19 -04:00
Rossen Stoyanchev de899820c9 Add Message, MessageChannel and refactor stomp support 2013-06-09 19:36:46 -04:00
Rossen Stoyanchev 8913283ce0 Add AnnotationStompService 2013-06-03 19:35:40 -04:00
Rossen Stoyanchev b194d4d6a0 Add AbstractStompService 2013-05-30 15:29:46 -04:00
Rossen Stoyanchev 4de40fad8e Refactor STOMP package and class names 2013-05-30 15:29:20 -04:00
Rossen Stoyanchev 2b5acbda99 Add handling for remaining STOMP server commands 2013-05-30 15:28:42 -04:00
Rossen Stoyanchev 69ef364ef9 Introduce messaging package
org.springframework.web.stomp is now
org.springframework.web.messaging.stomp

Also classes in the ~.stomp.server and ~.stomp.adapter packages have
been renamed.
2013-05-30 15:28:42 -04:00
Rossen Stoyanchev c67b694339 Add STOMP service that relays messages to STOMP broker 2013-05-30 15:28:42 -04:00
Rossen Stoyanchev 3eac62925b Add basic stomp error handling 2013-05-30 15:28:42 -04:00
Rossen Stoyanchev 730d456e84 Add early STOMP/reactor support 2013-05-30 15:28:42 -04:00
Rossen Stoyanchev 87a9602f65 Fix bug in WebSocketClient implementations 2013-05-16 19:12:27 -04:00
Rossen Stoyanchev fb4e34fce4 Add partial WebSocketMessage support 2013-05-16 12:17:40 -04:00
Rossen Stoyanchev 81bce424cb Fix bug with deriving SockJS path 2013-05-15 21:31:51 -04:00
Rossen Stoyanchev 6825aaf41f Add Javadoc 2013-05-14 16:41:47 -04:00
Rossen Stoyanchev 278a5924cb Remove isLast flag from WebSocketMessage 2013-05-14 14:32:25 -04:00
Rossen Stoyanchev 05084d504b Add spring-websocket module tests 2013-05-14 13:59:15 -04:00
Rob Winch 9468548116 Add @Override to remaining source files
Issue: SPR-10130
2013-05-13 17:04:56 -05:00
Juergen Hoeller 2a44228b98 Consistent use of <pre class="code">
Issue: SPR-8108
2013-05-07 21:31:26 +02:00
Rossen Stoyanchev 37c6a94905 Update deps for spring-websocket 2013-05-06 16:42:42 -04:00
Rossen Stoyanchev d89b18613f Polish (minor) 2013-05-06 14:33:00 -04:00
Rossen Stoyanchev 7845ebc428 Add SockJS path detection 2013-05-05 20:51:37 -04:00
Rossen Stoyanchev 97d225ba75 Refactor packages
org.springframework.websocket  -> org.springframework.web.socket
org.springframework.sockjs     -> org.springframework.web.socket.sockjs

Flatten .sockjs and .sockjs.server
2013-05-02 20:39:54 -04:00
Rossen Stoyanchev 4faf0d265f Rename classes 2013-05-02 20:25:09 -04:00
Rossen Stoyanchev 2a7935a913 Add WebSocketSession attributes + initialization
In addition to adding the attributes, there is now mechanism for
initializing WebSocketSession instances from attributes of the
handshake request.
2013-05-02 13:47:18 -04:00
Rossen Stoyanchev 166ca7a5a3 Update exception handling
Allow WebSocketHandler methods to raise an exception.

By default we install ExceptionWebSocketHandlerDecorator, which logs
unhandled exceptions and closes the session. That decorator can be
extended or replaced.

Any exceptions that remain unhandled still (i.e. no exception handling
decorator), are caught in the lowest level before propagating to the
WebSocket engine or a SockJS transport handler and handled the same
way. That means default behavior is guaranteed but also fully
customizable.
2013-05-01 16:04:58 -04:00
Rossen Stoyanchev 9ca4672300 Fix handshake handling issue 2013-05-01 14:18:25 -04:00
Rossen Stoyanchev 46bcffcf30 Add JettyWebSocketClient
Also split out JSR-356 related configuration and load it conditionally.
2013-04-30 17:35:20 -04:00
Rossen Stoyanchev f45ef75f95 Add WebSocketHandlerDecorator 2013-04-29 22:36:20 -04:00
Rossen Stoyanchev ba87743087 Polish (minor) 2013-04-29 10:17:57 -04:00
Rossen Stoyanchev f347988428 Remove parameterized type from WebSocketHandler 2013-04-27 05:56:46 -04:00
Rossen Stoyanchev 0c1b329949 Remove HandlerProvider 2013-04-26 21:59:04 -04:00
Rossen Stoyanchev 861ab900ae Switch to single message method for WebSocketHandler 2013-04-26 12:04:45 -04:00
Rossen Stoyanchev 5f22cf0532 Add WebSocketHandlerInvoker class 2013-04-25 23:12:21 -04:00
Phillip Webb db2c2480db Javadocs and general formatting polish 2013-04-25 16:47:25 -07:00
Rossen Stoyanchev 9da2c21edb Consolidate WebSocketHandler interface and sub-interfaces 2013-04-25 19:01:49 -04:00
Rossen Stoyanchev 8200601ace Tighten up exception handling strategy
WebSocketHandler implementations:
- methods must deal with exceptions locally
- uncaught runtime exceptions are handled by ending the session
- transport errors (websocket engine) are passed into handleError

WebSocketSession methods may raise IOException

SockJS implementation of WebSocketHandler:
- delegate SockJS transport errors into handleError
- stop runtime exceptions from user WebSocketHandler and end session

SockJsServce and TransportHandlers:
- raise IOException or TransportErrorException

HandshakeHandler:
- raise IOException
2013-04-25 18:31:07 -04:00
Rossen Stoyanchev 34c95034d8 Fix minor issue and polish 2013-04-24 13:29:08 -04:00
Rossen Stoyanchev 36148b7cb1 Switch DefaultSockJsService to constructor DI
DefaultSockJsService now relies on constructors and requires a
TaskScheduler at a minimum. It no longer needs lifecycle methods.
2013-04-23 21:35:24 -04:00
Rossen Stoyanchev c28ce0e2bd Ensure WebSocketHandlerEndpoint can connect only once
WebSocketHandlerEndpoint and SockJsWebSocketHandler are stateful
wrappers that are not intended to be used with one client connection.
2013-04-23 17:44:53 -04:00
Phillip Webb db4de526d2 Minor polish and FIXMEs 2013-04-23 13:47:52 -07:00
Phillip Webb ff2e9aa5bc Minor tweaks to WebSocketMessage
- payload is now required
- byte data is obtained and stored only once (allowing multiple calls)
- minor formatting polish
2013-04-23 13:47:52 -07:00
Phillip Webb a14161f0ca JettyRequestUpgradeStrategy 2013-04-23 13:47:43 -07:00
Rossen Stoyanchev 3cd4909ba3 Minor fix 2013-04-23 11:56:57 -04:00
Rossen Stoyanchev 84089bf396 Add HandlerProvider interface
HandlerProvider is now an interface that can be used to plug in
WebSocket handlers with per-connection scope semantics. There are two
implementations, of the interface, one simple and a second that creates
handler instances through AutowireCapableBeanFactory.

HandlerProvider also provides a destroy method that is used to
apply a destroy callback whenever a client connection closes.
2013-04-23 11:48:10 -04:00
Rossen Stoyanchev f9078c947f Add WebSocketMessage and WebSocketHandler sub-interfcs
There is now a WebSocketMessage type with TextMessage and BinaryMessage
sub-types. WebSocketHandler is also sub-divided into TextMessageHandler
and BinaryMessageHandler, so that applications can choose to handle
text, binary, or both.

Also in this commit, the SockJsHandler and SockJsSession interfaces
have been removed. SockJsService now accepts WebSocketHandler.
2013-04-22 17:59:19 -04:00
Rossen Stoyanchev 2046629945 Add WebSocketClient and WebSocketConnectionManager
This change adds a WebSocketClient abstraction and enables the use of
WebSocketHandler on the client side.
2013-04-21 10:04:44 -04:00
Rossen Stoyanchev ab5d60d343 Improve APIs for WebSocket and SockJS messages 2013-04-18 22:04:18 -04:00
Rossen Stoyanchev 6273fc41f1 Rename SockJS session type to include "SockJs" 2013-04-17 11:26:20 -04:00
Rossen Stoyanchev 2794224b28 Add onClosed to SockJsSessionSupport sub-classes
As opposed to close(), which actively closes the session, the
onClosed method is called when the underlying connection has been
closed or disconnected.
2013-04-17 11:19:28 -04:00
Rossen Stoyanchev f056f7e2ad Init and destroy internally created SockJS schedulers 2013-04-15 15:28:06 -04:00
Rossen Stoyanchev 177e082172 Refactor SockJS and WebSocket layer configuration
Add HandlerProvider<T> class
Modify HandshakeHandler to accept + adapt WebSocketHandler at runtime
Modify SockJsService to accept + adapt SockJsHandler at runtime
2013-04-15 11:03:24 -04:00
Rossen Stoyanchev 71e82069ce Add SockJsSessionFactory 2013-04-15 11:03:24 -04:00
Rossen Stoyanchev 3a2c15b0fd Add flush method to ServerHttpResponse
This is useful to make sure response headers are written to the
underlying response. It is also useful in conjunction with long
running, async requests and HTTP streaming, to ensure the Servlet
response buffer is sent to the client without additional delay and
also causes an IOException to be raised if the client has gone away.
2013-04-15 11:03:24 -04:00
Rossen Stoyanchev db6f8f2d4b Add package-info, javadoc, and update package names 2013-04-15 11:03:24 -04:00
Rossen Stoyanchev 592da431a8 Add Glassfish request upgrade strategy 2013-04-15 11:03:24 -04:00
Rossen Stoyanchev 6bd6311214 Refactor SockJS code
- configure SockJS handler by type (as well as by instance)
- add method to obtain SockJS handler instance via SockJsConfiguration
- detect presense of jsr-356 and use it if available
2013-04-15 11:03:24 -04:00
Rossen Stoyanchev 4ad6091510 Debug and test SockJS server support 2013-04-15 11:03:24 -04:00
Rossen Stoyanchev 41153efd03 Polish in EndpointRegistration 2013-04-15 11:03:24 -04:00
Rossen Stoyanchev 6cf17449fa Add endpoint connection manager 2013-04-15 11:03:24 -04:00
Rossen Stoyanchev 914e969ac3 Add support for @ServerEndpoint annotated classes 2013-04-15 11:03:24 -04:00
Rossen Stoyanchev 88447e503b Add first cut of SockJS server support 2013-04-15 11:03:24 -04:00
Rossen Stoyanchev 30ab5953f9 Add EndpointRequestUpgradeStrategy
Now there is just one EndpointHandshakeRequestHandler that works on
different runtimes.
2013-04-15 11:03:24 -04:00
Rossen Stoyanchev 741927664c Update package structure 2013-04-15 11:03:24 -04:00
Rossen Stoyanchev 715018fe75 Add handshake request handler abstraction 2013-04-15 11:03:24 -04:00
Rossen Stoyanchev cdd7d7bd88 Add javax.websocket.Endpoint configuration support 2013-04-15 11:03:24 -04:00
Rossen Stoyanchev 4e67f809fb Add spring-websocket module 2013-04-15 11:03:23 -04:00