Commit Graph

328 Commits

Author SHA1 Message Date
Rossen Stoyanchev 2b1ff4c5db Fix condition in SubProtocolWebSocketHandler
Issue: SPR-11884
2014-06-29 17:00:24 -04:00
Rossen Stoyanchev 7441f23012 Add support for removeOnCancelPolicy
This change removes the recently added SockJsThreadPoolTaskScheduler
and instead builds support for the removeOnCancelPolicy property in
ThreadPoolTaskScheduler and ScheduledExecutorFactoryBean.

Issue: SPR-11918
2014-06-29 14:28:52 -04:00
Rossen Stoyanchev 7dc2b2927e Use SESSION_NOT_RELIABLE when no messages received
When a WebSocket session is closed after not having received any
messages, we'll use SESSION_NOT_RELIABLE to indicate to other parts
of the session closing code not to send anything further (e.g.
SockJS "Go Away!" frame).

Issue: SPR-11884
2014-06-29 13:15:21 -04:00
Rossen Stoyanchev 3af488a701 Avoid multiple invocations of afterConnectionClosed
This change ensures the state of a SockJS session is set to CLOSED
immediately after close is invoked. This avoids duplicate invocations
of afterConnectionClosed in WebSocket transport.

Issue: SPR-11884
2014-06-29 13:15:21 -04:00
Rossen Stoyanchev 86de416908 More WebSocket logging updates
Update WebSocketSession toString methods to include the handshake URI
and add id and URI fields to ensure they're available after close().

Log WebSocket session open and close events at INFO.

Remove trace messages for destinations that do not match.

Issue: SPR-11884
2014-06-29 13:15:02 -04:00
Rossen Stoyanchev 1c91a52639 Add STOMP subscribe/unscubscribe ApplicationContext events
Issue: SPR-11813
2014-06-28 11:07:42 -04:00
Rossen Stoyanchev 7a5b3c1eed Append suffx to user dest in SimpMessagingTemplate
Isssue: SPR-11868
2014-06-27 12:43:52 -04:00
Rossen Stoyanchev 113fd1180a Fine tune STOMP and WebSocket related logging
Optimize logging with tracking the opening and closing of WebSocket
sessions and STOMP broker connections in mind.

While the volume of messages makes it impractical to log every message
at anything higher than TRACE, the opening and closing of connections
is more manageable and can be logged at INFO. This makes it possible to
drop to INFO in production and get useful information without getting
too much in a short period of time.

The logging is also optimized to avoid providing the same information
from multiple places since messages pass through multiple layers.

Issue: SPR-11884
2014-06-27 04:06:06 -04:00
Brian Clozel b2f6445058 Fix unit test for SPR-11919
Issue: SPR-11919
2014-06-27 10:01:27 +02:00
Brian Clozel 24cdefb785 Workaround for WFLY-3474 NullPointerException
Prior to this commit, the ServletResponseHttpHeaders.get method
would throw an NPE when used under Wildfly 8.0.0.Final and 8.1.0.Final.
This can be traced to WFLY-3474, which throws an NPE when calling
HttpServletResponse.getHeaders("foo") and that header has not
been defined prior to that.
This would cause NPE being thrown by AbstractSockJsService when
checking for CORS HTTP headers in the server HTTP response.

This commit surrounds that method call in AbstractSockJsService and
guards against this issue.

Issue: SPR-11919
2014-06-26 23:47:10 +02:00
Rossen Stoyanchev 9796af72db Improve JettySockJsIntegrationTests to show real error
In a recent CI build failure a test timed out waiting for a message:
https://build.spring.io/browse/SPR-PUB-1316

In fact there was a WebSocket transport failure originating in Jetty's
WebSocket Parser. However this failure is only apparent by looking at
the logs. This change adds a check if a transport error ocurred while
we were waiting and throws an AssertionError.
2014-06-26 10:07:00 -04:00
Rossen Stoyanchev a3fa9c9797 Add check for unused WebSocket sessions
Sessions connected to a STOMP endpoint are expected to receive some
client messages. Having received none after successfully connecting
could be an indication of proxy or network issue. This change adds
periodic checks to see if we have not received any messages on a
session which is an indication the session isn't going anywhere
most likely due to a proxy issue (or unreliable network) and close
those sessions.

