Search in sources :

Example 1 with DefaultMetadataExtractor

use of org.springframework.messaging.rsocket.DefaultMetadataExtractor in project spring-security by spring-projects.

the class BasicAuthenticationPayloadExchangeConverter method createDefaultExtractor.

private static MetadataExtractor createDefaultExtractor() {
    DefaultMetadataExtractor result = new DefaultMetadataExtractor(new BasicAuthenticationDecoder());
    result.metadataToExtract(UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE, UsernamePasswordMetadata.class, (String) null);
    return result;
}
Also used : DefaultMetadataExtractor(org.springframework.messaging.rsocket.DefaultMetadataExtractor) BasicAuthenticationDecoder(org.springframework.security.rsocket.metadata.BasicAuthenticationDecoder)

Example 2 with DefaultMetadataExtractor

use of org.springframework.messaging.rsocket.DefaultMetadataExtractor 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 3 with DefaultMetadataExtractor

use of org.springframework.messaging.rsocket.DefaultMetadataExtractor 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 4 with DefaultMetadataExtractor

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

the class RSocketMessageHandlerTests method metadataExtractorWithExplicitlySetDecoders.

@Test
public void metadataExtractorWithExplicitlySetDecoders() {
    DefaultMetadataExtractor extractor = new DefaultMetadataExtractor(StringDecoder.allMimeTypes());
    RSocketMessageHandler handler = new RSocketMessageHandler();
    handler.setDecoders(Arrays.asList(new ByteArrayDecoder(), new ByteBufferDecoder()));
    handler.setEncoders(Collections.singletonList(new ByteBufferEncoder()));
    handler.setMetadataExtractor(extractor);
    handler.afterPropertiesSet();
    assertThat(((DefaultMetadataExtractor) handler.getMetadataExtractor()).getDecoders()).hasSize(1);
}
Also used : ByteBufferEncoder(org.springframework.core.codec.ByteBufferEncoder) DefaultMetadataExtractor(org.springframework.messaging.rsocket.DefaultMetadataExtractor) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) Test(org.junit.jupiter.api.Test)

Example 5 with DefaultMetadataExtractor

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

the class RSocketMessageHandlerTests method setRSocketStrategies.

@Test
public void setRSocketStrategies() {
    RSocketStrategies strategies = RSocketStrategies.builder().encoder(new ByteArrayEncoder()).decoder(new ByteArrayDecoder()).routeMatcher(new SimpleRouteMatcher(new AntPathMatcher())).metadataExtractor(new DefaultMetadataExtractor()).reactiveAdapterStrategy(new ReactiveAdapterRegistry()).build();
    RSocketMessageHandler handler = new RSocketMessageHandler();
    handler.setRSocketStrategies(strategies);
    assertThat(handler.getEncoders()).isEqualTo(strategies.encoders());
    assertThat(handler.getDecoders()).isEqualTo(strategies.decoders());
    assertThat(handler.getRouteMatcher()).isSameAs(strategies.routeMatcher());
    assertThat(handler.getMetadataExtractor()).isSameAs(strategies.metadataExtractor());
    assertThat(handler.getReactiveAdapterRegistry()).isSameAs(strategies.reactiveAdapterRegistry());
}
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)

Aggregations

DefaultMetadataExtractor (org.springframework.messaging.rsocket.DefaultMetadataExtractor)6 ByteArrayDecoder (org.springframework.core.codec.ByteArrayDecoder)5 Test (org.junit.jupiter.api.Test)4 ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)3 ByteArrayEncoder (org.springframework.core.codec.ByteArrayEncoder)3 RSocketStrategies (org.springframework.messaging.rsocket.RSocketStrategies)3 AntPathMatcher (org.springframework.util.AntPathMatcher)3 SimpleRouteMatcher (org.springframework.util.SimpleRouteMatcher)3 ByteBufferDecoder (org.springframework.core.codec.ByteBufferDecoder)1 ByteBufferEncoder (org.springframework.core.codec.ByteBufferEncoder)1 BasicAuthenticationDecoder (org.springframework.security.rsocket.metadata.BasicAuthenticationDecoder)1