Top Description Inners Fields Constructors Methods
org.springframework.messaging.rsocket

public Class DefaultMetadataExtractor

extends Object
implements MetadataExtractor, MetadataExtractorRegistry
Class Inheritance
All Implemented Interfaces
org.springframework.messaging.rsocket.MetadataExtractorRegistry, org.springframework.messaging.rsocket.MetadataExtractor
Imports
java.util.Arrays, .Collections, .HashMap, .Iterator, .List, .Map, java.util.function.BiConsumer, io.netty.buffer.ByteBuf, .ByteBufAllocator, io.rsocket.Payload, io.rsocket.metadata.CompositeMetadata, .RoutingMetadata, .WellKnownMimeType, org.apache.commons.logging.Log, .LogFactory, org.springframework.core.ParameterizedTypeReference, .ResolvableType, org.springframework.core.codec.Decoder, org.springframework.core.io.buffer.NettyDataBuffer, .NettyDataBufferFactory, org.springframework.lang.Nullable, org.springframework.util.MimeType

Default MetadataExtractor implementation that relies on Decoders to deserialize the content of metadata entries.

By default only "message/x.rsocket.routing.v0" is extracted and saved under MetadataExtractor#ROUTE_KEY. Use metadataToExtract methods to specify other metadata mime types of interest to extract.

Author
Rossen Stoyanchev
Since
5.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final List<Decoder<?>>
private static final Log
private final Map<String, DefaultMetadataExtractor.EntryExtractor<?>>

Constructor Summary

AccessConstructor and Description
public
DefaultMetadataExtractor(Decoder<?>... decoders)

Constructor with decoders for de-serializing metadata entries.

public
DefaultMetadataExtractor(List<Decoder<?>> decoders)

Constructor with list of decoders for de-serializing metadata entries.

Method Summary

Modifier and TypeMethod and Description
public Map<String, Object>
extract(Payload
the payload whose metadata should be read
payload
,
MimeType
the metadata MimeType for the connection.
metadataMimeType
)

Implements org.springframework.messaging.rsocket.MetadataExtractor.extract.

Extract a map of values from the given Payload metadata.
private void
extractEntry(ByteBuf content, String mimeType, Map<String, Object> result)

public List<? extends Decoder<?>>
getDecoders()

Return a read-only list with the configured decoders.

public <T> void
metadataToExtract(MimeType
the mime type of metadata entries to extract
mimeType
,
Class<T>
the target value type to decode to
targetType
,
BiConsumer<T, Map<String, Object>>
custom logic to add the decoded value to the output map
mapper
)

Implements org.springframework.messaging.rsocket.MetadataExtractorRegistry.metadataToExtract.

Variant of metadataToExtract(MimeType, Class, String) that allows custom logic to be used to map the decoded value to any number of values in the output map.
public <T> void
metadataToExtract(MimeType
the mime type of metadata entries to extract
mimeType
,
ParameterizedTypeReference<T>
the target value type to decode to
type
,
BiConsumer<T, Map<String, Object>>
custom logic to add the decoded value to the output map
mapper
)

Implements org.springframework.messaging.rsocket.MetadataExtractorRegistry.metadataToExtract.

Variant of metadataToExtract(MimeType, Class, BiConsumer) that accepts ParameterizedTypeReference instead of Class for specifying a target type with generic parameters.
private <T> void
registerMetadata(MimeType mimeType, ResolvableType targetType, BiConsumer<T, Map<String, Object>> mapper)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

decodersback to summary
private final List<Decoder<?>> decoders
loggerback to summary
private static final Log logger
registrationsback to summary
private final Map<String, DefaultMetadataExtractor.EntryExtractor<?>> registrations

Constructor Detail

DefaultMetadataExtractorback to summary
public DefaultMetadataExtractor(Decoder<?>... decoders)

Constructor with decoders for de-serializing metadata entries.

DefaultMetadataExtractorback to summary
public DefaultMetadataExtractor(List<Decoder<?>> decoders)

Constructor with list of decoders for de-serializing metadata entries.

