Commit Graph

1188 Commits

Author SHA1 Message Date
Rossen Stoyanchev c879796e00 Add cache limit to DefaultSessionRegistry and polish
Issue: SPR-11657
2014-04-29 18:16:09 -04:00
Sebastien Deleuze 1054080b24 Fix DefaultSubscriptionRegistry when using pattern destinations
DestinationCache is now used for both plain and pattern
destinations. It stores internally the subscriptions map for each
cached destination. Subscriptions are initially created when there
is no cache for the requested destination, and are updated when
subscriptions change.

Issue: SPR-11657
2014-04-29 18:16:09 -04:00
Rossen Stoyanchev 58adc150c9 Fix STOMP broker relay int test issue
Avoid dependency on order in which expected messages are received.
2014-04-29 17:17:10 -04:00
Rossen Stoyanchev 56d26443e2 Fix one more issue in STOMP broker relay int test 2014-04-29 16:36:43 -04:00
Rossen Stoyanchev 13be6d2321 Fix issue in STOMP broker relay integration test 2014-04-29 15:48:39 -04:00
Rossen Stoyanchev 01fe2923ee Simplify STOMP broker relay integration test
This change simplifies the implementation of the "test" EventPublisher
and MessageHandler used in the STOMP broker relay integration tests.
The updated implementations use a time-limted poll on a BlockingQueue.
2014-04-29 13:22:23 -04: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 bded025d9f @SendTo support for jms listener endpoints
This commit replaces the "responseDestination" attribute on the
JmsListener annotation by a support of the standard SendTo annotation.

Issue: SPR-11707
2014-04-24 15:33:24 +03:00
Rossen Stoyanchev 08f0395033 Rename Reactor support classes
This change modifies the names of the Reactor support classes in order
to align with the same changes in the 4.0.x line which now supports
both Reactor 1.1 and 1.0.

Issue: SPR-11636
2014-04-23 23:46:43 -04:00
Stephane Nicoll 5559209233 Remove useless imports 2014-04-22 09:57:12 +02:00
Philippe Marschall eb5f397a39 Clean up spring-messaging imports
spring-messaging is full of unused imports. This commit removes all
unused imports from spring-messaging.
2014-04-22 07:28:10 +02:00
Juergen Hoeller 086f1eda71 Polishing 2014-04-17 22:39:47 +02:00
Juergen Hoeller 28887750b0 MessageConversionException offers constructor without cause argument now, plus related polishing
Issue: SPR-11653
2014-04-17 21:19:37 +02:00
Stephane Nicoll 713dd60fa7 JMS annotation-driven endpoints.
This commit adds the support of JMS annotated endpoint. Can be
activated both by @EnableJms or <jms:annotation-driven/> and
detects methods of managed beans annotated with @JmsListener,
either directly or through a meta-annotation.

Containers are created and managed under the cover by a registry
at application startup time. Container creation is delegated to a
JmsListenerContainerFactory that is identified by the containerFactory
attribute of the JmsListener annotation. Containers can be
retrieved from the registry using a custom id that can be specified
directly on the annotation.

A "factory-id" attribute is available on the container element of
the XML namespace. When it is present, the configuration defined at
the namespace level is used to build a JmsListenerContainerFactory
that is exposed with the value of the "factory-id" attribute. This can
be used as a smooth migration path for users having listener containers
defined at the namespace level. It is also possible to migrate all
listeners to annotated endpoints and yet keep the
<jms:listener-container> or <jms:jca-listener-container> element to
share the container configuration.

The configuration can be fine-tuned by implementing the
JmsListenerConfigurer interface which gives access to the registrar
used to register endpoints. This includes a programmatic registration
of endpoints in complement to the declarative approach. A default
JmsListenerContainerFactory can also be specified to be used if no
containerFactory has been set on the annotation.

Annotated methods can have flexible method arguments that are similar
to what @MessageMapping provides. In particular, jms listener endpoint
methods can fully use the messaging abstraction, including convenient
header accessors. It is also possible to inject the raw
javax.jms.Message and the Session for more advanced use cases. The
payload can be injected as long as the conversion service is able to
convert it from the original type of the JMS payload. By
default, a DefaultJmsHandlerMethodFactory is used but it can be
configured further to support additional method arguments or to
customize conversion and validation support.

The return type of an annotated method can also be an instance of
Spring's Message abstraction. Instead of just converting the payload,
such response type allows to communicate standard and custom headers.

The JmsHeaderMapper infrastructure from Spring integration has also
been migrated to the Spring framework. SimpleJmsHeaderMapper is based
on SI's DefaultJmsHeaderMapper. The simple implementation maps all
JMS headers so that the generated Message abstraction has all the
information stored in the protocol specific message.

Issue: SPR-9882
2014-04-17 09:16:06 +02:00
Rossen Stoyanchev 6cb9a144db Expand static resource handling mechanism
An initial commit with expanded support for static resource handling:

- Add ResourceResolver strategy for resolving a request to a Resource
  along with a few implementations.

- Add PublicResourceUrlProvider to get URLs for client-side use.

- Add ResourceUrlEncodingFilter and
  PublicResourceUrlProviderExposingInterceptor along with initial
  MVC Java config support.

Issue: SPR-10933
2014-04-16 23:42:44 -04:00
Rossen Stoyanchev 4e1781ae8c Use strategy for customizing ID/TIMESTAMP generation
Issue: SPR-11468
2014-04-14 21:03:13 -04:00
Rossen Stoyanchev 95e25d4e6f Add strategy for customizing ID/TIMESTAMP headers
Introduce MessageHeaderInitializer strategy for initializing a
MessageHeaderAccessor.

Add IdTimestampMessageHeaderInitializer implementation that provides
control over ID and timestamp header generation.

Disable ID and timestamp by default in SimpMessageHeaderAccessor and
therefore its sub-class StompHeaderAccessor.

Issue: SPR-11468
2014-04-14 13:52:55 -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 fda9c633c4 Support mutable headers in MessagingTemplate
AbstractMessageConverter and messaging template implementations now
detect and use mutable headers if passed in.

The SimpMessagingTemplate is optimized to supporting using a single
MessageHeaders instance while preparing a message.