Issue: SPR-11884
2014-06-26 10:07:00 -04:00
Juergen Hoeller 98d6f7b443 Polishing 2014-06-26 16:01:24 +02:00
Juergen Hoeller 8ea0d8eea1 Latest dependency updates (AspectJ 1.8.1, Reactor 1.1.2, Tomcat 8.0.9, Jackson 2.4.1, JAMon 2.76) 2014-06-26 12:21:21 +02:00
Rossen Stoyanchev 0f47732523 Fix failing test 2014-06-25 15:51:42 -04:00
Rossen Stoyanchev 6ad79e03c6 Create SockJS ThreadPoolTaskScheduler extension
Commit 5d2e6f enabled the setRemoveOnCancelPolicy of the SockJS
ScheduledThreadPoolExecutor by default. However that property is only
available in JDK 1.7 or later. This change fixes the issue and
introduces an extension of ThreadPoolTaskScheduler for for use with
SockJS which is necessary in any case since ThreadPoolTaskScheduler
does not expose the underlying ScheduledThreadPoolExecutor otherwise.

Issue: SPR-11918
2014-06-25 15:08:42 -04:00
Rossen Stoyanchev 1e342e4dbf Use SimpleAsyncTaskExecutor in WebSocketClient impls
JettyWebsocketClient and StandardWebSocketClient now use the
SimpleAsyncTaskExecutor by default to ensure non-blocking connect.
2014-06-25 14:09:42 -04:00
Rossen Stoyanchev 5d2e6f6d4c Prevent unbounded retention of cancelled SockJS tasks
This change sets the removeOnCancelPolicy on the SockJS
ScheduledThreadPoolExecutor to true. This ensures that cancelled
tasks are removed immediately to avoid the "unbounded retention
of cancelled tasks" that is mentioned in the Javadoc of
ScheduledThreadPoolExecutor:

"By default, such a cancelled task is not automatically removed from
the work queue until its delay elapses. While this enables further
inspection and monitoring, it may also cause unbounded retention of
cancelled tasks. To avoid this, set setRemoveOnCancelPolicy to true,
which causes tasks to be immediately removed from the work queue at
time of cancellation."

Issue: SPR-11918
2014-06-25 14:09:42 -04:00
Rossen Stoyanchev fcf6ae8328 Fix concurrency issues in SockJS session impls
This change ensures the server "WebSocketHandler" is notified of the
opening of a session before writing the open frame to the remote
handler. Any messages sent by the server "WebSocketHandler" while
getting notified of the opening get cached and flushed after the open
frame has been written.

This change introduces locking in AbtractHttpSockJsSession to guard
access to the HTTP response. The goal is to prevent contention between
client requests to receive messages (i.e. long polling) and
the application trying to write.

Issue: SPR-11916
2014-06-25 14:09:42 -04:00
Rossen Stoyanchev e82df99a22 Add SockJS client
This change adds a new implementation of WebSocketClient that can
connect to a SockJS server using one of the SockJS transports
"websocket", "xhr_streaming", or "xhr". From a client perspective
there is no implementation difference between "xhr_streaming" and
"xhr". Just keep receiving and when the response is complete,
start over. Other SockJS transports are browser specific
and therefore not relevant in Java ("eventsource", "htmlfile" or
iframe based variations).

The client loosely mimics the behavior of the JavaScript SockJS client.
First it sends an info request to find the server capabilities,
then it tries to connect with each configured transport, falling
back, or forcing a timeout and then falling back, until one of the
configured transports succeeds.

The WebSocketTransport can be configured with any Spring Framework
WebSocketClient implementation (currently JSR-356 or Jetty 9).