Method Detail

extractback to summary
public Map<String, Object> extract(Payload payload, MimeType metadataMimeType)

Implements org.springframework.messaging.rsocket.MetadataExtractor.extract.

Doc from org.springframework.messaging.rsocket.MetadataExtractor.extract.

Extract a map of values from the given Payload metadata. The Payload "route", if present, should be saved under ROUTE_KEY.

Parameters
payload:Payload

the payload whose metadata should be read

metadataMimeType:MimeType

the metadata MimeType for the connection.

Returns:Map<String, Object>

name values pairs extracted from the metadata

Annotations
@Override
extractEntryback to summary
private void extractEntry(ByteBuf content, String mimeType, Map<String, Object> result)
getDecodersback to summary
public List<? extends Decoder<?>> getDecoders()

Return a read-only list with the configured decoders.

metadataToExtractback to summary
public <T> void metadataToExtract(MimeType mimeType, Class<T> targetType, BiConsumer<T, Map<String, Object>> mapper)

Implements org.springframework.messaging.rsocket.MetadataExtractorRegistry.metadataToExtract.

Doc from org.springframework.messaging.rsocket.MetadataExtractorRegistry.metadataToExtract.

Variant of metadataToExtract(MimeType, Class, String) that allows custom logic to be used to map the decoded value to any number of values in the output map.

Parameters
<T>
the target value type
mimeType:MimeType

the mime type of metadata entries to extract

targetType:Class<T>

the target value type to decode to

mapper:BiConsumer<T, Map<String, Object>>

custom logic to add the decoded value to the output map

Annotations
@Override
metadataToExtractback to summary
public <T> void metadataToExtract(MimeType mimeType, ParameterizedTypeReference<T> type, BiConsumer<T, Map<String, Object>> mapper)

Implements org.springframework.messaging.rsocket.MetadataExtractorRegistry.metadataToExtract.

Doc from org.springframework.messaging.rsocket.MetadataExtractorRegistry.metadataToExtract.

Variant of metadataToExtract(MimeType, Class, BiConsumer) that accepts ParameterizedTypeReference instead of Class for specifying a target type with generic parameters.

Parameters
<T>
the target value type
mimeType:MimeType

the mime type of metadata entries to extract

type:ParameterizedTypeReference<T>

the target value type to decode to

mapper:BiConsumer<T, Map<String, Object>>

custom logic to add the decoded value to the output map

Annotations
@Override
registerMetadataback to summary
private <T> void registerMetadata(MimeType mimeType, ResolvableType targetType, BiConsumer<T, Map<String, Object>> mapper)
Annotations
@SuppressWarnings:unchecked
org.springframework.messaging.rsocket back to summary

private Class DefaultMetadataExtractor.EntryExtractor<T>

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.messaging.rsocket.DefaultMetadataExtractor.EntryExtractor

Field Summary

Modifier and TypeField and Description
private final BiConsumer<T, Map<String, Object>>
private static final NettyDataBufferFactory
private final Decoder<T>
private final MimeType
private final ResolvableType

Constructor Summary

AccessConstructor and Description
pack-priv
EntryExtractor(Decoder<T> decoder, MimeType mimeType, ResolvableType targetType, BiConsumer<T, Map<String, Object>> accumulator)

Method Summary

Modifier and TypeMethod and Description
public void
extract(ByteBuf content, Map<String, Object> result)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

accumulatorback to summary
private final BiConsumer<T, Map<String, Object>> accumulator
bufferFactoryback to summary
private static final NettyDataBufferFactory bufferFactory
decoderback to summary
private final Decoder<T> decoder
mimeTypeback to summary
private final MimeType mimeType
targetTypeback to summary
private final ResolvableType targetType

Constructor Detail

EntryExtractorback to summary
pack-priv EntryExtractor(Decoder<T> decoder, MimeType mimeType, ResolvableType targetType, BiConsumer<T, Map<String, Object>> accumulator)

Method Detail

extractback to summary
public void extract(ByteBuf content, Map<String, Object> result)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override