This commit also updates code using the SimpMessagingTemplate to take
advantage of its new capabilities.

Issue: SPR-11468
2014-04-13 18:43:25 -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 ddf8750511 Update MessageHeaders constructor
Following discussion with Gary.

Issue: SPR-11468
2014-04-04 15:49:53 -04:00
Gary Russell 1eee339c15 Relax constraints in MessageHeaders for subclasses
Allow a subclass to modify MessageHeaders as well as override the
strategy for or even skip having `ID` and `TIMESTAMP` headers.

Issue: SPR-11468
2014-04-04 14:39:09 -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 59703981c4 Upgrade to reactor 1.1.0 snapshots
Issue: SPR-11636
2014-04-01 22:05:10 -04:00
Sam Brannen 89a4c291c3 Remove trailing whitespace 2014-04-01 20:22:25 +02:00
Rossen Stoyanchev 75439c7836 Polish 2014-03-27 20:35:00 -04:00
Rossen Stoyanchev e3ef3fffa5 Optimize STOMP encoding/decoding hotspots 2014-03-27 20:15:53 -04:00
Rossen Stoyanchev d19e30e2f8 Increase log level in spring-messaging tests 2014-03-27 09:21:08 -04:00
Stephane Nicoll c1eb50ef48 polishing 2014-03-25 16:49:54 +01:00
Rossen Stoyanchev 2c1d5efbb0 Introduce base exception class for arg resolution
Issue: SPR-11584
2014-03-25 11:02:24 -04:00
Stephane Nicoll 2aee0d8250 Improve MessageMethodArgumentResolver
This commit validates that the payload type of the message is
assignable to the one declared in the method signature. If that
is not the case, a meaningful exception message is thrown with
the types mismatch.

Prior to this commit, only the Message interface could be defined
in the method signature: it is now possible to define a sub-class
of Message if necessary which will match as long as the Message
parameter is assignable to that type.

Issue: SPR-11584
2014-03-25 10:12:29 -04:00
Rossen Stoyanchev 8780464c64 Update test to catch CI server issue 2014-03-25 08:24:53 -04:00
Rossen Stoyanchev c11484b2e7 Add WebSocket transport configuration support
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
Juergen Hoeller dd7f54c3c0 Revised ResizableByteArrayOutputStream as an actual subclass of ByteArrayOutputStream, and consistently applied appropriate ByteArrayOutputStream initial capacities across the codebase
Issue: SPR-11594
2014-03-24 22:57:38 +01:00
Rossen Stoyanchev 929e9ca401 Raise MessageConversionException in @Payload resolver
If a payload is present but conversion returns null (meaning no
converter knows how to convert), raise a MessageConversionException
that provides information about the type we were trying to convert
to and the message itself whose headers (namely content-type) contain
crucial information required to debug the problem.

Issue: SPR-11577
2014-03-21 08:59:12 -04:00
Rossen Stoyanchev d4782647a4 Ensure default value of @Payload required is enforced
When no @Payload is provided, it is equivalent to @Payload with default
attribute values. Since the default value of required=true, then
an argument that's not annotated is required.
2014-03-20 19:44:19 -04:00
Stephane Nicoll 52c3f713bf Fix handling of required payload.
A payload that is required will now throw an appropriate exception
regardless of if a conversion is required or not.

isEmptyPayload now takes the payload instead of the message
so that both the original payload and the converted payload, if
necessary, share the same logic.

JSR-303 validation is now consistently applied.

Issue: SPR-11577
2014-03-20 16:43:33 -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 1fa4a7d34f Fix minor issue in STOMP broker relay 2014-03-19 10:35:48 -04:00
Rossen Stoyanchev df98490f0d Increase logging for spring-messaging tests
A temporary measure related to intermittent CI build server failures.
2014-03-17 22:32:01 -04:00
Rossen Stoyanchev a372b683cd Use custom config read in ReactorTcpClient
Use a custom ConfigReader to enforce the use of SynchronousDispatcher
and no other dispatchers otherwise created by default. Avoids the
creation thread pools never to be used.
2014-03-17 21:13:14 -04:00
Rossen Stoyanchev 57af56aeeb Improve logging in STOMP broker relay
Ignore DISCONNECT messages if already disconnected. This can occur if
the client explicitly sends a DISCONNECT frame and then closes the
socket quickly. The closing of the WebSocket sessions also sends a
DISCONNECT upstream to ensure the broker is aware.
2014-03-17 17:11:15 -04:00
Rossen Stoyanchev 918e21fd8f Upgrade to reactor 1.0.1.RELEASE 2014-03-17 17:10:53 -04:00
Rossen Stoyanchev f68bd5c8b2 Rename ReactorNettyTcpClient to ReactorTcpClient
Even though Netty is a required dependency of reactor-tcp at present,
there is no hard dependency in the spring-messaging Reactor-based
implementation.
2014-03-16 18:12:45 -04:00
Rossen Stoyanchev 2e13bf8b81 Refine Reactor-based TCP client implementation
Configure explicitly use of SynchronousDispatcher instead of the one
used otherwise by default (RingBufferDispatcher). As a result TCP
optations are now scoped to Netty's threads.

Remove Environment field. It is no longer required to shut it down
since we're now using SynchronousDispatcher by default.

Replace connection.in() with connection.consume() when composing
connection handling. The former creates a Stream for further composing,
e.g. via map(), filter() but all we need is to read a message.

Provide additional constructor that aceepts a pre-configured Reactor
TcpClient instance.

Issue: SPR-11531
2014-03-16 18:12:45 -04: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
Juergen Hoeller 189cd663c5 Polishing 2014-03-15 00:46:06 +01:00
Juergen Hoeller 791f58e6be Polishing 2014-03-13 17:31:39 +01:00
Rossen Stoyanchev 13af188bdc Handle invalid STOMP content-length header value
After this change if a content-length header is provided but is less
than 0 or cannot be parsed as a number, it is ignored and the body
is read sequentially, i.e. until we reach a null byte terminator.

This provides better protection against clients that may set the
content-length header in error.