The XhrTransport currently has a RestTemplate-based and a Jetty
HttpClient-based implementations. To use those to simulate a large
number of users be sure to configure Jetty's HttpClient executor
and maxConnectionsPerDestination to high numbers. The same is true
for whichever underlying HTTP library is used with the RestTemplate
(e.g. maxConnPerRoute and maxConnTotal in Apache HttpComponents).

Issue: SPR-10797
2014-06-25 13:56:04 -04:00
Rossen Stoyanchev dc1d85d045 Support registering Filters in WebSocket test servers 2014-06-25 08:50:26 -04:00
Rossen Stoyanchev c14ba1a0ff Add SockJsFrameType enum
SPR-10797
2014-06-25 08:50:26 -04:00
Rossen Stoyanchev c86f711de5 Polish SockJsFrame 2014-06-25 08:50:26 -04:00
Juergen Hoeller 18131bf611 Consistent declaration of private static final logger variables
Issue: SPR-11905
2014-06-24 14:02:05 +02:00
Rossen Stoyanchev c809143cc4 Upgrade to Undertow 1.0.15 and fix failing test
Issue: SPR-11777
2014-06-11 17:45:19 -04:00
Rossen Stoyanchev fc91add35e Allow custom UrlPathHelper for WebSocket requests
Issue: SPR-117711
2014-06-09 17:42:43 -04:00
Rossen Stoyanchev 9706e5cc99 Update Javadoc on SockJS client library URL
Issue: SPR-11766
2014-06-06 10:32:04 -04:00
Juergen Hoeller f7b465390c Moved @Uses annotations to org.springframework.lang; fixed Base64Utils to declare Java 8, and fixed PathResource's declaration to refer to Java 7.
Issue: SPR-11604
2014-06-04 21:34:23 +02:00
Rossen Stoyanchev 4372dac002 Polish 2014-05-30 12:04:32 -04:00
Artem Bilan 0dddb6f3e1 Fix issue with StompSubProtocolHandler initialization
This change ensures that StompSubProtocolHandler is injected with an
ApplicationEventPublisher for both the Java and XML config.

Issue: SPR-11825
2014-05-30 12:04:32 -04:00
Juergen Hoeller 2750ab6734 Undertow-related polishing 2014-05-12 23:14:16 +02:00
Rossen Stoyanchev 2c4cbb617e Add WebSocket scope
This change adds support for a custom "websocket" scope.

WebSocket-scoped beans may be injected into controllers with message
handling methods as well as channel interceptor registered on the
"inboundClientChannel".

Issue: SPR-11305
2014-05-11 12:31:17 -04:00
Rossen Stoyanchev 66c63c374b Ensure handshake attrs are copied in SockJS session 2014-05-09 17:01:37 -04:00
Rossen Stoyanchev 97fb308b6b Allow use of @SendToUser even w/o authenticated user
Before this change, subscribing to a user destination and use of
@SendToUser annotation required an authenticated user.

This change makes it possible to subscribe to a user destination from
WebSocket sessions without an authenticated user. In such cases the
destination is associated with one session only rather than with a
user (and all their sessions).

It is then also possible to send a message to a user destination
via "/user/{sessionId}/.." rather than "/user/{user}/...".

That means @SendToUser works relying on the session id of the input
message, effectively sending a reply to destination private to the
session.

A key use case for this is handling an exception with an
@MessageExceptionHandler method and sending a reply with @SendToUser.

Issue: SPR-11309
2014-05-08 22:06:57 -04:00
Rossen Stoyanchev ae30a60d03 Relax websocket xsd attr types for ${} style props
Issue: SPR-11624
2014-05-02 15:17:04 -04:00
Rossen Stoyanchev 209bb4ee4b Fix Javadoc typo 2014-04-30 10:06:57 -04:00
Stephane Nicoll bd85c916eb Integrate animal sniffer
Animal sniffer provides tools to assist verifying that classes
compiled with a newer JDK are compatible with an older JDK.

This integratesthe latest version of the tool (1.11) that
permits the use of custom annotations. Added @UsesJava7,
@UsesJava8 and @UsesSunHttpServer and annotated the few places
where we rely on a specific environment.

The verification process can be invoked by running the 'sniff'
task.

