Enable ModifierOrderCheck Checkstyle rule (#2673)
* Enable ModifierOrderCheck Checkstyle rule * Fix violations for `static` and `abstract` modifier * Remove redundant code in the `TcpNioConnection` * Mark `connectionFactoryName` as `@Nullable` in the `TcpConnectionSupport` ctor and its inheritors * Fix some smells according IDEA suggestions in the affected classes * This should fix some Sonar smells as well * * Fix `HeaderMapperTests` * * Polishing `TcpConnection` code style and fix Javdocs
This commit is contained in:
committed by
Gary Russell
parent
a01d09f0f1
commit
93d7c58b64
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2016 the original author or authors.
|
||||
* Copyright 2015-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,11 +28,13 @@ import com.esotericsoftware.kryo.Registration;
|
||||
* Base class for {@link KryoRegistrar} implementations.
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
public abstract class AbstractKryoRegistrar implements KryoRegistrar {
|
||||
|
||||
protected final static Kryo kryo = new Kryo();
|
||||
protected static final Kryo kryo = new Kryo();
|
||||
|
||||
protected final Log log = LogFactory.getLog(this.getClass());
|
||||
|
||||
@@ -55,7 +57,7 @@ public abstract class AbstractKryoRegistrar implements KryoRegistrar {
|
||||
Registration existing = kryo.getRegistration(id);
|
||||
|
||||
if (existing != null) {
|
||||
throw new RuntimeException((String.format("registration already exists %s", existing)));
|
||||
throw new RuntimeException("registration already exists " + existing);
|
||||
}
|
||||
|
||||
if (this.log.isInfoEnabled()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2016 the original author or authors.
|
||||
* Copyright 2015-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,12 +20,14 @@ package org.springframework.integration.codec.kryo;
|
||||
* Default registration ids for serializers provided by the framework.
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 4.2
|
||||
*
|
||||
*/
|
||||
public final class RegistrationIds {
|
||||
|
||||
public final static int DEFAULT_FILE_REGISTRATION_ID = 40;
|
||||
public static final int DEFAULT_FILE_REGISTRATION_ID = 40;
|
||||
|
||||
public static final int DEFAULT_MESSAGEHEADERS_ID = 41;
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ class DefaultConfiguringBeanFactoryPostProcessor
|
||||
|
||||
private static final Log logger = LogFactory.getLog(DefaultConfiguringBeanFactoryPostProcessor.class);
|
||||
|
||||
private final static IntegrationConverterInitializer INTEGRATION_CONVERTER_INITIALIZER =
|
||||
private static final IntegrationConverterInitializer INTEGRATION_CONVERTER_INITIALIZER =
|
||||
new IntegrationConverterInitializer();
|
||||
|
||||
private static final Set<Integer> registriesProcessed = new HashSet<>();
|
||||
@@ -152,17 +152,22 @@ class DefaultConfiguringBeanFactoryPostProcessor
|
||||
*/
|
||||
private void registerNullChannel() {
|
||||
if (this.beanFactory.containsBean(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME)) {
|
||||
BeanDefinition nullChannelDefinition;
|
||||
BeanDefinition nullChannelDefinition = null;
|
||||
if (this.beanFactory.containsBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME)) {
|
||||
nullChannelDefinition =
|
||||
this.beanFactory.getBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME);
|
||||
}
|
||||
else {
|
||||
nullChannelDefinition =
|
||||
((BeanDefinitionRegistry) this.beanFactory.getParentBeanFactory())
|
||||
.getBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME); // NOSONAR not null
|
||||
BeanDefinitionRegistry parentBeanFactory =
|
||||
(BeanDefinitionRegistry) this.beanFactory.getParentBeanFactory();
|
||||
if (parentBeanFactory != null) {
|
||||
nullChannelDefinition =
|
||||
parentBeanFactory.getBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME);
|
||||
}
|
||||
}
|
||||
if (!NullChannel.class.getName().equals(nullChannelDefinition.getBeanClassName())) {
|
||||
|
||||
if (nullChannelDefinition != null &&
|
||||
!NullChannel.class.getName().equals(nullChannelDefinition.getBeanClassName())) {
|
||||
throw new IllegalStateException("The bean name '" + IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME
|
||||
+ "' is reserved.");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,26 +27,27 @@ import org.springframework.util.Assert;
|
||||
* FactoryBean for creating Expression instances.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ExpressionFactoryBean extends AbstractFactoryBean<Expression> {
|
||||
|
||||
private final static ExpressionParser DEFAULT_PARSER = new SpelExpressionParser();
|
||||
|
||||
private static final ExpressionParser DEFAULT_PARSER = new SpelExpressionParser();
|
||||
|
||||
private final String expressionString;
|
||||
|
||||
private volatile ExpressionParser parser = DEFAULT_PARSER;
|
||||
private ExpressionParser parser = DEFAULT_PARSER;
|
||||
|
||||
|
||||
public ExpressionFactoryBean(String expressionString) {
|
||||
Assert.hasText(expressionString, "expressionString must not be empty or null");
|
||||
Assert.hasText(expressionString, "'expressionString' must not be empty or null");
|
||||
this.expressionString = expressionString;
|
||||
}
|
||||
|
||||
|
||||
public void setParserConfiguration(SpelParserConfiguration parserConfiguration) {
|
||||
Assert.notNull(parserConfiguration, "parserConfiguration must not be null");
|
||||
Assert.notNull(parserConfiguration, "'parserConfiguration' must not be null");
|
||||
this.parser = new SpelExpressionParser(parserConfiguration);
|
||||
}
|
||||
|
||||
@@ -57,7 +58,7 @@ public class ExpressionFactoryBean extends AbstractFactoryBean<Expression> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Expression createInstance() throws Exception {
|
||||
protected Expression createInstance() {
|
||||
return this.parser.parseExpression(this.expressionString);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,23 +32,27 @@ import org.springframework.util.StringUtils;
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ConverterParser extends AbstractBeanDefinitionParser {
|
||||
|
||||
private final static IntegrationConverterInitializer INTEGRATION_CONVERTER_INITIALIZER = new IntegrationConverterInitializer();
|
||||
private static final IntegrationConverterInitializer INTEGRATION_CONVERTER_INITIALIZER =
|
||||
new IntegrationConverterInitializer();
|
||||
|
||||
@Override
|
||||
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionRegistry registry = parserContext.getRegistry();
|
||||
BeanComponentDefinition converterDefinition = IntegrationNamespaceUtils.parseInnerHandlerDefinition(element, parserContext);
|
||||
BeanComponentDefinition converterDefinition =
|
||||
IntegrationNamespaceUtils.parseInnerHandlerDefinition(element, parserContext);
|
||||
if (converterDefinition != null) {
|
||||
INTEGRATION_CONVERTER_INITIALIZER.registerConverter(registry, converterDefinition);
|
||||
}
|
||||
else {
|
||||
String beanName = element.getAttribute("ref");
|
||||
Assert.isTrue(StringUtils.hasText(beanName),
|
||||
"Either a 'ref' attribute pointing to a Converter or a <bean> sub-element defining a Converter is required.");
|
||||
"Either a 'ref' attribute pointing to a Converter " +
|
||||
"or a <bean> sub-element defining a Converter is required.");
|
||||
INTEGRATION_CONVERTER_INITIALIZER.registerConverter(registry, new RuntimeBeanReference(beanName));
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
public abstract class IntegrationComponentSpec<S extends IntegrationComponentSpec<S, T>, T>
|
||||
implements FactoryBean<T>, InitializingBean, DisposableBean {
|
||||
|
||||
protected final static SpelExpressionParser PARSER = new SpelExpressionParser();
|
||||
protected static final SpelExpressionParser PARSER = new SpelExpressionParser();
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass()); // NOSONAR
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@ import org.springframework.integration.transformer.PayloadSerializingTransformer
|
||||
import org.springframework.integration.transformer.PayloadTypeConvertingTransformer;
|
||||
import org.springframework.integration.transformer.StreamTransformer;
|
||||
import org.springframework.integration.transformer.SyslogToMapTransformer;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -58,14 +58,16 @@ import reactor.core.publisher.Mono;
|
||||
*/
|
||||
public abstract class Transformers {
|
||||
|
||||
private final static SpelExpressionParser PARSER = new SpelExpressionParser();
|
||||
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
|
||||
|
||||
public static ObjectToStringTransformer objectToString() {
|
||||
return objectToString(null);
|
||||
}
|
||||
|
||||
public static ObjectToStringTransformer objectToString(String charset) {
|
||||
return charset != null ? new ObjectToStringTransformer(charset) : new ObjectToStringTransformer();
|
||||
public static ObjectToStringTransformer objectToString(@Nullable String charset) {
|
||||
return charset != null
|
||||
? new ObjectToStringTransformer(charset)
|
||||
: new ObjectToStringTransformer();
|
||||
}
|
||||
|
||||
public static ObjectToMapTransformer toMap() {
|
||||
@@ -100,20 +102,21 @@ public abstract class Transformers {
|
||||
return toJson(null, null, null);
|
||||
}
|
||||
|
||||
public static ObjectToJsonTransformer toJson(JsonObjectMapper<?, ?> jsonObjectMapper) {
|
||||
public static ObjectToJsonTransformer toJson(@Nullable JsonObjectMapper<?, ?> jsonObjectMapper) {
|
||||
return toJson(jsonObjectMapper, null, null);
|
||||
}
|
||||
|
||||
public static ObjectToJsonTransformer toJson(JsonObjectMapper<?, ?> jsonObjectMapper,
|
||||
ObjectToJsonTransformer.ResultType resultType) {
|
||||
public static ObjectToJsonTransformer toJson(@Nullable JsonObjectMapper<?, ?> jsonObjectMapper,
|
||||
@Nullable ObjectToJsonTransformer.ResultType resultType) {
|
||||
return toJson(jsonObjectMapper, resultType, null);
|
||||
}
|
||||
|
||||
public static ObjectToJsonTransformer toJson(String contentType) {
|
||||
public static ObjectToJsonTransformer toJson(@Nullable String contentType) {
|
||||
return toJson(null, null, contentType);
|
||||
}
|
||||
|
||||
public static ObjectToJsonTransformer toJson(JsonObjectMapper<?, ?> jsonObjectMapper, String contentType) {
|
||||
public static ObjectToJsonTransformer toJson(@Nullable JsonObjectMapper<?, ?> jsonObjectMapper,
|
||||
@Nullable String contentType) {
|
||||
return toJson(jsonObjectMapper, null, contentType);
|
||||
}
|
||||
|
||||
@@ -124,16 +127,18 @@ public abstract class Transformers {
|
||||
* @return the ObjectToJsonTransformer
|
||||
* @since 5.0.9
|
||||
*/
|
||||
public static ObjectToJsonTransformer toJson(ObjectToJsonTransformer.ResultType resultType) {
|
||||
public static ObjectToJsonTransformer toJson(@Nullable ObjectToJsonTransformer.ResultType resultType) {
|
||||
return toJson(null, resultType, null);
|
||||
}
|
||||
|
||||
public static ObjectToJsonTransformer toJson(ObjectToJsonTransformer.ResultType resultType, String contentType) {
|
||||
public static ObjectToJsonTransformer toJson(@Nullable ObjectToJsonTransformer.ResultType resultType,
|
||||
@Nullable String contentType) {
|
||||
return toJson(null, resultType, contentType);
|
||||
}
|
||||
|
||||
public static ObjectToJsonTransformer toJson(JsonObjectMapper<?, ?> jsonObjectMapper,
|
||||
ObjectToJsonTransformer.ResultType resultType, String contentType) {
|
||||
public static ObjectToJsonTransformer toJson(@Nullable JsonObjectMapper<?, ?> jsonObjectMapper,
|
||||
@Nullable ObjectToJsonTransformer.ResultType resultType, @Nullable String contentType) {
|
||||
|
||||
ObjectToJsonTransformer transformer;
|
||||
if (jsonObjectMapper != null) {
|
||||
if (resultType != null) {
|
||||
@@ -159,15 +164,17 @@ public abstract class Transformers {
|
||||
return fromJson(null, null);
|
||||
}
|
||||
|
||||
public static JsonToObjectTransformer fromJson(Class<?> targetClass) {
|
||||
public static JsonToObjectTransformer fromJson(@Nullable Class<?> targetClass) {
|
||||
return fromJson(targetClass, null);
|
||||
}
|
||||
|
||||
public static JsonToObjectTransformer fromJson(JsonObjectMapper<?, ?> jsonObjectMapper) {
|
||||
public static JsonToObjectTransformer fromJson(@Nullable JsonObjectMapper<?, ?> jsonObjectMapper) {
|
||||
return fromJson(null, jsonObjectMapper);
|
||||
}
|
||||
|
||||
public static JsonToObjectTransformer fromJson(Class<?> targetClass, JsonObjectMapper<?, ?> jsonObjectMapper) {
|
||||
public static JsonToObjectTransformer fromJson(@Nullable Class<?> targetClass,
|
||||
@Nullable JsonObjectMapper<?, ?> jsonObjectMapper) {
|
||||
|
||||
return new JsonToObjectTransformer(targetClass, jsonObjectMapper);
|
||||
}
|
||||
|
||||
@@ -175,7 +182,7 @@ public abstract class Transformers {
|
||||
return serializer(null);
|
||||
}
|
||||
|
||||
public static PayloadSerializingTransformer serializer(Serializer<Object> serializer) {
|
||||
public static PayloadSerializingTransformer serializer(@Nullable Serializer<Object> serializer) {
|
||||
PayloadSerializingTransformer transformer = new PayloadSerializingTransformer();
|
||||
if (serializer != null) {
|
||||
transformer.setSerializer(serializer);
|
||||
@@ -187,7 +194,7 @@ public abstract class Transformers {
|
||||
return deserializer(null, whiteListPatterns);
|
||||
}
|
||||
|
||||
public static PayloadDeserializingTransformer deserializer(Deserializer<Object> deserializer,
|
||||
public static PayloadDeserializingTransformer deserializer(@Nullable Deserializer<Object> deserializer,
|
||||
String... whiteListPatterns) {
|
||||
PayloadDeserializingTransformer transformer = new PayloadDeserializingTransformer();
|
||||
transformer.setWhiteListPatterns(whiteListPatterns);
|
||||
@@ -198,7 +205,6 @@ public abstract class Transformers {
|
||||
}
|
||||
|
||||
public static <T, U> PayloadTypeConvertingTransformer<T, U> converter(Converter<T, U> converter) {
|
||||
Assert.notNull(converter, "The Converter<?, ?> is required for the PayloadTypeConvertingTransformer");
|
||||
PayloadTypeConvertingTransformer<T, U> transformer = new PayloadTypeConvertingTransformer<>();
|
||||
transformer.setConverter(converter);
|
||||
return transformer;
|
||||
@@ -276,7 +282,7 @@ public abstract class Transformers {
|
||||
* @param charset the charset.
|
||||
* @return the {@link StreamTransformer} instance.
|
||||
*/
|
||||
public static StreamTransformer fromStream(String charset) {
|
||||
public static StreamTransformer fromStream(@Nullable String charset) {
|
||||
return new StreamTransformer(charset);
|
||||
}
|
||||
|
||||
|
||||
@@ -84,10 +84,12 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]>, BeanFactoryAware {
|
||||
|
||||
private final static Log logger = LogFactory.getLog(GatewayMethodInboundMessageMapper.class);
|
||||
private static final Log logger = LogFactory.getLog(GatewayMethodInboundMessageMapper.class);
|
||||
|
||||
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
|
||||
|
||||
private final Map<String, Expression> parameterPayloadExpressions = new HashMap<>();
|
||||
|
||||
private final Method method;
|
||||
|
||||
private final Map<String, Expression> headerExpressions;
|
||||
@@ -102,13 +104,11 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
|
||||
private final MessageBuilderFactory messageBuilderFactory;
|
||||
|
||||
private volatile Expression payloadExpression;
|
||||
private Expression payloadExpression;
|
||||
|
||||
private final Map<String, Expression> parameterPayloadExpressions = new HashMap<String, Expression>();
|
||||
private EvaluationContext payloadExpressionEvaluationContext;
|
||||
|
||||
private volatile StandardEvaluationContext payloadExpressionEvaluationContext;
|
||||
|
||||
private volatile BeanFactory beanFactory;
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
private Expression sendTimeoutExpression;
|
||||
|
||||
@@ -127,6 +127,7 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
@Nullable Map<String, Expression> globalHeaderExpressions,
|
||||
@Nullable MethodArgsMessageMapper mapper,
|
||||
@Nullable MessageBuilderFactory messageBuilderFactory) {
|
||||
|
||||
this(method, headerExpressions, globalHeaderExpressions, null, mapper, messageBuilderFactory);
|
||||
}
|
||||
|
||||
@@ -189,7 +190,7 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Message<?> mapArgumentsToMessage(Object[] arguments, Map<String, Object> headers) {
|
||||
private Message<?> mapArgumentsToMessage(Object[] arguments, @Nullable Map<String, Object> headers) {
|
||||
try {
|
||||
return this.argsMapper.toMessage(new MethodArgsHolder(this.method, arguments), headers);
|
||||
}
|
||||
@@ -205,6 +206,7 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
|
||||
private Map<String, Object> evaluateHeaders(EvaluationContext methodInvocationEvaluationContext,
|
||||
Map<String, Expression> headerExpressions) {
|
||||
|
||||
Map<String, Object> evaluatedHeaders = new HashMap<>();
|
||||
for (Map.Entry<String, Expression> entry : headerExpressions.entrySet()) {
|
||||
Object value = entry.getValue().getValue(methodInvocationEvaluationContext);
|
||||
@@ -277,7 +279,7 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
String expressionString = (String) AnnotationUtils.getValue(payload);
|
||||
Assert.hasText(expressionString,
|
||||
"@Payload at method-level on a Gateway must provide a non-empty Expression.");
|
||||
expression = PARSER.parseExpression(expressionString);
|
||||
expression = PARSER.parseExpression(expressionString); // NOSONAR protected with hasText()
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
@@ -285,7 +287,7 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
public class DefaultMethodArgsMessageMapper implements MethodArgsMessageMapper {
|
||||
|
||||
@Override
|
||||
public Message<?> toMessage(MethodArgsHolder holder, @Nullable Map<String, Object> headers) throws Exception {
|
||||
public Message<?> toMessage(MethodArgsHolder holder, @Nullable Map<String, Object> headers) {
|
||||
Object messageOrPayload = null;
|
||||
boolean foundPayloadAnnotation = false;
|
||||
Object[] arguments = holder.getArgs();
|
||||
@@ -296,13 +298,15 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
: new HashMap<>();
|
||||
if (GatewayMethodInboundMessageMapper.this.payloadExpression != null) {
|
||||
messageOrPayload =
|
||||
GatewayMethodInboundMessageMapper.this.payloadExpression.getValue(methodInvocationEvaluationContext);
|
||||
GatewayMethodInboundMessageMapper.this.payloadExpression.getValue(
|
||||
methodInvocationEvaluationContext);
|
||||
}
|
||||
for (int i = 0; i < GatewayMethodInboundMessageMapper.this.parameterList.size(); i++) {
|
||||
Object argumentValue = arguments[i];
|
||||
MethodParameter methodParameter = GatewayMethodInboundMessageMapper.this.parameterList.get(i);
|
||||
Annotation annotation =
|
||||
MessagingAnnotationUtils.findMessagePartAnnotation(methodParameter.getParameterAnnotations(), false);
|
||||
MessagingAnnotationUtils.findMessagePartAnnotation(methodParameter.getParameterAnnotations(),
|
||||
false);
|
||||
if (annotation != null) {
|
||||
if (annotation.annotationType().equals(Payload.class)) {
|
||||
if (messageOrPayload != null) {
|
||||
@@ -329,7 +333,8 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
else if (annotation.annotationType().equals(Headers.class)) {
|
||||
if (argumentValue != null) {
|
||||
if (!(argumentValue instanceof Map)) {
|
||||
throw new IllegalArgumentException("@Headers annotation is only valid for Map-typed parameters");
|
||||
throw new IllegalArgumentException(
|
||||
"@Headers annotation is only valid for Map-typed parameters");
|
||||
}
|
||||
for (Object key : ((Map<?, ?>) argumentValue).keySet()) {
|
||||
Assert.isInstanceOf(String.class, key, "Invalid header name [" + key +
|
||||
@@ -369,10 +374,11 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
v -> GatewayMethodInboundMessageMapper.this.replyTimeoutExpression
|
||||
.getValue(methodInvocationEvaluationContext, Long.class));
|
||||
}
|
||||
MessageBuilderFactory messageBuilderFactory = GatewayMethodInboundMessageMapper.this.messageBuilderFactory;
|
||||
AbstractIntegrationMessageBuilder<?> builder =
|
||||
(messageOrPayload instanceof Message)
|
||||
? GatewayMethodInboundMessageMapper.this.messageBuilderFactory.fromMessage((Message<?>) messageOrPayload)
|
||||
: GatewayMethodInboundMessageMapper.this.messageBuilderFactory.withPayload(messageOrPayload);
|
||||
? messageBuilderFactory.fromMessage((Message<?>) messageOrPayload)
|
||||
: messageBuilderFactory.withPayload(messageOrPayload);
|
||||
builder.copyHeadersIfAbsent(headers);
|
||||
// Explicit headers in XML override any @Header annotations...
|
||||
if (!CollectionUtils.isEmpty(GatewayMethodInboundMessageMapper.this.headerExpressions)) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,10 +22,12 @@ import org.springframework.messaging.Message;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Dave Syer
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public abstract class AbstractMessageProcessor<T> extends AbstractExpressionEvaluator implements MessageProcessor<T> {
|
||||
|
||||
abstract public T processMessage(Message<?> message);
|
||||
public abstract T processMessage(Message<?> message);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,13 +29,14 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
* @param <V> The Map value type.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
public class MapBuilder<B extends MapBuilder<B, K, V>, K, V> {
|
||||
|
||||
protected final static SpelExpressionParser PARSER = new SpelExpressionParser();
|
||||
protected static final SpelExpressionParser PARSER = new SpelExpressionParser();
|
||||
|
||||
private final Map<K, V> map = new HashMap<K, V>();
|
||||
private final Map<K, V> map = new HashMap<>();
|
||||
|
||||
public B put(K key, V value) {
|
||||
this.map.put(key, value);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -45,11 +45,11 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class BeanFactoryChannelResolver implements DestinationResolver<MessageChannel>, BeanFactoryAware {
|
||||
|
||||
private final static Log logger = LogFactory.getLog(BeanFactoryChannelResolver.class);
|
||||
private static final Log logger = LogFactory.getLog(BeanFactoryChannelResolver.class);
|
||||
|
||||
private volatile BeanFactory beanFactory;
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
private volatile HeaderChannelRegistry replyChannelRegistry;
|
||||
private HeaderChannelRegistry replyChannelRegistry;
|
||||
|
||||
private volatile boolean initialized;
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ import io.micrometer.core.instrument.Timer;
|
||||
* The Micrometer implementation of {@link MetricsCaptor}.
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 5.0.4
|
||||
*
|
||||
@@ -148,7 +149,7 @@ public class MicrometerMetricsCaptor implements MetricsCaptor {
|
||||
|
||||
}
|
||||
|
||||
protected static abstract class AbstractMeter<M extends Meter> implements MeterFacade {
|
||||
protected abstract static class AbstractMeter<M extends Meter> implements MeterFacade {
|
||||
|
||||
protected final MeterRegistry meterRegistry; // NOSONAR
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -141,7 +141,7 @@ public class SubscriberOrderTests {
|
||||
}
|
||||
|
||||
|
||||
static abstract class AbstractTestBean {
|
||||
abstract static class AbstractTestBean {
|
||||
|
||||
@Order(4)
|
||||
abstract void fourth(Message<?> message);
|
||||
@@ -157,7 +157,7 @@ public class SubscriberOrderTests {
|
||||
|
||||
private final int maxCallsPerMethod;
|
||||
|
||||
private volatile List<Integer> calls = new ArrayList<Integer>();
|
||||
private final List<Integer> calls = new ArrayList<>();
|
||||
|
||||
|
||||
TestBean(int maxCallsPerMethod) {
|
||||
@@ -166,7 +166,7 @@ public class SubscriberOrderTests {
|
||||
|
||||
|
||||
void reset() {
|
||||
this.calls = new ArrayList<Integer>();
|
||||
this.calls.clear();
|
||||
}
|
||||
|
||||
@Order(3)
|
||||
@@ -211,6 +211,7 @@ public class SubscriberOrderTests {
|
||||
}
|
||||
this.calls.add(methodNumber);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,18 +24,22 @@ import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Artem Bilan
|
||||
*
|
||||
*/
|
||||
class TimeBasedUUIDGenerator {
|
||||
|
||||
static final Object lock = new Object();
|
||||
|
||||
private static final Logger logger = Logger.getLogger(TimeBasedUUIDGenerator.class.getName());
|
||||
|
||||
public static final Object lock = new Object();
|
||||
private static final long macAddress = getMac();
|
||||
|
||||
private static boolean canNotDetermineMac = true;
|
||||
|
||||
private static long lastTime;
|
||||
|
||||
private static long clockSequence = 0;
|
||||
private static final long macAddress = getMac();
|
||||
|
||||
private TimeBasedUUIDGenerator() {
|
||||
super();
|
||||
@@ -45,11 +49,11 @@ class TimeBasedUUIDGenerator {
|
||||
* Will generate unique time based UUID where the next UUID is
|
||||
* always greater then the previous.
|
||||
*/
|
||||
public final static UUID generateId() {
|
||||
static UUID generateId() {
|
||||
return generateIdFromTimestamp(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public final static UUID generateIdFromTimestamp(long currentTimeMillis) {
|
||||
static UUID generateIdFromTimestamp(long currentTimeMillis) {
|
||||
long time;
|
||||
|
||||
synchronized (lock) {
|
||||
@@ -78,11 +82,12 @@ class TimeBasedUUIDGenerator {
|
||||
|
||||
clock_seq_hi_and_reserved <<= 48;
|
||||
|
||||
long cls = 0 | clock_seq_hi_and_reserved;
|
||||
long cls = clock_seq_hi_and_reserved;
|
||||
|
||||
long lsb = cls | macAddress;
|
||||
if (canNotDetermineMac) {
|
||||
logger.warning("UUID generation process was not able to determine your MAC address. Returning random UUID (non version 1 UUID)");
|
||||
logger.warning("UUID generation process was not able to determine your MAC address. " +
|
||||
"Returning random UUID (non version 1 UUID)");
|
||||
return UUID.randomUUID();
|
||||
}
|
||||
else {
|
||||
@@ -98,11 +103,9 @@ class TimeBasedUUIDGenerator {
|
||||
//byte[] mac = ni.getHardwareAddress(); // availabe since Java 1.6
|
||||
byte[] mac = "01:23:45:67:89:ab".getBytes();
|
||||
//Converts array of unsigned bytes to an long
|
||||
if (mac != null) {
|
||||
for (int i = 0; i < mac.length; i++) {
|
||||
macAddressAsLong <<= 8;
|
||||
macAddressAsLong ^= (long) mac[i] & 0xFF;
|
||||
}
|
||||
for (byte aMac : mac) {
|
||||
macAddressAsLong <<= 8;
|
||||
macAddressAsLong ^= (long) aMac & 0xFF;
|
||||
}
|
||||
}
|
||||
canNotDetermineMac = false;
|
||||
@@ -112,4 +115,5 @@ class TimeBasedUUIDGenerator {
|
||||
}
|
||||
return macAddressAsLong;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,11 +34,14 @@ import org.springframework.integration.mapping.AbstractHeaderMapper.HeaderMatche
|
||||
import org.springframework.integration.mapping.AbstractHeaderMapper.PatternBasedHeaderMatcher;
|
||||
import org.springframework.integration.mapping.AbstractHeaderMapper.PrefixBasedMatcher;
|
||||
import org.springframework.integration.mapping.AbstractHeaderMapper.SinglePatternBasedHeaderMatcher;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
public class HeaderMapperTests {
|
||||
@@ -75,8 +78,8 @@ public class HeaderMapperTests {
|
||||
GenericTestProperties properties = createSimpleGenericTestProperties();
|
||||
|
||||
Map<String, Object> attributes = this.mapper.toHeadersFromRequest(properties);
|
||||
assertEquals(null, attributes.get(GenericTestHeaders.APP_ID));
|
||||
assertEquals(null, attributes.get(GenericTestHeaders.REQUEST_ONLY));
|
||||
assertNull(attributes.get(GenericTestHeaders.APP_ID));
|
||||
assertNull(attributes.get(GenericTestHeaders.REQUEST_ONLY));
|
||||
assertEquals("reply-123", attributes.get(GenericTestHeaders.REPLY_ONLY));
|
||||
assertEquals("bar", attributes.get("foo"));
|
||||
assertEquals("Wrong number of mapped header(s)", 2, attributes.size());
|
||||
@@ -310,7 +313,7 @@ public class HeaderMapperTests {
|
||||
}
|
||||
|
||||
public MessageHeaders createSimpleMessageHeaders() {
|
||||
Map<String, Object> headers = new HashMap<String, Object>();
|
||||
Map<String, Object> headers = new HashMap<>();
|
||||
headers.put(GenericTestHeaders.APP_ID, "myAppId");
|
||||
headers.put(GenericTestHeaders.REDELIVERED, true);
|
||||
headers.put(GenericTestHeaders.REQUEST_ONLY, "request-456");
|
||||
@@ -324,7 +327,6 @@ public class HeaderMapperTests {
|
||||
|
||||
@Test
|
||||
public void prefixHeaderPatternMatching() {
|
||||
@SuppressWarnings("deprecation")
|
||||
PatternBasedHeaderMatcher strategy =
|
||||
new PatternBasedHeaderMatcher(Collections.singleton("fOo*"));
|
||||
|
||||
@@ -338,7 +340,6 @@ public class HeaderMapperTests {
|
||||
|
||||
@Test
|
||||
public void suffixHeaderPatternMatching() {
|
||||
@SuppressWarnings("deprecation")
|
||||
PatternBasedHeaderMatcher strategy =
|
||||
new PatternBasedHeaderMatcher(Collections.singleton("*fOo"));
|
||||
|
||||
@@ -435,7 +436,7 @@ public class HeaderMapperTests {
|
||||
}
|
||||
|
||||
|
||||
private static abstract class GenericTestHeaders {
|
||||
private abstract static class GenericTestHeaders {
|
||||
|
||||
public static final String PREFIX = "generic_";
|
||||
|
||||
@@ -464,7 +465,7 @@ public class HeaderMapperTests {
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> extractStandardHeaders(GenericTestProperties source) {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
if (StringUtils.hasText(source.getAppId())) {
|
||||
result.put(GenericTestHeaders.APP_ID, source.getAppId());
|
||||
}
|
||||
@@ -547,6 +548,7 @@ public class HeaderMapperTests {
|
||||
this.appId = appId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Integer getTransactionSize() {
|
||||
return transactionSize;
|
||||
}
|
||||
@@ -555,6 +557,7 @@ public class HeaderMapperTests {
|
||||
this.transactionSize = transactionSize;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Boolean getRedelivered() {
|
||||
return redelivered;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,6 +25,7 @@ import org.springframework.messaging.Message;
|
||||
* Factory for handler beans that are useful for testing.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class TestHandlers {
|
||||
@@ -32,8 +33,9 @@ public abstract class TestHandlers {
|
||||
/**
|
||||
* Create a handler that always returns null.
|
||||
*/
|
||||
public final static Object nullHandler() {
|
||||
public static final Object nullHandler() {
|
||||
return new Object() {
|
||||
|
||||
public Message<?> handle(Message<?> message) {
|
||||
return null;
|
||||
}
|
||||
@@ -43,8 +45,9 @@ public abstract class TestHandlers {
|
||||
/**
|
||||
* Create a handler that simply returns the {@link Message} it receives.
|
||||
*/
|
||||
public final static Object echoHandler() {
|
||||
public static final Object echoHandler() {
|
||||
return new Object() {
|
||||
|
||||
public Message<?> handle(Message<?> message) {
|
||||
return message;
|
||||
}
|
||||
@@ -54,8 +57,9 @@ public abstract class TestHandlers {
|
||||
/**
|
||||
* Create a handler that increments the provided counter.
|
||||
*/
|
||||
public final static Object countingHandler(final AtomicInteger counter) {
|
||||
public static final Object countingHandler(final AtomicInteger counter) {
|
||||
return new Object() {
|
||||
|
||||
public Message<?> handle(Message<?> message) {
|
||||
counter.incrementAndGet();
|
||||
return null;
|
||||
@@ -66,8 +70,9 @@ public abstract class TestHandlers {
|
||||
/**
|
||||
* Create a handler that counts down on the provided latch.
|
||||
*/
|
||||
public final static Object countDownHandler(final CountDownLatch latch) {
|
||||
public static final Object countDownHandler(final CountDownLatch latch) {
|
||||
return new Object() {
|
||||
|
||||
public Message<?> handle(Message<?> message) {
|
||||
latch.countDown();
|
||||
return null;
|
||||
@@ -79,8 +84,9 @@ public abstract class TestHandlers {
|
||||
* Create a handler that counts down on the provided latch
|
||||
* and also increments the provided counter.
|
||||
*/
|
||||
public final static Object countingCountDownHandler(final AtomicInteger counter, final CountDownLatch latch) {
|
||||
public static final Object countingCountDownHandler(final AtomicInteger counter, final CountDownLatch latch) {
|
||||
return new Object() {
|
||||
|
||||
public Message<?> handle(Message<?> message) {
|
||||
counter.incrementAndGet();
|
||||
latch.countDown();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2017-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,12 +25,13 @@ import org.springframework.messaging.Message;
|
||||
|
||||
/**
|
||||
* @author Ivan Krizsan
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
public class DefaultMessageChannelMetricsTests {
|
||||
|
||||
protected final static int MESSAGE_COUNT = 10;
|
||||
protected static final int MESSAGE_COUNT = 10;
|
||||
|
||||
protected final static long SEND_TIMEOUT = 1;
|
||||
protected static final long SEND_TIMEOUT = 1;
|
||||
|
||||
@Test
|
||||
public void errorCountWithCountsEnabledOnlySuccessTest() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,6 @@ package org.springframework.integration.support.management;
|
||||
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -37,11 +36,12 @@ import org.springframework.util.StopWatch;
|
||||
* @author Dave Syer
|
||||
* @author Gary Russell
|
||||
* @author Steven Swor
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
@Ignore("Very sensitive to the time. Don't forget to test after some changes.")
|
||||
public class ExponentialMovingAverageRateTests {
|
||||
|
||||
private final static Log logger = LogFactory.getLog(ExponentialMovingAverageRateTests.class);
|
||||
private static final Log logger = LogFactory.getLog(ExponentialMovingAverageRateTests.class);
|
||||
|
||||
private final ExponentialMovingAverageRate history = new ExponentialMovingAverageRate(1., 10., 10, true);
|
||||
|
||||
@@ -54,7 +54,7 @@ public class ExponentialMovingAverageRateTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testGetTimeSinceLastMeasurement() throws Exception {
|
||||
public void testGetTimeSinceLastMeasurement() {
|
||||
long sleepTime = 20L;
|
||||
|
||||
// fill history with the same value.
|
||||
@@ -67,7 +67,7 @@ public class ExponentialMovingAverageRateTests {
|
||||
assertEquals(Long.valueOf(now), times.peekLast());
|
||||
|
||||
//increment just so we'll have a different value between first and last
|
||||
history.increment(System.nanoTime() - sleepTime * 1000000);
|
||||
history.increment(System.nanoTime() - sleepTime * 1000000);
|
||||
assertNotEquals(times.peekFirst(), times.peekLast());
|
||||
|
||||
/*
|
||||
@@ -76,7 +76,7 @@ public class ExponentialMovingAverageRateTests {
|
||||
* the queue, then we should be closer to the sleep time than we are to
|
||||
* 2 x sleepTime, but we should definitely be greater than the sleep
|
||||
* time.
|
||||
*/
|
||||
*/
|
||||
double timeSinceLastMeasurement = history.getTimeSinceLastMeasurement();
|
||||
assertTrue(timeSinceLastMeasurement > sleepTime);
|
||||
assertTrue(timeSinceLastMeasurement <= (1.5 * sleepTime));
|
||||
@@ -126,7 +126,6 @@ public class ExponentialMovingAverageRateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testGetStandardDeviation() throws Exception {
|
||||
assertEquals(0, history.getStandardDeviation(), 0.01);
|
||||
Thread.sleep(20L);
|
||||
@@ -138,13 +137,12 @@ public class ExponentialMovingAverageRateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testReset() throws Exception {
|
||||
assertEquals(0, history.getStandardDeviation(), 0.01);
|
||||
history.increment();
|
||||
Thread.sleep(30L);
|
||||
history.increment();
|
||||
assertFalse(0 == history.getStandardDeviation());
|
||||
assertNotEquals(0, history.getStandardDeviation(), 0.0);
|
||||
history.reset();
|
||||
assertEquals(0, history.getStandardDeviation(), 0.01);
|
||||
assertEquals(0, history.getCount());
|
||||
@@ -155,7 +153,6 @@ public class ExponentialMovingAverageRateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // tolerance needed is too dependent on hardware
|
||||
public void testRate() {
|
||||
ExponentialMovingAverageRate rate = new ExponentialMovingAverageRate(1, 60, 10);
|
||||
int count = 1000000;
|
||||
@@ -170,7 +167,6 @@ public class ExponentialMovingAverageRateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testPerf() {
|
||||
ExponentialMovingAverageRate rate = new ExponentialMovingAverageRate(1, 60, 10);
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
|
||||
Reference in New Issue
Block a user