Issue: SPR-11528
2014-03-10 22:07:39 -04: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 a473d46e1c Tighten connection management in STOMP broker relay
Fix NPE exception when closing TcpConnection

Ensure a ConnectionHandler is cleared when a TcpConnection is closed
(at the same time), logging an exception if the closing fails.

Improve error messages.

Issue: SPR-11531
2014-03-10 16:46:13 -04:00
Sam Brannen 2edff2135f Polish Javadoc for DefaultContentTypeResolver 2014-02-28 15:19:35 +01: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 0da1eefd74 Add default ContentTypeResolver initialization
Previously AbstractMessageConverter did not have a ContentTypeResolver
configured by default. However the Java config and XML namespace in
spring-messaging and spring-websocket always configured one.

This change ensures every AbstractMessageConverter is configured with an
instance of DefaultContentTypeResolver by default. This makes sense since
all the resolver does is make an attempt to find a content type to use
for matching. If it can't it returns null and it's up to the converter
to decide whether it can convert or not.

Issue: SPR-11462
2014-02-27 21:40:53 -05:00
Rossen Stoyanchev 56476cdd5f Add strictContentTypeMatching converter option
AbstractMessageConverter now supports a strictContentTypeMatching mode
in which the content type of a message must be resolved to a (non-null)
value that matches one of the configured supported MIME types in order
for the converter to be used.

Issue: SPR-11463
2014-02-27 15:43:54 -05:00
Sebastien Deleuze 2b69c1f15b Support String contentType headers in spring-messaging
After this change DefaultContentTypeResolver supports String-based
"contentType" header values in addition to MimeType-based.

Issue: SPR-11461
2014-02-27 12:00:50 -05:00
Rossen Stoyanchev b727cdb120 Adjust ActiveMQ settings in integration tests
Before this change tests on the CI server showed the following message:

Store limit is 102400 mb, whilst the data directory:
/opt/.../KahaDB only has 74810 mb of usable space

This change turns off store persistence and also explicitly sets the
limit on memory usage.
2014-02-24 17:07:34 -05:00
Brian Clozel 1dedb67fbc Set virtualHost on StompBrokerRelayRegistration
Prior to this commit, one couldn't set the virtualHost property on
StompBrokerRelayMessageHandler via JavaConfig, since
StompBrokerRelayRegistration's API didn't offer that possibility.

This commit adds a new method in StompBrokerRelayRegistration's fluent
API to set the virtualHost used by StompBrokerRelayMessageHandler.
Note: this property is already configurable via xml config.

Issue: SPR-11433
2014-02-17 14:51:05 +01:00
Juergen Hoeller 14e5a02870 Mixed polishing along with recent changes 2014-02-14 21:39:40 +01:00
Juergen Hoeller 72fe7ebc34 Objects with multi-threaded access should not lazily populate a hash field
Issue. SPR-11428
2014-02-14 20:46:34 +01: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
Juergen Hoeller cead06a3d9 Polishing 2014-02-12 00:12:52 +01:00
Juergen Hoeller 1a1c72ce4b Revised InvocableHandlerMethod exception handling
Issue: SPR-11281
2014-02-11 23:48:10 +01:00
Rossen Stoyanchev 7301b58ec9 Improve info on use of @Controller's with aop proxying
Before this change, issues surrounding the use of @Controller's in
combination with AOP proxying, resulted in an IllegalArgumentException
when trying to invoke the controller method.

This change detects such cases proactively and reports them with a
clear recommendation to use class-based proxying when it comes to
@Controller's. This is the most optimcal approach for controllers
in many respects, also allows @MVC annotations to remain on the
class.

The documentation has also been updated to have a specific section
on @Controller's and AOP proxying providing the same advice.

Issue:SPR-11281
2014-02-11 12:25:54 -05:00
Sam Brannen c335e99e3f Remove trailing whitespace from source code 2014-02-08 17:30:39 +01:00
Juergen Hoeller 919d6ccb3b Actually log the cause of canRead/canWrite failures
Issue: SPR-11403
2014-02-07 17:27:17 +01:00
Rossen Stoyanchev f636ccb5eb Fix failing test 2014-02-05 22:02:59 -05:00
Rossen Stoyanchev 46c0e45130 Improve header processing in SimpMessagingTemplate
Headers provided to the SimpMessagingTemplate's convertAndSend methods
are now automatically moved into the "nativeHeaders" sub-map. This
ensures the headers will go out with the STOMP message and be received
by subscribers.

Issue: SPR-11387
2014-02-05 21:25:35 -05:00
Sam Brannen 67142dcb0a Polish Javadoc in @*ExceptionHandler 2014-02-05 20:15:50 +01:00
Rossen Stoyanchev e6f4796779 Fix failing test 2014-02-01 10:46:51 -05:00
Rossen Stoyanchev da369aa826 Add null check after message conversion
AbstractMessageSendingTemplate now checks if MessageConverter.toMessage
returns null and raises an exception.

Issue: SPR-11370
2014-01-31 21:34:18 -05:00
Rossen Stoyanchev f0a53ae54e Fine-tune default mime type in message broker config
Issue: SPR-11370
2014-01-31 20:55:07 -05:00
Rossen Stoyanchev a106e06a89 Expose failing test in GenericMessagingTemplateTests
Assertions made in callbacks invoked on separate thread were not
reaching the test framework. This fix ensures failures are detected
and cause tests to fail.
2014-01-22 16:43:21 -05:00
Gary Russell 0e7b94f9e9 Add constructors to MessageHandlingException
Issue: SPR-11345
2014-01-22 14:43:35 -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
Brian Clozel db9b6fa28e Split tests for MethodMessageHandlers impl.
Prior to this commit, all MethodMessageHandlers tests were
implemented in a single class. Since SimpAnnotationMsgHandler
has been refactored with an abstract class, tests also
needed such a refactoring.

This commit creates test fixtures for AbstractMethodMessageHandler.

Issue: SPR-11191
2014-01-22 10:42:24 -05:00
Sam Brannen 597ef099d0 Suppress warnings and remove unused imports 2014-01-22 12:23:32 +01:00
Brian Clozel 845a6b0b7d Remove serialVersionUIDs in spring-messaging Exc.
Prior to this commit, several spring-messaging exceptions
had defined serialVersionUIDs. Those exception aren't
supposed to leave the system via Java serialization; also,
their deserialization is supported only against the same
version of Spring.

