Commit Graph

231 Commits

Author SHA1 Message Date
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