Commit Graph

575 Commits

Author SHA1 Message Date
Juergen Hoeller 86c5880888 Polishing 2014-08-21 18:41:23 +02:00
Juergen Hoeller 11805b6a5d ServerEndpointExporter can initialize itself based on a late-provided ServletContext as well (for Boot)
Also allows for direct setting of a ServerContainer and for custom triggering of endpoint registration.

Issue: SPR-12109
2014-08-21 18:40:35 +02:00
Juergen Hoeller 2ef3d66c89 Polishing 2014-08-18 19:27:08 +02:00
Phillip Webb ac8326d2df Polish mockito usage
Consistent use of BDDMockito rather than standard Mockito.
2014-08-11 16:23:11 -07:00
Sebastien Deleuze 3922f6fc53 Update references to RFC 2616
Replace references to the old RFC 2616 (HTTP 1.1) with references
to the new RFCs 7230 to 7235.

This commit also deprecates:
 - HttpStatus.USE_PROXY
 - HttpStatus.REQUEST_ENTITY_TOO_LARGE in favor of HttpStatus.PAYLOAD_TOO_LARGE
 - HttpStatus.REQUEST_URI_TOO_LONG in favor of HttpStatus.URI_TOO_LONG

Issue: SPR-12067
2014-08-07 14:50:45 +02:00
Stephane Nicoll 3da68cfe21 Remove unused imports 2014-08-04 14:13:40 +02:00
Rossen Stoyanchev 8751936b12 Fix issue with sub-protocol negotiation and SockJS
Before this change the SockJsWebSocketHandler precluded determination
of the sub-protocols by wrapping the actual target handler.

After this change SockJsWebSocketHandler implements SubProtocolCapable
and returns the list of sub-protocols from the wrapped handler.
2014-07-31 10:33:11 -04:00
Rossen Stoyanchev 41cdc92fc3 Remove AbstractWebSocketClient from SockJsClient
SockJsClient now implements WebSocketClient directly without extending
AbstractWebSocketClient.

Issue: SPR-12030
2014-07-30 15:39:01 -04:00
Rossen Stoyanchev c68b4c01e1 Polish SockJsClient 2014-07-30 15:29:46 -04:00
Rossen Stoyanchev ba952ca331 Fix test condition 2014-07-30 09:02:23 -04:00
Rossen Stoyanchev c89325b9ca Add WebLogicRequestUpgradeStrategy
This change creates an AbstractTyrusRequestUpgradeStrategy shared
between the WebLogic and GlassFish sub-classes.

The version of Tyrus is lowered to 1.3.5 to match the version used
in WebLogic (12.1.3) and that in turn requires a little extra effort
in the base AbstractTyrusRequestUpgradeStrategy to make up for
changes that have taken place from Tyrus 1.3.5 to 1.7.

Issue: SPR-11293
2014-07-25 17:16:00 -04:00
Rossen Stoyanchev 88d8dff3ac Upgrade to Tyrus 1.7
This change provides WebSocket support for the upcoming Glassfish 4.0.1
release while at the same dropping support for Glassfish 4.0 due to
incompatible changes.

Issue: SPR-11094
2014-07-24 09:58:22 -04:00
Rossen Stoyanchev afb56681ac Fix minor issue in StandardToWebSocketExtensionAdapter
This change ensures proper initialization of a WebSocketExtension
from a JSR-356 Extension.

This is in preparation for SPR-11094
2014-07-24 09:58:22 -04:00
Rossen Stoyanchev e74ac06733 Filter WebSocket extensions
Before this change the DefaultHandshakeHandler by default passed the
list of requested WebSocket extensions as-is relying on the WebSocket
engine to remove those not supported.

This change ensures that WebSocket extensions not supported by the
runtime are proactively removed instead.

This change is preparation for SPR-11094.
2014-07-24 09:58:22 -04:00
Rossen Stoyanchev 73267d7523 Ensure Undertow 1.1 compatibility
Issue: SPR-11914
2014-07-22 15:28:40 -04:00
Rossen Stoyanchev 988499f7dc Remove awaitCloseStatus in SockJS integration tests
A CloseStatus may not be received if the connection is closed while
the client is between XHR polling requests.
2014-07-22 13:40:02 -04:00
Juergen Hoeller 9d6c38bd54 Consistent bracket alignment 2014-07-18 17:21:58 +02:00
Rossen Stoyanchev 90f8e4b71f Add @Ignored temporarily to Jetty SockJS tests 2014-07-18 00:45:14 -04:00
Rossen Stoyanchev b18ed6b724 Remove erroneously commited code 2014-07-16 20:49:12 -04:00
Rossen Stoyanchev 89b202029a Fix failing test 2014-07-15 22:59:25 -04:00
Rossen Stoyanchev d86e4cf203 Re-obtain port on every WebSocket integration test
This change adds a WebSocketTestServer setup method that initializes
the server and obtains a new port.

