Search in sources :

Example 1 with RSocketStrategies

use of org.springframework.messaging.rsocket.RSocketStrategies in project spring-boot by spring-projects.

the class RSocketStrategiesAutoConfiguration method rSocketStrategies.

@Bean
@ConditionalOnMissingBean
public RSocketStrategies rSocketStrategies(ObjectProvider<RSocketStrategiesCustomizer> customizers) {
    RSocketStrategies.Builder builder = RSocketStrategies.builder();
    if (ClassUtils.isPresent(PATHPATTERN_ROUTEMATCHER_CLASS, null)) {
        builder.routeMatcher(new PathPatternRouteMatcher());
    }
    customizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
    return builder.build();
}
Also used : PathPatternRouteMatcher(org.springframework.web.util.pattern.PathPatternRouteMatcher) RSocketStrategies(org.springframework.messaging.rsocket.RSocketStrategies) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with RSocketStrategies

use of org.springframework.messaging.rsocket.RSocketStrategies in project spring-boot by spring-projects.

the class RSocketStrategiesAutoConfigurationTests method shouldUseStrategiesCustomizer.

@Test
void shouldUseStrategiesCustomizer() {
    this.contextRunner.withUserConfiguration(StrategiesCustomizer.class).run((context) -> {
        assertThat(context).getBeans(RSocketStrategies.class).hasSize(1);
        RSocketStrategies strategies = context.getBean(RSocketStrategies.class);
        assertThat(strategies.decoders()).hasAtLeastOneElementOfType(CustomDecoder.class);
        assertThat(strategies.encoders()).hasAtLeastOneElementOfType(CustomEncoder.class);
    });
}
Also used : RSocketStrategiesCustomizer(org.springframework.boot.rsocket.messaging.RSocketStrategiesCustomizer) RSocketStrategies(org.springframework.messaging.rsocket.RSocketStrategies) Test(org.junit.jupiter.api.Test)

Example 3 with RSocketStrategies

use of org.springframework.messaging.rsocket.RSocketStrategies in project spring-framework by spring-projects.

the class RSocketMessageHandlerTests method getRSocketStrategiesReflectsCurrentState.

@Test
public void getRSocketStrategiesReflectsCurrentState() {
    RSocketMessageHandler handler = new RSocketMessageHandler();
    // 1. Set properties
    handler.setDecoders(Collections.singletonList(new ByteArrayDecoder()));
    handler.setEncoders(Collections.singletonList(new ByteArrayEncoder()));
    handler.setRouteMatcher(new SimpleRouteMatcher(new AntPathMatcher()));
    handler.setMetadataExtractor(new DefaultMetadataExtractor());
    handler.setReactiveAdapterRegistry(new ReactiveAdapterRegistry());
    RSocketStrategies strategies = handler.getRSocketStrategies();
    assertThat(strategies.encoders()).isEqualTo(handler.getEncoders());
    assertThat(strategies.decoders()).isEqualTo(handler.getDecoders());
    assertThat(strategies.routeMatcher()).isSameAs(handler.getRouteMatcher());
    assertThat(strategies.metadataExtractor()).isSameAs(handler.getMetadataExtractor());
    assertThat(strategies.reactiveAdapterRegistry()).isSameAs(handler.getReactiveAdapterRegistry());
    // 2. Set properties again
    handler.setDecoders(Collections.singletonList(StringDecoder.allMimeTypes()));
    handler.setEncoders(Collections.singletonList(CharSequenceEncoder.allMimeTypes()));
    handler.setRouteMatcher(new SimpleRouteMatcher(new AntPathMatcher()));
    handler.setMetadataExtractor(new DefaultMetadataExtractor());
    handler.setReactiveAdapterRegistry(new ReactiveAdapterRegistry());
    handler.afterPropertiesSet();
    strategies = handler.getRSocketStrategies();
    assertThat(strategies.encoders()).isEqualTo(handler.getEncoders());
    assertThat(strategies.decoders()).isEqualTo(handler.getDecoders());
    assertThat(strategies.routeMatcher()).isSameAs(handler.getRouteMatcher());
    assertThat(strategies.metadataExtractor()).isSameAs(handler.getMetadataExtractor());
    assertThat(strategies.reactiveAdapterRegistry()).isSameAs(handler.getReactiveAdapterRegistry());
}
Also used : ByteArrayEncoder(org.springframework.core.codec.ByteArrayEncoder) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) RSocketStrategies(org.springframework.messaging.rsocket.RSocketStrategies) DefaultMetadataExtractor(org.springframework.messaging.rsocket.DefaultMetadataExtractor) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) Test(org.junit.jupiter.api.Test)

