001/* 002 * Copyright 2002-2019 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.springframework.messaging.rsocket; 017 018import java.util.Map; 019 020import io.rsocket.Payload; 021 022import org.springframework.core.codec.DecodingException; 023import org.springframework.util.MimeType; 024 025/** 026 * Strategy to extract a map of value(s) from {@link Payload} metadata, which 027 * could be composite metadata with multiple entries. Each metadata entry 028 * is decoded based on its {@code MimeType} and a name is assigned to the decoded 029 * value. The resulting name-value pairs can be added to the headers of a 030 * {@link org.springframework.messaging.Message Message}. 031 * 032 * @author Rossen Stoyanchev 033 * @since 5.2 034 * @see MetadataExtractorRegistry 035 */ 036public interface MetadataExtractor { 037 038 /** 039 * The key to assign to the extracted "route" of the payload. 040 */ 041 String ROUTE_KEY = "route"; 042 043 044 /** 045 * Extract a map of values from the given {@link Payload} metadata. 046 * The Payload "route", if present, should be saved under {@link #ROUTE_KEY}. 047 * @param payload the payload whose metadata should be read 048 * @param metadataMimeType the metadata MimeType for the connection. 049 * @return name values pairs extracted from the metadata 050 * @throws DecodingException if the metadata cannot be decoded 051 * @throws IllegalArgumentException if routing metadata cannot be decoded 052 */ 053 Map<String, Object> extract(Payload payload, MimeType metadataMimeType); 054 055}