In turn AbstractWebSocketIntegrationTests invokes the new method from
its setup method thus ensuring a new port is used on every test.
2014-07-15 16:53:38 -04:00
Rossen Stoyanchev ea7ae8949e Use regex comparison in WebSocket stats test
The output includes thread pool information which appears to not vary
enough to cause failures locally but does so on the build server.
2014-07-15 16:53:38 -04:00
Rossen Stoyanchev 4dd5c274a0 Add missing HandshakeInterceptor for STOMP endpoints
Issue: SPR-11845
2014-07-15 13:31:30 -04:00
Rossen Stoyanchev 6d6cc0ecec Polish WebSocket Java config 2014-07-15 13:31:30 -04:00
Rossen Stoyanchev 85c175059a Add missing handshake-interceptor namespace support
Issue: SPR-11845
2014-07-15 13:31:29 -04:00
Rossen Stoyanchev 61e77eeb61 Fix white spaces 2014-07-15 13:31:29 -04:00
Rossen Stoyanchev 6557800f97 Polish WebSocket namespace 2014-07-15 13:31:29 -04:00
Rossen Stoyanchev ab2526a586 Update support for using "." as path separator
Issue: SPR-11660
2014-07-14 18:49:25 -04:00
Sebastien Deleuze 928a466b5d Allow to customize separator for messaging destinations
In order to be able to use separators like "." (used by default
by most broker relays) instead of "/" for destination patterns
handling, the PathMatcher used in spring-messaging can now
be customized easily thanks to XML websocket namespace
or JavaConfig.

AntPathMatcher has been updated in order to use the configured path
separator instead of an hardcoded "/" for path concatenation.
Extension handling is now disabled when the "." separator is configured.

Issue: SPR-11660
2014-07-14 18:49:24 -04:00
Rossen Stoyanchev 670c216d38 Change converter ordering in message broker config
Issue: SPR-11961
2014-07-10 12:57:00 -04:00
Rossen Stoyanchev 2ebc921545 Add Lifecycle to SockJsClient and Transport types
Issue: SPR-10797
2014-07-10 12:56:59 -04:00
Rossen Stoyanchev d73c1d5693 Update WebSocket client SmartLifecycle support
Before this change WebSocketConnectionManager delegated SmartLifecycle
methods to the client instance it contained. After this change
WebSocketClient implementations are expected to implement Lifecycle
(rather than SmartLifecycle).

The need for this is even more evident with SockJsClient, which is a
WebSocketClient implementation and contains a WebSocketTransport that
in turn contains the actual WebSocketClient. In this case
WebSocketConnectionManager as the top level container is the obvious
place to configure autostartup while Lifecycle events can be
propagated all the way down to the root WebSocketClient.
2014-07-10 12:56:59 -04:00
Juergen Hoeller 3c726aa6c1 Polishing 2014-07-09 21:24:59 +02:00
Rossen Stoyanchev bc62d63fdd Fix left-over merge issue from previous commit 2014-07-09 00:46:06 -04:00
Rossen Stoyanchev 48236be4a2 STOMP and WebSocket messaging related logging updates
This change removes most logging at INFO level and also ensures the
amount of information logged at DEBUG level is useful, brief, and
not duplicated.

Also added is custom logging for STOMP frames to ensure very readable
and consise output.

Issue: SPR-11934
2014-07-09 00:39:59 -04:00
Rossen Stoyanchev ab4864da2a Add STOMP/WebSocket stats collection
This change adds collection of stats in key infrastructure components
of the WebSocket message broker config setup and exposes the gathered
information for logging and viewing (e.g. via JMX).

WebSocketMessageBrokerStats is a single class that assembles all
gathered information and by default logs it once every 15 minutes.
Application can also easily expose to JMX through an MBeanExporter.

A new section in the reference documentation provides a summary of
the available information.