Example 4 with RSocketStrategies

use of org.springframework.messaging.rsocket.RSocketStrategies in project spring-framework by spring-projects.

the class RSocketMessageHandlerTests method getRSocketStrategies.

@Test
public void getRSocketStrategies() {
    RSocketMessageHandler handler = new RSocketMessageHandler();
    handler.setDecoders(Collections.singletonList(new ByteArrayDecoder()));
    handler.setEncoders(Collections.singletonList(new ByteArrayEncoder()));
    handler.setRouteMatcher(new SimpleRouteMatcher(new AntPathMatcher()));
    handler.setMetadataExtractor(new DefaultMetadataExtractor());
    handler.setReactiveAdapterRegistry(new ReactiveAdapterRegistry());
    RSocketStrategies strategies = handler.getRSocketStrategies();
    assertThat(strategies).isNotNull();
    assertThat(strategies.encoders()).isEqualTo(handler.getEncoders());
    assertThat(strategies.decoders()).isEqualTo(handler.getDecoders());
    assertThat(strategies.routeMatcher()).isSameAs(handler.getRouteMatcher());
    assertThat(strategies.metadataExtractor()).isSameAs(handler.getMetadataExtractor());
    assertThat(strategies.reactiveAdapterRegistry()).isSameAs(handler.getReactiveAdapterRegistry());
}
Also used : ByteArrayEncoder(org.springframework.core.codec.ByteArrayEncoder) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) RSocketStrategies(org.springframework.messaging.rsocket.RSocketStrategies) DefaultMetadataExtractor(org.springframework.messaging.rsocket.DefaultMetadataExtractor) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) Test(org.junit.jupiter.api.Test)

Example 5 with RSocketStrategies

use of org.springframework.messaging.rsocket.RSocketStrategies in project spring-boot by spring-projects.

the class RSocketStrategiesAutoConfigurationTests method shouldCreateDefaultBeans.

@Test
void shouldCreateDefaultBeans() {
    this.contextRunner.run((context) -> {
        assertThat(context).getBeans(RSocketStrategies.class).hasSize(1);
        RSocketStrategies strategies = context.getBean(RSocketStrategies.class);
        assertThat(strategies.decoders()).hasAtLeastOneElementOfType(Jackson2CborDecoder.class).hasAtLeastOneElementOfType(Jackson2JsonDecoder.class);
        assertThat(strategies.encoders()).hasAtLeastOneElementOfType(Jackson2CborEncoder.class).hasAtLeastOneElementOfType(Jackson2JsonEncoder.class);
        assertThat(strategies.routeMatcher()).isInstanceOf(PathPatternRouteMatcher.class);
    });
}
Also used : Jackson2CborEncoder(org.springframework.http.codec.cbor.Jackson2CborEncoder) RSocketStrategies(org.springframework.messaging.rsocket.RSocketStrategies) Jackson2CborDecoder(org.springframework.http.codec.cbor.Jackson2CborDecoder) Test(org.junit.jupiter.api.Test)

Aggregations

RSocketStrategies (org.springframework.messaging.rsocket.RSocketStrategies)6 Test (org.junit.jupiter.api.Test)5 ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)3 ByteArrayDecoder (org.springframework.core.codec.ByteArrayDecoder)3 ByteArrayEncoder (org.springframework.core.codec.ByteArrayEncoder)3 DefaultMetadataExtractor (org.springframework.messaging.rsocket.DefaultMetadataExtractor)3 AntPathMatcher (org.springframework.util.AntPathMatcher)3 SimpleRouteMatcher (org.springframework.util.SimpleRouteMatcher)3 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 RSocketStrategiesCustomizer (org.springframework.boot.rsocket.messaging.RSocketStrategiesCustomizer)1 Bean (org.springframework.context.annotation.Bean)1 Jackson2CborDecoder (org.springframework.http.codec.cbor.Jackson2CborDecoder)1 Jackson2CborEncoder (org.springframework.http.codec.cbor.Jackson2CborEncoder)1 PathPatternRouteMatcher (org.springframework.web.util.pattern.PathPatternRouteMatcher)1