Issue: SPR-11339
2014-01-22 11:37:04 +01:00
Rossen Stoyanchev d03fb8954b Encode user names in user destanations
Issue: SPR-11302
2014-01-21 14:57:51 -05: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 2cafe9d73a Polish 2014-01-21 12:12:05 -05:00
Phillip Webb 6bb6b6e6b5 Fix warnings in HeaderMethodArgumentResolver 2014-01-20 13:53:17 -08:00
Rossen Stoyanchev 5053fdc8c9 Resolve native header values with @Header
The @Header annotation in spring-messaging now resolves values from the
nested "nativeHeaders" map as well as top-level header map values.

In case of ambiguity (a value that exists in both), the top-level map
value is used and a warning message is printed. This is unlikly in most
cases but can be resolved by prefixing the header value with
"nativeHeadres.myHeader".

Issue: SPR-11326
2014-01-20 16:28:27 -05:00
Rossen Stoyanchev b4e48d6749 Fix issue in DefaultUserDestinationResolver
DefaultUserDestinationResolver now uses the session id of
SUBSCRIBE/UNSUBSCRIBE messages rather than looking up all session id's
associated with a user.

Issue: SPR-11325
2014-01-20 15:41:22 -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 4e933b4765 Polish log messages 2014-01-17 11:03:02 -05:00
Sam Brannen 2dfd69bbb3 Stop using deprecated junit.framework.Assert class 2014-01-14 18:19:06 +01: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 abb8a93e2f Drop separate user dest property for subscriptions
Before this change DefaultUserDestinationResolver provided a separate
destination prefix property for identifying "user" destinations in
subscription requests as opposed to in sent messages. Such a separate
property should not be needed.

Issue: SPR-11263
2014-01-03 16:44:01 -05:00
Brian Clozel b9c8f47b01 Use OptionalValidatorFactoryBean in Configurers
Configurers and BeanDefinitionParsers should use
OptionalValidatorFactoryBean instead of
LocalValidatorFactoryBean.

The Optional implementation catches and logs setup
exceptions, useful when a validation API is present on
the classpath but not the actual implementation.

Issue: SPR-11272
2014-01-03 22:36:56 +01:00
Brian Clozel 15d7d6d7ab Fix Validator initialization with a no-op implementation
Issue: SPR-11185
2014-01-03 16:02:57 +01:00
Brian Clozel 2c8f670d5f Support Validation in @MessageMapping annotated methods
Payload parameters in @MessageMapping annotated
methods can now also be validated when annotated
with a Validation annotation (@Valid, @Validated...).

A default Validator is registered by the MessageBroker
Configurer, but it is possible to provide a list of custom
validators as well.

Issue: SPR-11185
2014-01-03 15:25:33 +01:00
Rossen Stoyanchev 3b14e974f8 Remove unnecessary copying of headers in GenericMessage
Since the MessageHeaders constructor is makes a copy of the headers and
is protected against a null map, there is no need for the same to be
done in GenericMessage.

Issue: SPR-11268
2014-01-02 11:35:31 -05:00
Rossen Stoyanchev 12fe9174f0 Make ObjectMapper configurable in spring-messaging
Issue: SPR-11279
2014-01-02 11:27:18 -05:00
Juergen Hoeller 85921808b3 MappingJackson2(Http)MessageConverter logs warnings after canRead/canWrite checks
This change involves a general upgrade to Jackson 2.3 in our build.

Issue: SPR-11261
2013-12-29 21:50:43 +01:00
Rossen Stoyanchev 4e5e700213 Add client login/passcode to broker relay
Issue: SPR-11154
2013-12-23 21:40:27 -05:00
Rossen Stoyanchev 0a12f28b58 Introduce StompReactorNettyTcpClient
Issue: SPR-11153
2013-12-23 21:40:27 -05:00
Rossen Stoyanchev e637418010 Update stomp/websocket documentation 2013-12-11 23:36:55 -05:00
Rossen Stoyanchev 92dad1849f Rename @[Path/Destination]Variable in spring-messaging
Issue: SPR-11208
2013-12-11 14:44:57 -05:00
Phillip Webb a1529d498e Fix possible GenericMsgTemplate race condition
Fix a potential race condition with GenericMessagingTemplate's inner
TemporaryReplyChannel class.

Prior to this commit the `hasReceived` member variable was read after
calling `replyLatch.countDown()`.

Issue: SPR-11206
2013-12-11 00:08:34 -08:00
Rossen Stoyanchev fcecd0328a Collapse messaging.simp.handler into messaging.simp 2013-12-06 17:23:31 -05: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 7a154e8e98 Renamed handler.support to handler.invocation 2013-12-06 21:50:47 +01: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
Rossen Stoyanchev 947f3d4b2b Update Javadoc, add tests and polish spring-messaging 2013-12-05 21:30:52 -05:00
Rossen Stoyanchev 47ef45d152 Polish websocket xml namespace
Issue: SPR-11063
2013-12-02 15:25:49 -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
Phillip Webb a31ac882c5 Fix various javadoc warnings 2013-11-26 13:25:37 -08:00
Rossen Stoyanchev ce3e55743f Extract IdGenerator into a top-level class 2013-11-25 21:50:47 -05: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
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 35b9b8400b Rename @SubscribeEvent to @SubscribeMapping
Also @SubscribeMapping is now a method-level annotation only that can
be used in combination with a type-level @MessageMapping.

This method also documents supported method arguments and return value
types on @Subscribe- and @MessageMapping methods.
2013-11-15 16:34:27 +00:00
Rossen Stoyanchev 6802f813de Polish STOMP codec
Issue: SPR-11088
2013-11-13 13:45:56 -05:00
Andy Wilkinson e84885c655 Update STOMP decoder to handle incomplete frames
Previously, StompDecoder would throw a StompConversionException when
it attempted to decode a Buffer that contained an incomplete frame.

