use of io.rsocket.metadata.CompositeMetadata in project spring-framework by spring-projects.
the class MetadataEncoderTests method compositeMetadata.
@Test
public void compositeMetadata() {
Mono<String> asyncMeta1 = Mono.delay(Duration.ofMillis(1)).map(aLong -> "Async Metadata 1");
Mono<String> asyncMeta2 = Mono.delay(Duration.ofMillis(1)).map(aLong -> "Async Metadata 2");
DataBuffer buffer = new MetadataEncoder(COMPOSITE_METADATA, this.strategies).route("toA").metadata("My metadata", MimeTypeUtils.TEXT_PLAIN).metadata(asyncMeta1, new MimeType("text", "x.test.metadata1")).metadata(Unpooled.wrappedBuffer("Raw data".getBytes(UTF_8)), MimeTypeUtils.APPLICATION_OCTET_STREAM).metadata(asyncMeta2, new MimeType("text", "x.test.metadata2")).encode().block();
CompositeMetadata entries = new CompositeMetadata(((NettyDataBuffer) buffer).getNativeBuffer(), false);
Iterator<CompositeMetadata.Entry> iterator = entries.iterator();
assertThat(iterator.hasNext()).isTrue();
CompositeMetadata.Entry entry = iterator.next();
assertThat(entry.getMimeType()).isEqualTo(WellKnownMimeType.MESSAGE_RSOCKET_ROUTING.getString());
assertRoute("toA", entry.getContent());
assertThat(iterator.hasNext()).isTrue();
entry = iterator.next();
assertThat(entry.getMimeType()).isEqualTo(MimeTypeUtils.TEXT_PLAIN_VALUE);
assertThat(entry.getContent().toString(UTF_8)).isEqualTo("My metadata");
assertThat(iterator.hasNext()).isTrue();
entry = iterator.next();
assertThat(entry.getMimeType()).isEqualTo("text/x.test.metadata1");
assertThat(entry.getContent().toString(UTF_8)).isEqualTo("Async Metadata 1");
assertThat(iterator.hasNext()).isTrue();
entry = iterator.next();
assertThat(entry.getMimeType()).isEqualTo(MimeTypeUtils.APPLICATION_OCTET_STREAM_VALUE);
assertThat(entry.getContent().toString(UTF_8)).isEqualTo("Raw data");
assertThat(iterator.hasNext()).isTrue();
entry = iterator.next();
assertThat(entry.getMimeType()).isEqualTo("text/x.test.metadata2");
assertThat(entry.getContent().toString(UTF_8)).isEqualTo("Async Metadata 2");
assertThat(iterator.hasNext()).isFalse();
}
use of io.rsocket.metadata.CompositeMetadata in project spring-framework by spring-projects.
the class MetadataEncoderTests method defaultDataBufferFactory.
@Test
public void defaultDataBufferFactory() {
DefaultDataBufferFactory bufferFactory = DefaultDataBufferFactory.sharedInstance;
RSocketStrategies strategies = RSocketStrategies.builder().dataBufferFactory(bufferFactory).build();
DataBuffer buffer = new MetadataEncoder(COMPOSITE_METADATA, strategies).route("toA").encode().block();
ByteBuf byteBuf = new NettyDataBufferFactory(ByteBufAllocator.DEFAULT).wrap(buffer.asByteBuffer()).getNativeBuffer();
CompositeMetadata entries = new CompositeMetadata(byteBuf, false);
Iterator<CompositeMetadata.Entry> iterator = entries.iterator();
assertThat(iterator.hasNext()).isTrue();
CompositeMetadata.Entry entry = iterator.next();
assertThat(entry.getMimeType()).isEqualTo(WellKnownMimeType.MESSAGE_RSOCKET_ROUTING.getString());
assertRoute("toA", entry.getContent());
assertThat(iterator.hasNext()).isFalse();
}
use of io.rsocket.metadata.CompositeMetadata in project spring-security by spring-projects.
the class BearerPayloadExchangeConverter method convert.
@Override
public Mono<Authentication> convert(PayloadExchange exchange) {
ByteBuf metadata = exchange.getPayload().metadata();
CompositeMetadata compositeMetadata = new CompositeMetadata(metadata, false);
for (CompositeMetadata.Entry entry : compositeMetadata) {
if (BEARER_MIME_TYPE_VALUE.equals(entry.getMimeType())) {
ByteBuf content = entry.getContent();
String token = content.toString(StandardCharsets.UTF_8);
return Mono.just(new BearerTokenAuthenticationToken(token));
}
}
return Mono.empty();
}
Aggregations