Class DefaultMetadataExtractor

java.lang.Object
org.springframework.messaging.rsocket.DefaultMetadataExtractor
All Implemented Interfaces:
MetadataExtractor, MetadataExtractorRegistry

public class DefaultMetadataExtractor extends Object implements MetadataExtractor, MetadataExtractorRegistry
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.

Since:
5.2
Author:
Rossen Stoyanchev
  • Constructor Details

    • DefaultMetadataExtractor

      public DefaultMetadataExtractor(org.springframework.core.codec.Decoder<?>... decoders)
      Constructor with decoders for de-serializing metadata entries.
    • DefaultMetadataExtractor

      public DefaultMetadataExtractor(List<org.springframework.core.codec.Decoder<?>> decoders)
      Constructor with list of decoders for de-serializing metadata entries.
  • Method Details

    • getDecoders

      public List<? extends org.springframework.core.codec.Decoder<?>> getDecoders()
      Return a read-only list with the configured decoders.
    • metadataToExtract

      public <T> void metadataToExtract(org.springframework.util.MimeType mimeType, Class<T> targetType, BiConsumer<T,Map<String,Object>> mapper)
      Description copied from interface: MetadataExtractorRegistry
      Variant of MetadataExtractorRegistry.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.
      Specified by:
      metadataToExtract in interface MetadataExtractorRegistry
      Type Parameters:
      T - the target value type
      Parameters:
      mimeType - the mime type of metadata entries to extract
      targetType - the target value type to decode to
      mapper - custom logic to add the decoded value to the output map
    • metadataToExtract

      public <T> void metadataToExtract(org.springframework.util.MimeType mimeType, org.springframework.core.ParameterizedTypeReference<T> type, BiConsumer<T,Map<String,Object>> mapper)
      Description copied from interface: MetadataExtractorRegistry
      Variant of MetadataExtractorRegistry.metadataToExtract(MimeType, Class, BiConsumer) that accepts ParameterizedTypeReference instead of Class for specifying a target type with generic parameters.
      Specified by:
      metadataToExtract in interface MetadataExtractorRegistry
      Type Parameters:
      T - the target value type
      Parameters:
      mimeType - the mime type of metadata entries to extract
      type - the target value type to decode to
      mapper - custom logic to add the decoded value to the output map
    • extract

      public Map<String,Object> extract(io.rsocket.Payload payload, org.springframework.util.MimeType metadataMimeType)
      Description copied from interface: MetadataExtractor
      Extract a map of values from the given Payload metadata. The Payload "route", if present, should be saved under MetadataExtractor.ROUTE_KEY.
      Specified by:
      extract in interface MetadataExtractor
      Parameters:
      payload - the payload whose metadata should be read
      metadataMimeType - the metadata MimeType for the connection.
      Returns:
      name values pairs extracted from the metadata