Search in sources :

Example 1 with SimpleRouteMatcher

use of org.springframework.util.SimpleRouteMatcher in project spring-framework by spring-projects.

the class MessageMappingMessageHandler method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    // Initialize RouteMatcher before parent initializes handler mappings
    if (this.routeMatcher == null) {
        AntPathMatcher pathMatcher = new AntPathMatcher();
        pathMatcher.setPathSeparator(".");
        this.routeMatcher = new SimpleRouteMatcher(pathMatcher);
    }
    super.afterPropertiesSet();
}
Also used : AntPathMatcher(org.springframework.util.AntPathMatcher) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher)

Example 2 with SimpleRouteMatcher

use of org.springframework.util.SimpleRouteMatcher in project spring-framework by spring-projects.

the class MessageMappingMessageHandlerTests method message.

private Message<?> message(String destination, String... content) {
    Flux<DataBuffer> payload = Flux.fromIterable(Arrays.asList(content)).map(this::toDataBuffer);
    MessageHeaderAccessor headers = new MessageHeaderAccessor();
    headers.setLeaveMutable(true);
    headers.setHeader(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, new SimpleRouteMatcher(new AntPathMatcher()).parseRoute(destination));
    return MessageBuilder.createMessage(payload, headers.getMessageHeaders());
}
Also used : MessageHeaderAccessor(org.springframework.messaging.support.MessageHeaderAccessor) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) DataBuffer(org.springframework.core.io.buffer.DataBuffer)

Example 3 with SimpleRouteMatcher

use of org.springframework.util.SimpleRouteMatcher in project spring-framework by spring-projects.

the class MessageMappingMessageHandlerTests method unhandledExceptionShouldFlowThrough.

@Test
public void unhandledExceptionShouldFlowThrough() {
    GenericMessage<?> message = new GenericMessage<>(new Object(), Collections.singletonMap(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, new SimpleRouteMatcher(new AntPathMatcher()).parseRoute("string")));
    StepVerifier.create(initMesssageHandler().handleMessage(message)).expectErrorSatisfies(ex -> assertThat(ex.getMessage().startsWith("Could not resolve method parameter at index 0")).as("Actual: " + ex.getMessage()).isTrue()).verify(Duration.ofSeconds(5));
}
Also used : CharSequenceEncoder(org.springframework.core.codec.CharSequenceEncoder) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Decoder(org.springframework.core.codec.Decoder) PropertySource(org.springframework.core.env.PropertySource) DefaultDataBufferFactory(org.springframework.core.io.buffer.DefaultDataBufferFactory) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DestinationVariable(org.springframework.messaging.handler.annotation.DestinationVariable) DestinationPatternsMessageCondition(org.springframework.messaging.handler.DestinationPatternsMessageCondition) Controller(org.springframework.stereotype.Controller) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) Duration(java.time.Duration) Message(org.springframework.messaging.Message) AntPathMatcher(org.springframework.util.AntPathMatcher) Encoder(org.springframework.core.codec.Encoder) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) TestEncoderMethodReturnValueHandler(org.springframework.messaging.handler.invocation.reactive.TestEncoderMethodReturnValueHandler) MessageHeaderAccessor(org.springframework.messaging.support.MessageHeaderAccessor) StringDecoder(org.springframework.core.codec.StringDecoder) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Mono(reactor.core.publisher.Mono) DataBuffer(org.springframework.core.io.buffer.DataBuffer) MessageMapping(org.springframework.messaging.handler.annotation.MessageMapping) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) List(java.util.List) MapPropertySource(org.springframework.core.env.MapPropertySource) MessageExceptionHandler(org.springframework.messaging.handler.annotation.MessageExceptionHandler) GenericMessage(org.springframework.messaging.support.GenericMessage) Collections(java.util.Collections) MessageBuilder(org.springframework.messaging.support.MessageBuilder) EmbeddedValueResolver(org.springframework.beans.factory.config.EmbeddedValueResolver) GenericMessage(org.springframework.messaging.support.GenericMessage) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) Test(org.junit.jupiter.api.Test)

Example 4 with SimpleRouteMatcher

use of org.springframework.util.SimpleRouteMatcher in project spring-framework by spring-projects.

the class MethodMessageHandlerTests method bestMatch.

@Test
@SuppressWarnings("unchecked")
public void bestMatch() throws NoSuchMethodException {
    TestMethodMessageHandler handler = new TestMethodMessageHandler();
    TestController controller = new TestController();
    handler.registerHandlerMethod(controller, TestController.class.getMethod("handleMessageMatch1"), "/bestmatch/{foo}/path");
    handler.registerHandlerMethod(controller, TestController.class.getMethod("handleMessageMatch2"), "/bestmatch/*/*");
    handler.afterPropertiesSet();
    Message<?> message = new GenericMessage<>("body", Collections.singletonMap(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, new SimpleRouteMatcher(new AntPathMatcher()).parseRoute("/bestmatch/bar/path")));
    handler.handleMessage(message).block(Duration.ofSeconds(5));
    StepVerifier.create((Publisher<Object>) handler.getLastReturnValue()).expectNext("handleMessageMatch1").verifyComplete();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) Test(org.junit.jupiter.api.Test)

Example 5 with SimpleRouteMatcher

use of org.springframework.util.SimpleRouteMatcher in project spring-framework by spring-projects.

the class MethodMessageHandlerTests method argumentResolution.

@Test
@SuppressWarnings("unchecked")
public void argumentResolution() {
    ArgumentResolverConfigurer configurer = new ArgumentResolverConfigurer();
    configurer.addCustomResolver(new StubArgumentResolver(String.class, "foo"));
    TestMethodMessageHandler handler = initMethodMessageHandler(theHandler -> theHandler.setArgumentResolverConfigurer(configurer), TestController.class);
    Message<?> message = new GenericMessage<>("body", Collections.singletonMap(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, new SimpleRouteMatcher(new AntPathMatcher()).parseRoute("/handleMessageWithArgument")));
    handler.handleMessage(message).block(Duration.ofSeconds(5));
    StepVerifier.create((Publisher<Object>) handler.getLastReturnValue()).expectNext("handleMessageWithArgument,payload=foo").verifyComplete();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) Test(org.junit.jupiter.api.Test)

Aggregations

AntPathMatcher (org.springframework.util.AntPathMatcher)11 SimpleRouteMatcher (org.springframework.util.SimpleRouteMatcher)11 Test (org.junit.jupiter.api.Test)8 ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)5 ByteArrayDecoder (org.springframework.core.codec.ByteArrayDecoder)4 ByteArrayEncoder (org.springframework.core.codec.ByteArrayEncoder)4 GenericMessage (org.springframework.messaging.support.GenericMessage)4 DefaultMetadataExtractor (org.springframework.messaging.rsocket.DefaultMetadataExtractor)3 RSocketStrategies (org.springframework.messaging.rsocket.RSocketStrategies)3 MessageHeaderAccessor (org.springframework.messaging.support.MessageHeaderAccessor)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 CharSequenceEncoder (org.springframework.core.codec.CharSequenceEncoder)2 StringDecoder (org.springframework.core.codec.StringDecoder)2 DataBuffer (org.springframework.core.io.buffer.DataBuffer)2 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 Duration (java.time.Duration)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1