Issue: SPR-11604

polishing
2014-04-30 13:51:01 +02:00
Juergen Hoeller 6cb45f714e General defensiveness about the bootstrap ClassLoader (i.e. null ClassLoader)
Issue: SPR-11721
(cherry picked from commit 59cef3c)
2014-04-28 00:47:21 +02:00
Rossen Stoyanchev 1200755125 Fix issue with subscribe destination
The original fix for SPR-11423:
32e5f57e64

was insufficient when using an external broker since the original
destination header has to be in the "native headers" map (i.e. with
STOMP headers) in order to be included in messages broadcast by
the broker.
2014-04-25 12:26:04 -04:00
Stephane Nicoll 5559209233 Remove useless imports 2014-04-22 09:57:12 +02:00
Philippe Marschall e98d3f790b Clean up spring-websocket imports
spring-websocket is full of unused imports. This commit removes all
unused imports from spring-websocket.
2014-04-22 07:28:56 +02:00
Juergen Hoeller 48c977afdc Polishing 2014-04-17 21:19:47 +02:00
Rossen Stoyanchev 4e1781ae8c Use strategy for customizing ID/TIMESTAMP generation
Issue: SPR-11468
2014-04-14 21:03:13 -04:00
Rossen Stoyanchev 65b17b80ba Switch BufferingStompDecoder to decoration
The BufferingStompDecoder now decorates rather than extend
StompDecoder. This allows a single StompDecoder instance to be
configured and extended independantly while buffering remains a
separate concern.
2014-04-13 21:35:22 -04:00
Rossen Stoyanchev ae942ffdb8 Make use of enhanced MessageHeaderAccessor support
Mutate rather than re-create headers when decoding STOMP messages
before a message is sent on a message channel.

Use MessageBuilder.createMessage to ensure the fully prepared
MessageHeaders is used directly MessageHeaderAccessor instance.

Issue: SPR-11468
2014-04-13 18:43:25 -04:00
Rossen Stoyanchev 4867546aec Enhance MessageHeaderAccessor support
Refine semantics of ID and TIMESTAMP headers provided to protected
MessageHeaders constructor.

Refactor internal implementation of MessageHeaderAccessor.

Support mutating headers from a single thread while a message is being
built (e.g. StompDecoder creating message + then adding session id).

Improve immutablity in NativeMessageHeaderAccessor and in
StompHeaderAccessor.

Optimize object creation for initializing messages and subsequent
accessing their headers.

Introduce MessageHeaderAccessorFactory support to enable applying a
common strategies for ID and TIMESTAMP generation to every message.

Add MessageBuilder shortcut factory method for creating messages from
payload and a full-prepared MessageHeaders instance. Also add
equivalent constructors to GenericMessage and ErrorMessage.

Issue: SPR-11468
2014-04-13 18:43:25 -04:00
Rossen Stoyanchev 5e925ac03c Rename header for "orig" destination
The UserDestinationMessageHandler adds a header providing a hint for
what the original destination a user may have used when subscribing.
That is then used when writing messages back to WebSocket clients to
ensure they dont see the internally used, transformed user destination.

This change moves the header name constatn to make it more broadly
applicable. For example SPR-11645.
2014-04-04 14:31:49 -04:00
Brian Clozel ec0b672baa Fix @SubscribeMapping MESSAGE response destination
Prior to this commit, @SubscribeMapping mapped methods (backed with
@SendTo* annotations, or not) would send MESSAGEs with the wrong
destination. Instead of using the original SUBSCRIBE destination, it
would use the lookup path computed from the configured prefixes in the
application.

This commit fixes this issue - now @SubscribeMapping MESSAGEs use the
original SUBSCRIBE destination.

Issue: SPR-11648
2014-04-04 12:43:35 +02:00
Rossen Stoyanchev 990f5bb720 Improve handling of disconnects in STOMP broker relay
Issue: SPR-11655
2014-04-03 22:31:10 -04:00
Rossen Stoyanchev 8edbdf4ddb Fix failing test 2014-04-01 13:33:09 -04:00