From 53d4faa83c795c6da21cca0c3084c8ae42ea09bd Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 10 Jul 2019 09:52:59 -0400 Subject: [PATCH] Fix new Sonar smells * Use method chain in the `AggregatorSpec.processor()` * Add JavaDoc to the `AvroHeaders.PREFIX` --- .../integration/dsl/AggregatorSpec.java | 8 ++++---- .../SimpleFromAvroTransformer.java | 19 ++++++++++++------- .../transformer/support/AvroHeaders.java | 9 +++++++-- .../rsocket/AbstractRSocketConnector.java | 6 +++--- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/AggregatorSpec.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/AggregatorSpec.java index f50ccb191c..1de4d3c2de 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/AggregatorSpec.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/AggregatorSpec.java @@ -66,10 +66,10 @@ public class AggregatorSpec extends CorrelationHandlerSpec>( - msg -> msg.getHeaders().get(AvroHeaders.TYPE)); + private Expression typeIdExpression = + new FunctionExpression>((message) -> message.getHeaders().get(AvroHeaders.TYPE)); private EvaluationContext evaluationContext; @@ -76,11 +78,15 @@ public class SimpleFromAvroTransformer extends AbstractTransformer implements Be * @return the transformer */ public SimpleFromAvroTransformer typeExpression(Expression expression) { - Assert.notNull(expression, "'expression' must not be null"); + assertExpressionNotNull(expression); this.typeIdExpression = expression; return this; } + private void assertExpressionNotNull(Object expression) { + Assert.notNull(expression, "'expression' must not be null"); + } + /** * Set the expression to evaluate against the message to determine the type id. * Default {@code headers['avro_type']}. @@ -88,7 +94,7 @@ public class SimpleFromAvroTransformer extends AbstractTransformer implements Be * @return the transformer */ public SimpleFromAvroTransformer typeExpression(String expression) { - Assert.notNull(expression, "'expression' must not be null"); + assertExpressionNotNull(expression); this.typeIdExpression = EXPRESSION_PARSER.parseExpression(expression); return this; } @@ -99,7 +105,7 @@ public class SimpleFromAvroTransformer extends AbstractTransformer implements Be * @param expression the expression. */ public void setTypeExpression(Expression expression) { - Assert.notNull(expression, "'expression' must not be null"); + assertExpressionNotNull(expression); this.typeIdExpression = expression; } @@ -109,7 +115,7 @@ public class SimpleFromAvroTransformer extends AbstractTransformer implements Be * @param expression the expression. */ public void setTypeExpression(String expression) { - Assert.notNull(expression, "'expression' must not be null"); + assertExpressionNotNull(expression); this.typeIdExpression = EXPRESSION_PARSER.parseExpression(expression); } @@ -147,5 +153,4 @@ public class SimpleFromAvroTransformer extends AbstractTransformer implements Be } } - } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/support/AvroHeaders.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/support/AvroHeaders.java index f4ac872b90..15d349b76b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/support/AvroHeaders.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/support/AvroHeaders.java @@ -20,6 +20,8 @@ package org.springframework.integration.transformer.support; * Pre-defined names and prefixes for Apache Avro related headers. * * @author Gary Russell + * @author Artem Bilan + * * @since 5.2 */ public final class AvroHeaders { @@ -28,11 +30,14 @@ public final class AvroHeaders { super(); } - public static final String PREFIX = "avro"; + /** + * The prefix for Apache Avro specific message headers. + */ + public static final String PREFIX = "avro_"; /** * The {@code SpecificRecord} type. */ - public static final String TYPE = PREFIX + "_type"; + public static final String TYPE = PREFIX + "type"; } diff --git a/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/AbstractRSocketConnector.java b/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/AbstractRSocketConnector.java index 5ad3a8ef7b..7f4afa1388 100644 --- a/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/AbstractRSocketConnector.java +++ b/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/AbstractRSocketConnector.java @@ -27,7 +27,6 @@ import org.springframework.core.codec.CharSequenceEncoder; import org.springframework.core.codec.StringDecoder; import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.messaging.rsocket.RSocketStrategies; -import org.springframework.messaging.rsocket.annotation.support.DefaultMetadataExtractor; import org.springframework.messaging.rsocket.annotation.support.MetadataExtractor; import org.springframework.util.Assert; import org.springframework.util.MimeType; @@ -126,8 +125,9 @@ public abstract class AbstractRSocketConnector /** * Configure a {@link MetadataExtractor} to extract the route and possibly * other metadata from the first payload of incoming requests. - *

By default this is a {@link DefaultMetadataExtractor} with the - * configured {@link RSocketStrategies} (and decoders), extracting a route + *

By default this is a + * {@link org.springframework.messaging.rsocket.annotation.support.DefaultMetadataExtractor} + * with the configured {@link RSocketStrategies} (and decoders), extracting a route * from {@code "message/x.rsocket.routing.v0"} or {@code "text/plain"} * metadata entries. * @param extractor the extractor to use