提交 d33e4878 编写于 作者: R Rossen Stoyanchev

Move MetadataExtractor to the rsocket package

The move up the hierarchy reflects the fact that MetadataExtractor
is more generally useful and not tied to annotations.
上级 aa9f8409
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.messaging.rsocket.annotation.support;
package org.springframework.messaging.rsocket;
import java.util.Collections;
import java.util.HashMap;
......@@ -31,7 +31,6 @@ import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.NettyDataBufferFactory;
import org.springframework.lang.Nullable;
import org.springframework.messaging.rsocket.RSocketStrategies;
import org.springframework.util.Assert;
import org.springframework.util.MimeType;
......@@ -61,7 +60,7 @@ public class DefaultMetadataExtractor implements MetadataExtractor {
Assert.notNull(strategies, "RSocketStrategies is required");
this.rsocketStrategies = strategies;
// TODO: remove when rsocket-core API available
metadataToExtract(MessagingRSocket.ROUTING, String.class, ROUTE_KEY);
metadataToExtract(MetadataExtractor.ROUTING, String.class, ROUTE_KEY);
}
......@@ -131,7 +130,7 @@ public class DefaultMetadataExtractor implements MetadataExtractor {
@Override
public Map<String, Object> extract(Payload payload, MimeType metadataMimeType) {
Map<String, Object> result = new HashMap<>();
if (metadataMimeType.equals(MessagingRSocket.COMPOSITE_METADATA)) {
if (metadataMimeType.equals(COMPOSITE_METADATA)) {
for (CompositeMetadata.Entry entry : new CompositeMetadata(payload.metadata(), false)) {
processEntry(entry.getContent(), entry.getMimeType(), result);
}
......@@ -149,7 +148,7 @@ public class DefaultMetadataExtractor implements MetadataExtractor {
entryProcessor.process(content, result);
return;
}
if (MessagingRSocket.ROUTING.toString().equals(mimeType)) {
if (MetadataExtractor.ROUTING.toString().equals(mimeType)) {
// TODO: use rsocket-core API when available
}
}
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.messaging.rsocket.annotation.support;
package org.springframework.messaging.rsocket;
import java.util.Map;
......@@ -38,6 +38,16 @@ public interface MetadataExtractor {
*/
String ROUTE_KEY = "route";
/**
* Constant for mime type {@code message/x.rsocket.composite-metadata.v0}.
*/
MimeType COMPOSITE_METADATA = new MimeType("message", "x.rsocket.composite-metadata.v0");
/**
* Constant for mime type {@code message/x.rsocket.routing.v0}.
*/
MimeType ROUTING = new MimeType("message", "x.rsocket.routing.v0");
/**
* Extract a map of values from the given {@link Payload} metadata.
......
......@@ -22,6 +22,7 @@ import io.rsocket.RSocketFactory;
import org.springframework.messaging.handler.invocation.reactive.ArgumentResolverConfigurer;
import org.springframework.messaging.handler.invocation.reactive.ReturnValueHandlerConfigurer;
import org.springframework.messaging.rsocket.MetadataExtractor;
import org.springframework.messaging.rsocket.RSocketStrategies;
import org.springframework.util.RouteMatcher;
......
......@@ -24,6 +24,7 @@ import io.rsocket.RSocketFactory;
import org.springframework.lang.Nullable;
import org.springframework.messaging.handler.invocation.reactive.ArgumentResolverConfigurer;
import org.springframework.messaging.handler.invocation.reactive.ReturnValueHandlerConfigurer;
import org.springframework.messaging.rsocket.MetadataExtractor;
import org.springframework.messaging.rsocket.RSocketStrategies;
import org.springframework.util.Assert;
import org.springframework.util.RouteMatcher;
......
......@@ -40,6 +40,7 @@ import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.ReactiveMessageHandler;
import org.springframework.messaging.handler.DestinationPatternsMessageCondition;
import org.springframework.messaging.handler.invocation.reactive.HandlerMethodReturnValueHandler;
import org.springframework.messaging.rsocket.MetadataExtractor;
import org.springframework.messaging.rsocket.PayloadUtils;
import org.springframework.messaging.rsocket.RSocketRequester;
import org.springframework.messaging.support.MessageBuilder;
......@@ -60,11 +61,6 @@ import org.springframework.util.RouteMatcher;
*/
class MessagingRSocket extends AbstractRSocket {
static final MimeType COMPOSITE_METADATA = new MimeType("message", "x.rsocket.composite-metadata.v0");
static final MimeType ROUTING = new MimeType("message", "x.rsocket.routing.v0");
private final MimeType dataMimeType;
private final MimeType metadataMimeType;
......
......@@ -40,6 +40,8 @@ import org.springframework.messaging.handler.DestinationPatternsMessageCondition
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.reactive.MessageMappingMessageHandler;
import org.springframework.messaging.handler.invocation.reactive.HandlerMethodReturnValueHandler;
import org.springframework.messaging.rsocket.DefaultMetadataExtractor;
import org.springframework.messaging.rsocket.MetadataExtractor;
import org.springframework.messaging.rsocket.RSocketRequester;
import org.springframework.messaging.rsocket.RSocketStrategies;
import org.springframework.messaging.rsocket.annotation.ConnectMapping;
......@@ -74,7 +76,7 @@ public class RSocketMessageHandler extends MessageMappingMessageHandler {
@Nullable
private MimeType defaultDataMimeType;
private MimeType defaultMetadataMimeType = MessagingRSocket.COMPOSITE_METADATA;
private MimeType defaultMetadataMimeType = MetadataExtractor.COMPOSITE_METADATA;
/**
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.messaging.rsocket.annotation.support;
package org.springframework.messaging.rsocket;
import java.time.Duration;
import java.util.Map;
......@@ -31,16 +31,13 @@ import reactor.core.publisher.Mono;
import org.springframework.core.codec.CharSequenceEncoder;
import org.springframework.core.codec.StringDecoder;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.messaging.rsocket.LeakAwareNettyDataBufferFactory;
import org.springframework.messaging.rsocket.RSocketRequester;
import org.springframework.messaging.rsocket.RSocketStrategies;
import org.springframework.util.Assert;
import org.springframework.util.MimeType;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.messaging.rsocket.annotation.support.MessagingRSocket.COMPOSITE_METADATA;
import static org.springframework.messaging.rsocket.annotation.support.MessagingRSocket.ROUTING;
import static org.springframework.messaging.rsocket.annotation.support.MetadataExtractor.ROUTE_KEY;
import static org.springframework.messaging.rsocket.MetadataExtractor.COMPOSITE_METADATA;
import static org.springframework.messaging.rsocket.MetadataExtractor.ROUTE_KEY;
import static org.springframework.messaging.rsocket.MetadataExtractor.ROUTING;
import static org.springframework.util.MimeTypeUtils.TEXT_HTML;
import static org.springframework.util.MimeTypeUtils.TEXT_PLAIN;
import static org.springframework.util.MimeTypeUtils.TEXT_XML;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册