Issue: SPR-11739
2014-07-09 00:39:47 -04:00
Juergen Hoeller b559f15a00 Polishing 2014-07-07 21:45:40 +02:00
Juergen Hoeller 387da221c3 Polishing
Issue: SPR-11963
2014-07-07 19:41:39 +02:00
Brian Clozel 6bcb48f95d Polish SPR-11963 2014-07-07 17:34:08 +02:00
Brian Clozel e549103ca0 Remove Jackson dependency from TransportHandler hierarchy
Prior to this change, AbstractHttpReceivingTransportHandler had a direct
dependency on a Jacckson Exception (checking that exception in a catch
clause). This can cause issues for applications that don't have that
dependency.

This commit removes that direct dependency, still logging the
appropriate log messages using a parent exception (IOException) and
reflection.

Issue: SPR-11963
2014-07-07 17:29:32 +02:00
Rossen Stoyanchev 6d15fcc4a6 Log name of test for WebSocket integration tests
This makes it easier to trace log output on the CI server where the
output is per class.
2014-07-02 14:26:51 -04:00
Rossen Stoyanchev 59e02e63c4 Synchronize request init in AbstractHttpSockJsSession
Although unlikely in practice (but not impossible), the SockJS
integration tests write a message while the request is initializing.
This change adds synchronization around request intiailization
for the SockJS HTTP sesion.

Issue: SPR-11916
2014-07-02 13:53:23 -04:00
Juergen Hoeller e90143e03b Polishing 2014-07-01 12:52:09 +02:00
Rossen Stoyanchev 06d3e1b94e Fix Javadoc typo 2014-06-30 13:27:54 -04:00
Rossen Stoyanchev 71b942698d Fix sniff task warnings 2014-06-29 22:56:53 -04:00
Rossen Stoyanchev b1aebb2c0c Fix failing test 2014-06-29 22:09:54 -04:00
Rossen Stoyanchev cb40908a7d Fix warnings from the sniff task 2014-06-29 17:35:00 -04:00
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
Rossen Stoyanchev 8ab8448148 Move tests to packages where they belong 2014-04-01 13:16:51 -04:00
Rossen Stoyanchev 73ecbc047c Update JettyWebSocketSession
Ensure the JettyWebSocket session can return the Principal and accepted
WebSocket sub-protocol even after the session is closed.

Issue: SPR-11621
2014-04-01 13:13:55 -04:00
Sebastien Deleuze a805f12374 Make WebSocket fields available after it is closed
Update some native WebSocket session getters to return basic
information after it is closed. It is required for example in
SubProtocolWebSocketHandler#afterConnectionEstablished() or
StompSubProtocolHandler#afterSessionStarted().

Issue: SPR-11621
2014-04-01 11:26:22 -04:00
Rossen Stoyanchev 6ec3de6029 Fix issue with default executor for broker channel
The default for the broker channel should be "no executor".

Issue: SPR-11623
2014-04-01 11:18:28 -04:00
Sebastien Deleuze fb7d81c4a2 Fix <websocket:interceptors> default configuration
Adding a ChannelInterceptor does not suppress default executor
settings anymore in the XML namespace.

Issue: SPR-11623
2014-04-01 10:49:09 -04:00
Rossen Stoyanchev ace6bd2418 Improve shutdown responsiveness of SubProtocolWSH
Proactively notify all active WebSocket sessions when a shutdown is
progress. Sessions then can ignore further attempts to send messages
and also stop stop trying to flush messages right away.
2014-03-27 20:15:53 -04:00
Rossen Stoyanchev 3347b45292 Provide more accurate error message 2014-03-26 11:32:34 -04:00
Rossen Stoyanchev bbf101eef6 Fix issue in last commit 2014-03-25 09:59:09 -04:00
Rossen Stoyanchev a247d5f2e8 Guard against exceptions from ApplicationListener
Issue: SPR-11578
2014-03-25 09:05:42 -04:00
Rossen Stoyanchev 1c1e1145a2 Allow configuring WebSocket message size in a session
Issue: SPR-11575
2014-03-25 00:27:05 -04:00
Rossen Stoyanchev 5caf36ae91 Update default pools size for SockJS scheduler
This change updates the XML namespace to match a change already made
to the Java config.
2014-03-24 21:44:03 -04:00
Rossen Stoyanchev 13da7057e6 Add session lifecycle ApplicationEvent's
Issue: SPR-11578
2014-03-24 20:30:41 -04:00
Rossen Stoyanchev c11484b2e7 Add WebSocket transport configuration support
Issue: SPR-11527
2014-03-24 19:20:38 -04:00
Rossen Stoyanchev 1e9960e1ce Add WebSocketTransportRegistration
Issue: SPR-11527
2014-03-24 19:20:38 -04:00
Rossen Stoyanchev 545c4effb1 Polish StompDecoder and the new Buffering sub-class
Issue: SPR-11527
2014-03-24 19:20:37 -04:00
Sebastien Deleuze bbdb72d808 Add configuration for message buffer size limit
BufferingStompDecoder message buffer size limit can now be configured
with JavaConfig MessageBrokerRegistry.setMessageBufferSizeLimit() or
with XML <websocket:message-brocker message-buffer-size="">.