This commit updates StompDecoder to return null when it encounters an
incomplete frame. It also resets the buffer, thereby allowing the
decode to be reattempted once more data has been received.
StompCodec's decoder function has been updated to stop attempting to
decode a Buffer when StompDecoder returns null.

Issue: SPR-11088
2013-11-13 13:45:12 -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 72dec7d0fe Add default destination for @SendTo methods
Issue: SPR-11085
2013-11-11 16:59:36 -05:00
Rossen Stoyanchev 5915b23e8a Rename method in MessageBrokerConfigurer 2013-11-10 10:47:35 -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 6a18daea33 Return AbstractSubscribableChannel from @Bean methods
Declare SubscribableChannel @Beans in
WebSocketMessageBrokerConfigurationSupport as
AbstractSubscribableChannel to avoid the need for casting when
registering interceptors.

Issue: SPR-11065
2013-11-07 22:28:00 -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
Rossen Stoyanchev c6c5555034 Use final keyword in MessageHeaders 2013-11-05 10:06:35 -05:00
Sam Brannen c3afda3992 Delete unnecessary @SuppressWarnings("unused") 2013-10-31 13:43:38 +01:00
Rossen Stoyanchev a640d84961 Fix issue in AbstractMethodMessageHandler 2013-10-29 21:57:27 -04: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
Sam Brannen bf9ec78c5d Polish spring-messsaging
- Removed unused imports
- Organized imports
- Discontinued use of deprecated junit.framework.Assert class
- Suppressed warnings where appropriate
- Added missing generics to return type for getMappingComparator() in
  SimpAnnotationMethodMessageHandler
2013-10-29 19:29:23 +01: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
Phillip Webb 12e896ed8b Polish 2013-10-25 16:42:47 -07:00
Rossen Stoyanchev b8809daf5f Refactor HandlerMethod support in spring-messaging
Introduce base class AbstractMethodMessageHandler for
HandlerMethod-based message handling.

Add MessageCondition interface for mapping conditions to messages
with support for combining type- and method-level annotation
conditions, the ability to match conditions to messages, and also
comparing matches to select the best match.

Issue: SPR-11024
2013-10-24 21:50:49 -04:00
Rossen Stoyanchev 4892a27016 Add STOMP broker relay unit tests 2013-10-23 16:26:28 -04:00
Rossen Stoyanchev bfa6645c7d Make changes for timing related test failures 2013-10-23 13:24:25 -04:00
Rossen Stoyanchev 2d78a066fb Add ListenableFuture to TcpOperations connect methods 2013-10-23 11:55:43 -04:00
Rossen Stoyanchev f3ca3c108c Switch to reactor snapshots and make use of API change 2013-10-22 22:34:41 -04:00
Rossen Stoyanchev 8917821e95 Polish GenericMessage 2013-10-21 16:29:01 -04:00
Rossen Stoyanchev 92a48b72d7 Polish (minor) 2013-10-21 16:26:07 -04:00
Phillip Webb 59fcf5014f Increase timeout for Stomp integration tests 2013-10-18 16:19:33 -07:00
Rossen Stoyanchev d2eff4ead6 Improve GenericMessage.toString()
Restore pringing the payload first and headers second as it has been in
SI but also handle specifically the case where the body is a byte array
to minimize unnecessary "noise" that causes otherwise for STOMP msgs.
2013-10-18 15:28:59 -04:00
Rossen Stoyanchev 61d13547e1 Remove @UnsubscribeEvent
The STOMP UNSUBSCRIBE message does not have a destination header so
there is no obvious simple way to do a mapping and the need for it
is not clear yet.
2013-10-18 15:15:24 -04:00
Rossen Stoyanchev 715a11ce8c Polish AnnotationMethodMessageHandler and annotations 2013-10-18 15:10:34 -04:00
Brian Clozel fb586da673 Support @PathVariable in annotated message handling methods
Prior to this commit, @SubscribeEvent @UnsubscribeEvent and
@MessageMapping annotated message handling methods
could only match a strict message destination.

This commit adds a @PathVariable annotation and
updates the message matching/handling process, since
message handling methods can now match PathMatcher-like
destinations and get path variables injected in parameters.

Issue: SPR-10949
2013-10-18 15:10:34 -04:00
Rossen Stoyanchev be4e5d2841 Add SimpleMessageConverter 2013-10-18 11:33:59 -04:00
Rossen Stoyanchev a53233b351 Fix issue in AbstractMessagingTemplate 2013-10-17 22:23:03 -04:00
Rossen Stoyanchev 29934d7c02 Add TCP abstractions to spring-messaging
This change adds abstractions for opening and managing TCP connections
primarily for use with the STOMP broker support. As one immediate
benefit the change makes the  StompBrokerRelayMessageHandler more
easy to test.
2013-10-17 22:16:15 -04:00
Rossen Stoyanchev a172b32d4c Refactor STOMP relay session
This change consolidates TCP-related logic in the StompRelaySession. As
a result the sub-class SystemStompRelaySession now contains only logic
intrinsic to the shared system session.
2013-10-17 22:16:14 -04:00
Rossen Stoyanchev 17aea892f0 Fix issue with forwarding messaging to STOMP broker 2013-10-17 22:16:14 -04:00
Rossen Stoyanchev 4e3390ae04 Upgrade to reactor 1.0 RC1 and remove MessageChannel
This change upgrades reactor to 1.0 RC1 and also removes the
reactor-based message channel in favor of the one available from
org.projectreactor:reactor-spring.
2013-10-17 22:15:59 -04:00
Juergen Hoeller 187b681b9e Consistency between InvocableHandlerMethod in web and messaging modules 2013-10-16 01:51:48 +02:00
Rossen Stoyanchev bcfbd862c7 Add value() attribute to @Payload 2013-10-14 22:16:13 -04:00
Rossen Stoyanchev 70dfec269b Use alternative UUID strategy in MessageHeaders
This change adds an alternative UUID generation strategy to use by
default in MessageHeaders. Instead of using SecureRandom for each
new UUID, SecureRandom is used only for the initial seed to be
provided java.util.Random. Thereafter the same Random instance is
used instead. This provides improved performance while id's are
still random but less securely so.
2013-10-14 21:55:13 -04:00
Rossen Stoyanchev 57d127b55a Validate if STOMP frame is allowed to have a body
Issue: SPR-10890
2013-10-14 21:37:44 -04:00
Rossen Stoyanchev 7c3749769a Add STOMP broker relay to configure "host" header
Issue: SPR-10955
2013-10-14 21:06:53 -04:00
Juergen Hoeller 3bd6dfe047 Autowiring of generic types
Includes revisions of MethodParameter and DependencyDescriptor (in particular towards a reference to the containing class). Also refines several ResolvableType method signatures.

