Fix new Sonar smells

* Use method chain in the `AggregatorSpec.processor()`
* Add JavaDoc to the `AvroHeaders.PREFIX`
This commit is contained in:
Artem Bilan
2019-07-10 09:52:59 -04:00
parent 9a2b75bae3
commit 53d4faa83c
4 changed files with 26 additions and 16 deletions

View File

@@ -66,10 +66,10 @@ public class AggregatorSpec extends CorrelationHandlerSpec<AggregatorSpec, Aggre
* @return the handler spec.
*/
public AggregatorSpec processor(Object target, String methodName) {
super.processor(target);
return outputProcessor(methodName != null
? new MethodInvokingMessageGroupProcessor(target, methodName)
: new MethodInvokingMessageGroupProcessor(target));
return super.processor(target)
.outputProcessor(methodName != null
? new MethodInvokingMessageGroupProcessor(target, methodName)
: new MethodInvokingMessageGroupProcessor(target));
}
/**

View File

@@ -39,6 +39,8 @@ import org.springframework.util.ClassUtils;
* from {@code byte[]}.
*
* @author Gary Russell
* @author Artem Bilan
*
* @since 5.2
*
*/
@@ -48,8 +50,8 @@ public class SimpleFromAvroTransformer extends AbstractTransformer implements Be
private final DecoderFactory decoderFactory = new DecoderFactory();
private Expression typeIdExpression = new FunctionExpression<Message<?>>(
msg -> msg.getHeaders().get(AvroHeaders.TYPE));
private Expression typeIdExpression =
new FunctionExpression<Message<?>>((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
}
}
}

View File

@@ -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";
}

View File

@@ -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.
* <p>By default this is a {@link DefaultMetadataExtractor} with the
* configured {@link RSocketStrategies} (and decoders), extracting a route
* <p>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