Issue: SPR-11527
2014-03-24 19:20:37 -04:00
Rossen Stoyanchev ebffd67b5e Add BufferingStompDecoder
Before this change the StompDecoder decoded and returned only the first
Message in the ByteBuffer passed to it. So to obtain all messages from
the buffer, one had to loop passing the same buffer in until no more
complete STOMP frames could be decoded.

This chage modifies StompDecoder to return List<Message> after
exhaustively decoding all available STOMP frames from the input buffer.
Also an overloaded decode method allows passing in Map that will be
populated with any headers successfully parsed, which is useful for
"peeking" at the "content-length" header.

This change also adds a BufferingStompDecoder sub-class which buffers
any content left in the input buffer after parsing one or more STOMP
frames. This sub-class can also deal with fragmented messages,
re-assembling them and parsing as a whole message.

Issue: SPR-11527
2014-03-24 19:20:37 -04:00
Rossen Stoyanchev 15188a8eee Document IE 8 and 9 related SockJS transport details
Issue: SPR-11496, SPR-11525
2014-03-23 22:52:13 -04:00
Rossen Stoyanchev 7af74b2475 Disable SockJS heartbeat if STOMP heartbeat is on 2014-03-23 02:12:57 -04:00
Rossen Stoyanchev 2c6d6b524d Adjust SockJS scheduler core pool size
Issue: SPR-11556
2014-03-23 01:04:30 -04:00
Rossen Stoyanchev 7651f83b4c Polish 2014-03-23 01:01:39 -04:00
Rossen Stoyanchev cbd5af3a03 Add CloseStatus to indicate unreliable session
When a send timeout is detected, the WebSocket session is now closed
with a custom close status that indicates so. This allows skipping
parts of the close logic that may cause further hanging.

Issue: SPR-11450
2014-03-23 00:51:33 -04:00
Rossen Stoyanchev 4028a3b0bc Remove synchronized keywords from SockJsSession impls
Before this change SockJsSession implementations of WebSocketSession
used synchronization around its method implementations protecting
internal state and ensuring only a single thread is sending messages
at a time.

A WebSocketSession is generally expected to be used from one thread
at a time and now that application messages are sent through
ConcurrentWebSocketSessionDecorator, there is no concern about
application messages sent from the different threads.

While there are some remaining concerns, those can be addressed
without using the synchronized keyword. This change removes it from
the methods of all SockJS session implementations.

Issue: SPR-11450
2014-03-22 22:59:48 -04:00
Rossen Stoyanchev ffac748f1c Improve ConcurrentWebSocketSessionDecorator
Before this change the decorator ensured that for a specific WebSocket
session only one thread at a time can send a message. Other threads
attempting to send would have their messages buffered and each time
that occurs, a check is also made to see if the buffer limit has been
reached or the send time limit has been exceeded and if so the session
is closed.

This change adds further protection to ensure only one thread at a time
can perform the session limit checks and attempt to close the session.
Furthermore if the session has timed out and become unresponsive,
attempts to close it may block yet another thread. Taking this into
consideration this change also ensures that state associated with the
session is cleaned first before an attempt is made to close the session.

Issue: SPR-11450
2014-03-22 22:59:39 -04:00
Rossen Stoyanchev 299be08268 Remove synchronized block around WebSocketSession.send
Since we now wrap the WebSocketSession with a concurrent decorator, the
synchronized keyword around message sending needed to be removed.