Issue: SPR-9965
2013-10-15 00:11:23 +02:00
Rossen Stoyanchev 8ae88c20d1 Add support for resolving message headers
This change adds support for @Header and @Headers annotated method
arguments to spring-messaging. Also supported are arguments of type
MessageHeaders, and MessageHeaderAccessor (including sub-types of
MessageHeaderAccessort as long as they provide a wrap(Message<?>)
static factory method).

This change also renames @MessageBody to @Payload.

Issue: SPR-10985
2013-10-13 11:13:16 -04:00
Rossen Stoyanchev 7d3b6497b5 Add support for MIME-based message conversion
The MessageConverter interface in spring-messaging is now explicitly
designed to support conversion of the payload of a Message<?> to and
from serialized form based on MIME type message header.
By default, the MessageHeaders.CONTENT_HEADER header is used but a
custom ContentTypeResolver can be configured to customize that.

Currently available are Jackson 2, String, and byte array converters.
A CompositeMessageConverter can be used to configure several
message converters in various places such as a messaging template.
2013-10-10 17:25:18 -04:00
Rossen Stoyanchev 824cb9f8cd Polish MessageBuilder 2013-10-07 09:27:04 -04:00
Andy Wilkinson 41e411a8a5 Introduce new HEARTBEAT message type
Previously, there was no generic concept of a message that represents
a heartbeat and the STOMP-specific code used a null STOMP command to
represent a heartbeat.

This commit introduces HEARTBEAT as a new SimpMessageType. The STOMP
support has been updated to create HEARTBEAT messages to represent
heartbeats, and to use the new message type as the mechanism by which
heartbeats are identified.
2013-10-02 16:30:53 -04:00
Andy Wilkinson a7f735b50a Make the broker relay heartbeat intervals configurable
Prior to this commit, the intervals at which the broker relay's system
session would send heartbeats to the STOMP broker and expect to
receive heartbeats from the STOMP broker were hard-coded at 10
seconds.

This commit makes the intervals configurable, with 10 seconds being
the default value.
2013-10-02 16:29:43 -04:00
Andy Wilkinson ba11af7f11 Improve broker relay's shutdown and availability events
Previously, when the broker relay was shut down, the TCP client was
closed and the relay sessions were left to find out about the
shutdown as a result of their TCP connections being closed. This led
to problems where an attempt could be made to use a session that was,
in fact, in the process of being shut down.

This commit updates the broker relay to explicitly close each of its
relay sessions as part of its stop processing.
As part of the broker relay being shut down explicitly close each of
its relay sessions. It does so before closing the TCP client so that
the relay sessions know that they are  disconnected before their TCP
connections are closed.

The broker relay's publishing of availability events has also been
improved. Prior to this commit, availability events were published
based on the availability of any relay session. For example, this
meant that a successfully established client relay session would
result in an event being published indicating that the broker's
available even if the system relay session was yet to be established.
This commit updates the relay so that broker availability events are
only published by the system relay session. This allows application
code the use these events as an accurate indication of the
availability of the broker. Clients that are interested in the
broker's availability can find out through the use of heart beats or
through the receipt of an ERROR frame in response to an attempt to
communnicate with the broker.
2013-10-01 21:04:26 -04:00
Rossen Stoyanchev 6ddacdc01d Fix issue in simple broker with peer-to-peer messages
Issue: SPR-10930
2013-09-30 21:02:51 -04:00
Rossen Stoyanchev 48caeef4de Polish and fix issues in STOMP broker relay
Fix error in te code that handles the result of sending a heartbeat

Fix error in processing DISCONNECTED frames that closed the TCP
connection before the message was sent.
2013-09-30 16:37:18 -04:00
Andy Wilkinson 34dd844716 Polishing
- Polish javadoc for CONNECTED_USER_HEADER
 - Improve method ordering
2013-09-30 14:24:57 -04:00
Andy Wilkinson 5025c304b8 Introduce CONNECT_ACK message type
Previously, handling of a STOMP CONNECT message and sending of a
CONNECTED response was performed by StompProtocolHandler if it was
backed by SimpleBrokerMessageHandler, or left up to the real message
broker if it was backed by StompBrokerRelayMessageHandler. This
wasn't ideal as it should be StompProtocolHandler's job to simply map
messages to and from the STOMP protocol, not to do part of the
broker's job and respond directly to CONNECT.

This commit introduces a new message type, CONNECT_ACK. When it
receives a CONNECT message, SimpleBrokerMessageHandler will now
respond with a CONNECT_ACK message that StompProtocolHandler can map
into a STOMP CONNECTED message. The CONNECT_ACK message contains the
CONNECT message as a header so that StompProtocolHandler has access to
its accept-version header.

StompProtocolHandler has been simplified so that a CONNECT message
is always passed to the output channel, irrespective of whether it's
backed by a simple broker or a real broker. The handleConnect flag,
and the code that would set it correctly depending on the app's
configuration, has been removed.
2013-09-30 14:24:57 -04:00
Andy Wilkinson b2f31a3c74 Improve handling of send failures
Prior to this commit, a failure to send a heartbeat was ignored and a
failure to forward a message to the broker would result in an error
frame being sent but nothing more.