Issue: SPR-11586
2014-03-21 11:42:23 -04:00
Brian Clozel 26309838ba Set custom handshakeHandler for XML sockjs config
Prior to this commit, configuring a custom handshakeHandler when setting
up a stomp-endpoint with SockJS would not be taken into account:

  <websocket:stomp-endpoint path="/foo">
    <websocket:handshake-handler ref="customHandler"/>
    <websocket:sockjs/>
  </websocket:stomp-endpoint>

This commit fixes this by creating and registering a
WebsocketTransportHandler (with this handshakeHandler) as a
transportHandler override for the SockJSService.

Issue: SPR-11568
2014-03-21 10:00:11 +01:00
Rossen Stoyanchev b7a974116e Add concurrent WebSocket session decorator (temp commit)
Issue: SPR-11586
2014-03-21 01:29:29 -04:00
Rossen Stoyanchev ac968e94ed Add getter for the length of a WebSocket message 2014-03-20 21:19:18 -04:00
Stephane Nicoll 4cd818b9e4 Harmonize log configuration
Prior to this commit, the codebase was using a mix of log4j.xml
and log4j.properties for test-related logging configuration. This
can be an issue as log4j takes the xml variant first when looking
for a default bootstrap configuration.

In practice, some modules declaring the properties variant were
taking the xml variant configuration from another module.

The general structure of the configuration has also been
harmonized to provide a standard console output as well as an
easy way to enable trace logs for the current module.
2014-03-20 09:43:29 -07:00
Rossen Stoyanchev 10af128e96 Update thread pool settings in STOMP/WebSocket config
The clientInboundChannel and clientOutboundChannel now use twice
the number of available processors by default to accomodate for some
degree of blocking in task execution on average.

In practice these settings still need to be configured explicitly in
applications but these should serve as better default values than
the default values in ThreadPoolTaskExecutor.

Issue: SPR-11450
2014-03-20 00:45:37 -04:00
Rossen Stoyanchev 1bab8a3916 Add session attributes to SimpMessageHeaderAccessor
This change exposes the WebSocketSession attributes through a message header.
The StompSubProtocolHandler adds this to incoming messages.
For now messaging handling  methods can access the map via @Header, e.g.:

@Header(StompHeaderAccessor.SESSION_ATTRIBUTES) Map<String, Object> attrs) {

Issue: SPR-11566
2014-03-19 13:45:40 -04:00
Rossen Stoyanchev 48b62e80d5 Rename handshakeAttributes to just attributes
Issue: SPR-11566
2014-03-19 12:25:08 -04:00
Rossen Stoyanchev 9552c82e2d Remove use of simple executor in WebSocket clients
Issue: SPR-11580
2014-03-19 10:24:48 -04:00
Juergen Hoeller 373f07b1ff Polishing 2014-03-18 22:30:32 +01:00
Rossen Stoyanchev 6bcbb94aba Refine BrokerAvailabilityEvent behavior
Add accessor for brokerAvailable in AbstractBrokerMessageHandler
Ensure brokerAvailable is set even if eventPublisher is not
Add tests BrokerMessageHandlerTests

Turn off brokerAvailable when StompBrokerRelayMessageHandler stops
Actually stop message handling when brokerAvailable=false
Improve log messages

Issue: SPR-11563
2014-03-16 18:12:45 -04:00
Sam Brannen a006ca2542 Remove trailing whitespace 2014-03-13 12:21:32 +01:00
Brian Clozel 8b2b165777 Fix "relay-port" XSD type in spring-websocket.xsd
Prior to this commit, the `relay-port` attribute of the
`<websocket:stomp-broker-relay />` tag was of type `xsd:int`.
This prevents developers from using `PropertyPlaceholderConfigurer`,
even though this configuration key is a good candidate for such use
(this value depends on prod/staging/etc environment).

This commit changes that type to `xsd:string`.

Issue: SPR-11537
2014-03-11 20:33:13 +01:00
Rossen Stoyanchev cff23b84ae Add messages for number of active sessions/connections
Issue: SPR-11531
2014-03-10 16:58:02 -04:00
Rossen Stoyanchev 49d7bda722 Improve CORS handling in AbstractSockJsService
After this change, AbstractSockJsService does not add CORS headers if
the response already contains an "Access-Control-Allow-Origin" header.
Essentially it backs off assuming CORS headers are handled centrally
e.g. through a Filter.

In order to support this, the ServletServerHttpResponse now returns an
instance of HttpHeaders that also provides access to headers already
present in the HttpServletResponse.

Issue: SPR-11443
2014-03-05 21:06:46 -05:00
Rossen Stoyanchev a434903a2a Adjust log level in LoggingWebSocketHandlerDecorator 2014-03-05 11:13:41 -05:00
Sam Brannen 9891bdc7b4 Clean up "abstract" test issues
- Deleted empty AbstractWebSocketClientTests class.

 - AbstractServletHandlerMethodTests and AbstractHttpRequestTests are
   now actually declared as abstract.

 - The following classes are not abstract but currently have an
   "Abstract" prefix and therefore get ignored by the Gradle build.
   This commit renames each of these by deleting the "Abstract" prefix.

   - AbstractFlashMapManagerTests
   - AbstractMappingContentNegotiationStrategyTests
   - AbstractSockJsServiceTests
   - AbstractWebSocketHandlerRegistrationTests
2014-03-05 12:41:26 +01:00
Sam Brannen b42f258c54 Use unmodifiable set in AbstractSockJsSession 2014-03-05 11:04:06 +01:00
Sam Brannen 8f3a897502 Polish AbstractSockJsSession 2014-03-02 16:21:48 +01:00
Rossen Stoyanchev 4238299661 Add smart logging for disconnected SockJS clients
The Servlet API does not provide notifications when a client
disconnects, see see https://java.net/jira/browse/SERVLET_SPEC-44.
Therefore network IO failures may occur simply because a client has
gone away. Before this change that could fill logs with unnecessary
stack traces.

After this change we make a best effort to identify such network
failures, on a per-server basis (tested with Jetty, Tomcat, Glassfish,
and WildFly), and log them under a separate log category.

A simple one-line message is logged at DEBUG level (i.e. no stack trace)
while a full stack trace is shown at TRACE level.

Issue: SPR-11438
2014-03-01 14:46:44 -05:00
Rossen Stoyanchev 6016536055 Remove ContentTypeResolver from composite converter
Before this change CompositeMessageConverter had a ContentTypeResolver
field that was in turn set on all contained converters.

After this change that field is removed and effectively
CompositeMessageConverter is a simple container of other converters.
Each converter in turn must have been configured with a
ContentTypeResolver.

Doing so means it is less likely to have unexpected consequences when
configuring converters, the ContentTypeResolver set in the composite
converter overriding the one configured in a contained converter.

Also commit 676ce6 added default ContentTypeResolver initialization
to AbstractMessageConverter, which ensures that converters are still
straight forward to configure.

Issue: SPR-11462
2014-02-27 21:41:35 -05:00
Rossen Stoyanchev 32e5f57e64 Ensure matching user destination returned
Before this change, when a client subscribed to a "user" destination
(e.g. /user/foo), actual messages received in response to that
subscription contained the server-translated, unique user destination
(e.g. /foo-user123).

This is not an issue for clients such as stomp.js since the
subscription is unique and sufficient to match subscription responses.
However, other STOMP clients do additional checks on the destination
of the subscription and the response.

This change ensures that messages sent to clients on user destionations
always contain a destination that matches the one on the original
subscription.

Issue: SPR-11423
2014-02-13 16:38:56 -05:00
Rossen Stoyanchev dfe2234781 Upgrade to Undertow 1.0 Final (WildFly 8 Final) 2014-02-12 11:06:51 -05:00
Rossen Stoyanchev 1c4530f251 Re-enable Undertow tests in WebSocketConfigurationIT 2014-01-22 14:50:25 -05:00
Rossen Stoyanchev 8ee2a2d18c Remove unused constructor arg from UserDestinationMH 2014-01-22 11:55:44 -05:00
Rossen Stoyanchev 0db2f79bdb Polish message method handling tests 2014-01-22 11:29:38 -05:00
Sam Brannen 597ef099d0 Suppress warnings and remove unused imports 2014-01-22 12:23:32 +01:00
Juergen Hoeller 12c393eb6d Switched 'order' attributes across namespaces to 'xsd:token'
Issue: SPR-10886
Issue: SPR-7342
2014-01-22 11:35:21 +01:00
Juergen Hoeller 3969467851 Temporarily deactivated Undertow integration tests
Undertow tests fail against OpenJDK 8 build 124 with a BindException.
2014-01-22 11:34:27 +01:00
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