Following this commit, a failure to send a heartbeat to the broker
is treated as a TCP client failure. Furthermore, if the system relay
session fails to forward a message to the broker an exception is
thrown. Typically, the system relay session will be forwarding
messages on behalf of local application code, rather than a remote
WebSocket client. Throwing an exception allows the application code
to be notified of the problem directly, rather than via a broker
availability event.
2013-09-30 14:21:42 -04:00
Rossen Stoyanchev c06ea3b437 Polish logging 2013-09-26 21:27:11 -04:00
Rossen Stoyanchev 469aaa8754 Polish 2013-09-26 16:06:35 -04:00
Andy Wilkinson 6679feb77b Improve handling of missed heartbeats
Previously, when a broker heartbeat was mnissed, the STOMP connection
would be left in a semi-disconnected state such that, for example, the
read and write idle callbacks would still be active, even though
the underlying TCP connection had been nulled out.

As part of disconnecting the STOMP connection, this commit closes the
underlying TCP connection when a heartbeat's missed which cancels the
read and write idle callbacks. It also now copes with the underlying
TCP connection being null when sending a heartbeat to the broker. This
protects again a race condition between the write idle callback being
fired, such that a heartbeat needs to be sent, and the connection
being nulled out due to it being closed.
2013-09-26 16:06:35 -04:00
Andy Wilkinson 496d8321c3 Add heart-beat support to STOMP broker relay
Previously, the STOMP broker relay did not support heart-beats. It sent
0,0 in the heart-beats header for its own CONNECTED message, and set the
heart-beats header to 0,0 when it was forwarding a CONNECTED from from a
client to the broker.

The broker relay now supports heart-beats for the system relay session.
It will send heart-beats at the send interval that's been negotiated
with the broker and will also expect to receive heart-beats at the
receive interval that's been negotiated with the broker. The receive
interval is multiplied by a factor of three to satisfy the STOMP spec's
suggestion of lenience and ActiveMQ 5.8.0's heart-beat behaviour (see
AMQ-4710).

The broker relay also supports heart-beats between clients and the
broker. For any given client's relay session, any heart-beats received
from the client are forwarded on to the broker and any heart-beats
received from the broker are sent back to the client.

Internally, a heart-beat is represented as a Message with a byte array
payload containing the single byte of new line ('\n') character and
'empty' headers. SubscriptionMethodReturnValueHandler has been updated
to default the message type to SimpMessageType.MESSAGE. This eases
the distinction between a heartbeat and a message that's been created
from a return value from application code.
2013-09-26 16:06:35 -04:00
Andy Wilkinson 8d2a376b0f Remove CONNECT-related message buffer from STOMP relay
Before this change, the StompProtocolHandler always responded to
clients with a CONNECTED frame, while the STOMP broker relay
independantly forwarded the client CONNECT to the broker and waited
for the CONNECTED frame back. That meant the relay had to buffer
client messages until it received the CONNECTED response from
the message broker.

This change ensures that clients wait for a CONNECTED frame from
the message broker. The broker relay forwards the CONNECT frame to
the broker. The broker responds with a CONNECTED frame, which the
relay then forwards to the client. As a result, a (well-written)
client will not send any messages to the relay until the connection
to the broker is fully established.

The StompProtcolHandler can now be configured whether to send CONNECTED
frame back. By default that is off. So when using the simple broker,
the StompProtocolHandler can still respond with CONNECTED frames.

The relay's handling of a connection being dropped has also been
improved. When a connection for a client relay session is dropped
an ERROR frame will be sent back to the client. If a connection is
closed as part of a DISCONNECT frame being sent, no ERROR frame
is sent back to the client. When the connection for the system relay
session is dropped, an event is published indicating that the broker
is unavailable. Reactor's TcpClient will then attempt to re-restablish
the connection.
2013-09-26 16:06:35 -04:00
Andy Wilkinson a489c2cf38 Add StompCodec
Previously, the broker relay's TCP client used Reactor's built in
delimited codec as part of its parsing of STOMP frames. \0 was used as
the delimiter. This worked for most STOMP frames but, crucially,
not for frames with a body that contained \0: when such a frame was
received it would be truncated.

This commit adds a custom codec that parses STOMP frames more
intelligently. It honours the content-length header allowing it to
correctly parse frames with a body that contains \0. The codec largely
delegates to two new classes: StompEncoder and StompDecoder. For
consistency, code that previously used StompMessageConverter has been
reworked to use these new encoder and decoder classes.

Issue: SPR-10818
2013-09-26 16:06:34 -04:00
Rossen Stoyanchev 45eab23e15 Rename @ReplyTo to @SendTo 2013-09-08 21:22:53 -04:00
Sam Brannen 41fa15a484 Polish Javadoc for messaging annotations 2013-09-07 22:07:09 +02:00
Rossen Stoyanchev 62921683fd Introduce ListenableFuture to WebSocketClient
Issue: SPR-10888
2013-09-06 12:28:21 -04:00
Rossen Stoyanchev 71e76196fe Polish StompProtocolHandler 2013-09-05 21:40:15 -04:00
Rossen Stoyanchev 1c47c8f35c Remove TODOs (replaced with JIRA tickets)
Issue: SPR-10703
2013-09-03 23:29:20 -04:00
Juergen Hoeller 8a4c6eb605 Fixed accidental use of Reactor's Assert util
Issue: SPR-10880
2013-09-03 23:56:43 +02:00
Rossen Stoyanchev 30d2f783a7 Modify return type of subProtocolWebSocketHandler bean
The @Bean method now returns WebSocketHandler allowing it to be
decorated via WebSocketHandlerDecorator.
2013-09-03 15:26:47 -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 cbdb99c042 Add basic javadoc to spring-messaging annotations 2013-08-29 14:09:52 -04:00
Rossen Stoyanchev 39ff1e2c53 Add StompProtocolHandler tests 2013-08-29 09:58:41 -04:00
Andy Wilkinson 364bc35709 Use correct header for version in CONNECTED frame
Previously, the negotiated version was included in the CONNECTED frame
using the accept-version header. This is incorrect. The version
header should be used.
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 4b2847d9d1 Add ChannelInterceptor to spring-messaging module
Issue: SPR-10866
2013-08-28 14:41:20 -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 750930fa25 Fix bug with the order of messaging arg resolvers 2013-08-27 15:05:34 -04:00
Rossen Stoyanchev 402a3b8473 Fix javadoc 2013-08-27 12:48:48 -04:00
Jan Machacek 3f130a1c08 Add support for custom types in AMMH 2013-08-27 12:43:21 -04:00
Rossen Stoyanchev 68c0df8305 Polish StompBrokerRelayMessageHandler 2013-08-19 21:16:00 -04:00
Rossen Stoyanchev 94fefec0f9 Add ActiveMQ-based STOMP relay integration tests 2013-08-19 21:16:00 -04:00
Andy Wilkinson 3fb5ff2654 Improve broker availability events
Use a single class for the broker availability event with a boolean
that indicates whether or not the broker is available, rather than one
event for an available broker and one event for an unavailable broker.

Publish broker availability events in SimpleBrokerMessageHandler so that
it can be used as a drop-in replacement for
StompBrokerRelayMessageHandler.
2013-08-19 21:16:00 -04:00
Andy Wilkinson 131b5de6f9 Add reconnect logic to the relay's system session
Upgrade to Reactor snapshot builds to take advantage of TcpClient's
reconnect support that was added post-M1. Now, the system relay session
will try every 5 seconds to establish a connection with the broker, both
when first connecting and in the event of subsequently becoming
disconnected.

A more sophisticated reconnection policy, including back off and
failover to different brokers, is possible with the Reactor API. We may
want to enhance the relay's reconnection policy in the future.

Typically, a broken connection is identified by the failure to forward
a message to the broker. As things stand, the message id then discarded.
Any further messages that are forwarded before the connection's been
re-established are queued for forwarding once the CONNECTED frame's been
received. We may want to consider also queueing the message that failed
to send, however we would then need to consider the possibility of the
message itself being what caused the broker to close the connection
and resending it would simply cause the connection to be closed again.
2013-08-19 21:15:59 -04:00
Andy Wilkinson 8b48d8f445 Publish events about broker's availability
Components that are using a StompBrokerRelayMessageHandler may want
to know whether or not the broker's unavailable. If they're sending
messages to the relay via an asynchronous channel there's currently
no way for them to find this out.

This commit enhances StompBrokerRelayMessageHandler to publish
application events when the broker's availability changes:
BrokerBecameAvailableEvent and BrokerBecameUnavailableEvent.
Irrespective of the number of relay sessions only a single event is
published for each change in the broker's availability.
2013-08-19 21:15:59 -04:00
Andy Wilkinson be6dbe54a3 Integration tests for the broker relay 2013-08-19 21:15:59 -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 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
Andy Wilkinson 4390591b68 Make BeanFactoryMCDR BeanFactoryAware
SI's BeanFactoryChannelResolver was BeanFactoryAware. This commit
brings Spring's BeanFactoryMessageChannelDestinationResolver in line
with the old SI class.
2013-07-24 16:45:52 -04:00
Rossen Stoyanchev 02949fc4a7 Fix failing tests 2013-07-21 20:39:07 -04:00
Rossen Stoyanchev b3c7c18c1b Add MessageHandler destination prefix checks 2013-07-21 12:07:50 -04:00
Rossen Stoyanchev 2cdac267f7 Add MessageMethodArumentResolver 2013-07-21 12:07:50 -04:00
Rossen Stoyanchev 90c4712d06 Revise UserSessionResolver to UserQueueSuffixResolver
The resolver for /user/{username} prefixed destinations is now
more explicitly designed to store queue suffixes rather than session
id's, which is what we happen to use as queue suffixes.

This allows something other than the sessionId to be used without
having to change many places. It also enables applications to
construct destinations with user-specific queue suffixes without
making assumptions about what's used for queue suffixes. For
example a controller may construct a map with subscription destinations
and send that down to the client.
2013-07-19 17:22:58 -04:00
Rossen Stoyanchev 3272917cf2 Polish concurrency in UserSessionResolver impl 2013-07-19 10:57:23 -04:00
Rossen Stoyanchev aa6f30482f Reverse change committed erroneously 2013-07-17 23:00:17 -04:00
Rossen Stoyanchev a109d6adc7 Set heartbeat to 0,0 on CONNECT to message broker 2013-07-17 22:40:44 -04:00
Rossen Stoyanchev 8a8501a992 Polish 2013-07-17 18:23:27 -04:00
Rossen Stoyanchev 329fbf31bc Fix concurrency issue in DefaultSubscriptionRegistry 2013-07-17 18:16:39 -04:00
Rossen Stoyanchev d73c2e26a5 Polish handling of STOMP message headers 2013-07-17 13:58:45 -04:00
Rossen Stoyanchev ba7998d03b Add SimpMessageSendingOperations 2013-07-17 10:09:55 -04:00
Rossen Stoyanchev 078cfb3e78 Add @ReplyTo/@ReplyToUser, remove deps on spring-web 2013-07-16 22:07:46 -04:00
Rossen Stoyanchev 55dae74f15 Add ReplyTo annotation 2013-07-16 10:24:45 -04:00
Rossen Stoyanchev e0d393eed3 Fix issue in STOMP broker relay 2013-07-15 17:45:54 -04:00
Rossen Stoyanchev 5d20b75dc2 Add support for sending private messages
The new UserDestinationMessageHandler resolves messages with
destinations prefixed with "/user/{username}" and resolves them into a
destination to which the user is currently subscribed by appending the
user session id.

For example a destination such as "/user/john/queue/trade-confirmation"
would resolve "/trade-confirmation/i9oqdfzo" assuming "i9oqdfzo" is the
user's session id.
2013-07-14 21:10:15 -04:00
Rossen Stoyanchev 2a48ad88fb Refactor and polish spring-messaging
Remove base class for STOMP-related message handler classes
(AbstractSimpMessageHandler), polish subclasses and fix issues with
more significant updates to STOMP broker relay.

Introduce base class for SubscribableChannel implementations providing
consistent logging for all channel implementations.
2013-07-13 19:05:32 -04:00
Rossen Stoyanchev f5f3f66b13 Add user-name header to CONNECTED frame 2013-07-12 19:42:31 -04:00
Rossen Stoyanchev bd68fefc6f Fix issue with clearing subscriptions on disconnect 2013-07-12 15:30:12 -04:00
Rossen Stoyanchev 210be9cde4 Add PrincipalMessageArgumentResolver 2013-07-12 15:15:37 -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