diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java index 93a36ee63e..0cfa8b0a02 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 the original author or authors. + * Copyright 2016-2019 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. @@ -486,19 +486,19 @@ public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducin } protected String generateExchangeName(Message requestMessage) { - String exchangeName = this.exchangeName; + String exchange = this.exchangeName; if (this.exchangeNameGenerator != null) { - exchangeName = this.exchangeNameGenerator.processMessage(requestMessage); + exchange = this.exchangeNameGenerator.processMessage(requestMessage); } - return exchangeName; + return exchange; } protected String generateRoutingKey(Message requestMessage) { - String routingKey = this.routingKey; + String key = this.routingKey; if (this.routingKeyGenerator != null) { - routingKey = this.routingKeyGenerator.processMessage(requestMessage); + key = this.routingKeyGenerator.processMessage(requestMessage); } - return routingKey; + return key; } protected void addDelayProperty(Message message, org.springframework.amqp.core.Message amqpMessage) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java index f331382473..964433f951 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java @@ -425,10 +425,10 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport Deque interceptorStack = null; boolean sent = false; boolean metricsProcessed = false; - MetricsContext metrics = null; - boolean countsEnabled = this.countsEnabled; - ChannelInterceptorList interceptors = this.interceptors; - AbstractMessageChannelMetrics channelMetrics = this.channelMetrics; + MetricsContext metricsContext = null; + boolean countsAreEnabled = this.countsEnabled; + ChannelInterceptorList interceptorList = this.interceptors; + AbstractMessageChannelMetrics metrics = this.channelMetrics; SampleFacade sample = null; try { if (this.datatypes.length > 0) { @@ -438,15 +438,15 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport if (debugEnabled) { logger.debug("preSend on channel '" + this + "', message: " + message); } - if (interceptors.getSize() > 0) { + if (interceptorList.getSize() > 0) { interceptorStack = new ArrayDeque<>(); - message = interceptors.preSend(message, this, interceptorStack); + message = interceptorList.preSend(message, this, interceptorStack); if (message == null) { return false; } } - if (countsEnabled) { - metrics = channelMetrics.beforeSend(); + if (countsAreEnabled) { + metricsContext = metrics.beforeSend(); if (this.metricsCaptor != null) { sample = this.metricsCaptor.start(); } @@ -454,7 +454,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport if (sample != null) { sample.stop(sendTimer(sent)); } - channelMetrics.afterSend(metrics, sent); + metrics.afterSend(metricsContext, sent); metricsProcessed = true; } else { @@ -465,20 +465,20 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport logger.debug("postSend (sent=" + sent + ") on channel '" + this + "', message: " + message); } if (interceptorStack != null) { - interceptors.postSend(message, this, sent); - interceptors.afterSendCompletion(message, this, sent, null, interceptorStack); + interceptorList.postSend(message, this, sent); + interceptorList.afterSendCompletion(message, this, sent, null, interceptorStack); } return sent; } catch (Exception e) { - if (countsEnabled && !metricsProcessed) { + if (countsAreEnabled && !metricsProcessed) { if (sample != null) { sample.stop(buildSendTimer(false, e.getClass().getSimpleName())); } - channelMetrics.afterSend(metrics, false); + metrics.afterSend(metricsContext, false); } if (interceptorStack != null) { - interceptors.afterSendCompletion(message, this, sent, e, interceptorStack); + interceptorList.afterSendCompletion(message, this, sent, e, interceptorStack); } throw IntegrationUtils.wrapInDeliveryExceptionIfNecessary(message, () -> "failed to send Message to channel '" + this.getComponentName() + "'", e); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/DirectChannel.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/DirectChannel.java index 073b432f31..f144dcfcb4 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/DirectChannel.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/DirectChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -85,8 +85,9 @@ public class DirectChannel extends AbstractSubscribableChannel { protected void onInit() { super.onInit(); if (this.maxSubscribers == null) { - Integer maxSubscribers = this.getIntegrationProperty(IntegrationProperties.CHANNELS_MAX_UNICAST_SUBSCRIBERS, Integer.class); - this.setMaxSubscribers(maxSubscribers); + Integer max = this.getIntegrationProperty(IntegrationProperties.CHANNELS_MAX_UNICAST_SUBSCRIBERS, + Integer.class); + this.setMaxSubscribers(max); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java index 0ed43846a0..11c9588e48 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -316,17 +316,17 @@ public class ConsumerEndpointFactoryBean if (this.autoStartup != null) { this.endpoint.setAutoStartup(this.autoStartup); } - int phase = this.phase; + int phaseToSet = this.phase; if (!this.isPhaseSet) { if (this.endpoint instanceof PollingConsumer) { - phase = Integer.MAX_VALUE / 2; + phaseToSet = Integer.MAX_VALUE / 2; } else { - phase = Integer.MIN_VALUE; + phaseToSet = Integer.MIN_VALUE; } } - this.endpoint.setPhase(phase); + this.endpoint.setPhase(phaseToSet); this.endpoint.setRole(this.role); if (this.taskScheduler != null) { this.endpoint.setTaskScheduler(this.taskScheduler); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java index bb6c58a370..154037e86a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -117,24 +117,20 @@ public abstract class AbstractMethodAnnotationPostProcessor) GenericTypeResolver.resolveTypeArgument(this.getClass(), MethodAnnotationPostProcessor.class); - Disposables disposables = null; + Disposables disposablesBean = null; try { - disposables = beanFactory.getBean(Disposables.class); + disposablesBean = beanFactory.getBean(Disposables.class); } catch (Exception e) { // NOSONAR - only for test cases } - this.disposables = disposables; + this.disposables = disposablesBean; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/EndpointSpec.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/EndpointSpec.java index 4990b94fe9..4c4da8bdf8 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/EndpointSpec.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/EndpointSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 the original author or authors. + * Copyright 2016-2019 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. @@ -88,9 +88,9 @@ public abstract class EndpointSpec, F extends Be * @see PollerSpec */ public S poller(PollerSpec pollerMetadataSpec) { - Map componentsToRegister = pollerMetadataSpec.getComponentsToRegister(); - if (componentsToRegister != null) { - this.componentsToRegister.putAll(componentsToRegister); + Map components = pollerMetadataSpec.getComponentsToRegister(); + if (components != null) { + this.componentsToRegister.putAll(components); } return poller(pollerMetadataSpec.get()); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowDefinition.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowDefinition.java index 1e16886211..45639ed328 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowDefinition.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowDefinition.java @@ -3095,14 +3095,14 @@ public abstract class IntegrationFlowDefinition> pollingTask = this::doPoll; + Callable> task = this::doPoll; - List adviceChain = this.adviceChain; - if (!CollectionUtils.isEmpty(adviceChain)) { - ProxyFactory proxyFactory = new ProxyFactory(pollingTask); - if (!CollectionUtils.isEmpty(adviceChain)) { - adviceChain.stream() + List advices = this.adviceChain; + if (!CollectionUtils.isEmpty(advices)) { + ProxyFactory proxyFactory = new ProxyFactory(task); + if (!CollectionUtils.isEmpty(advices)) { + advices.stream() .filter(advice -> !isReceiveOnlyAdvice(advice)) .forEach(proxyFactory::addAdvice); } - pollingTask = (Callable>) proxyFactory.getProxy(this.beanClassLoader); + task = (Callable>) proxyFactory.getProxy(this.beanClassLoader); } if (!CollectionUtils.isEmpty(receiveOnlyAdviceChain)) { applyReceiveOnlyAdviceChain(receiveOnlyAdviceChain); } - return pollingTask; + return task; } private Runnable createPoller() { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MessageProducerSupport.java b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MessageProducerSupport.java index 805ad22a52..19320c0604 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MessageProducerSupport.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MessageProducerSupport.java @@ -219,9 +219,9 @@ public abstract class MessageProducerSupport extends AbstractEndpoint implements * @since 4.3.10 */ protected final boolean sendErrorMessageIfNecessary(Message message, RuntimeException exception) { - MessageChannel errorChannel = getErrorChannel(); - if (errorChannel != null) { - this.messagingTemplate.send(errorChannel, buildErrorMessage(message, exception)); + MessageChannel channel = getErrorChannel(); + if (channel != null) { + this.messagingTemplate.send(channel, buildErrorMessage(message, exception)); return true; } return false; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/SourcePollingChannelAdapter.java b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/SourcePollingChannelAdapter.java index 278dea6502..2c95821624 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/SourcePollingChannelAdapter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/SourcePollingChannelAdapter.java @@ -145,17 +145,13 @@ public class SourcePollingChannelAdapter extends AbstractPollingEndpoint protected void applyReceiveOnlyAdviceChain(Collection chain) { if (!CollectionUtils.isEmpty(chain)) { if (AopUtils.isAopProxy(this.source)) { - Advised source = (Advised) this.source; - this.appliedAdvices.forEach(source::removeAdvice); - for (Advice advice : chain) { - source.addAdvisor(adviceToReceiveAdvisor(advice)); - } + Advised advised = (Advised) this.source; + this.appliedAdvices.forEach(advised::removeAdvice); + chain.stream().forEach(advice -> advised.addAdvisor(adviceToReceiveAdvisor(advice))); } else { ProxyFactory proxyFactory = new ProxyFactory(this.source); - for (Advice advice : chain) { - proxyFactory.addAdvisor(adviceToReceiveAdvisor(advice)); - } + chain.stream().forEach(advice -> proxyFactory.addAdvisor(adviceToReceiveAdvisor(advice))); this.source = (MessageSource) proxyFactory.getProxy(getBeanClassLoader()); } this.appliedAdvices.clear(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionEvalMap.java b/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionEvalMap.java index f8311e5842..3bd5c1b980 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionEvalMap.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/expression/ExpressionEvalMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 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. @@ -282,16 +282,21 @@ public final class ExpressionEvalMap extends AbstractMap { private class ExpressionEvalMapFinalBuilderImpl implements ExpressionEvalMapFinalBuilder { + ExpressionEvalMapFinalBuilderImpl() { + super(); + } + @Override public ExpressionEvalMap build() { if (ExpressionEvalMapBuilder.this.evaluationCallback != null) { return new ExpressionEvalMap(ExpressionEvalMapBuilder.this.expressions, ExpressionEvalMapBuilder.this.evaluationCallback); } - ComponentsEvaluationCallback evaluationCallback = - new ComponentsEvaluationCallback(ExpressionEvalMapBuilder.this.context, - ExpressionEvalMapBuilder.this.root, ExpressionEvalMapBuilder.this.returnType); - return new ExpressionEvalMap(ExpressionEvalMapBuilder.this.expressions, evaluationCallback); + else { + return new ExpressionEvalMap(ExpressionEvalMapBuilder.this.expressions, + new ComponentsEvaluationCallback(ExpressionEvalMapBuilder.this.context, + ExpressionEvalMapBuilder.this.root, ExpressionEvalMapBuilder.this.returnType)); + } } } @@ -300,6 +305,10 @@ public final class ExpressionEvalMap extends AbstractMap { private class ExpressionEvalMapComponentsBuilderImpl extends ExpressionEvalMapFinalBuilderImpl implements ExpressionEvalMapComponentsBuilder { + ExpressionEvalMapComponentsBuilderImpl() { + super(); + } + @Override public ExpressionEvalMapComponentsBuilder usingEvaluationContext(EvaluationContext context) { return ExpressionEvalMapBuilder.this.usingEvaluationContext(context); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java b/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java index 69734d2966..b163c581bf 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -173,9 +173,9 @@ public class MessageFilter extends AbstractReplyProducingPostProcessingMessageHa @Override public Object postProcess(Message message, Object result) { if (result == null) { - MessageChannel discardChannel = getDiscardChannel(); - if (discardChannel != null) { - this.messagingTemplate.send(discardChannel, message); + MessageChannel channel = getDiscardChannel(); + if (channel != null) { + this.messagingTemplate.send(channel, message); } if (this.throwExceptionOnRejection) { throw new MessageRejectedException(message, "MessageFilter '" + this.getComponentName() diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/AnnotationGatewayProxyFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/AnnotationGatewayProxyFactoryBean.java index 864e587574..441b9dadf5 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/AnnotationGatewayProxyFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/AnnotationGatewayProxyFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2019 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. @@ -38,6 +38,7 @@ import org.springframework.util.StringUtils; * Otherwise the default state is applied. * * @author Artem Bilan + * @author Gary Russell * * @since 5.0 */ @@ -47,17 +48,17 @@ public class AnnotationGatewayProxyFactoryBean extends GatewayProxyFactoryBean { public AnnotationGatewayProxyFactoryBean(Class serviceInterface) { super(serviceInterface); - AnnotationAttributes gatewayAttributes = + AnnotationAttributes annotationAttributes = AnnotatedElementUtils.getMergedAnnotationAttributes(serviceInterface, MessagingGateway.class.getName(), false, true); - if (gatewayAttributes == null) { - gatewayAttributes = AnnotationUtils.getAnnotationAttributes( + if (annotationAttributes == null) { + annotationAttributes = AnnotationUtils.getAnnotationAttributes( AnnotationUtils.synthesizeAnnotation(MessagingGateway.class), false, true); } - this.gatewayAttributes = gatewayAttributes; + this.gatewayAttributes = annotationAttributes; - String id = gatewayAttributes.getString("name"); + String id = annotationAttributes.getString("name"); if (StringUtils.hasText(id)) { setBeanName(id); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java index f51e013f97..d2e3ed28ac 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -634,10 +634,10 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint } Map headers = null; // We don't want to eagerly resolve the error channel here - Object errorChannel = this.errorChannel == null ? this.errorChannelName : this.errorChannel; - if (errorChannel != null && method.getReturnType().equals(void.class)) { + Object errorChannelForVoidReturn = this.errorChannel == null ? this.errorChannelName : this.errorChannel; + if (errorChannelForVoidReturn != null && method.getReturnType().equals(void.class)) { headers = new HashMap<>(); - headers.put(MessageHeaders.ERROR_CHANNEL, errorChannel); + headers.put(MessageHeaders.ERROR_CHANNEL, errorChannelForVoidReturn); } if (getMessageBuilderFactory() instanceof DefaultMessageBuilderFactory) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java index b52595f52f..ed9f733dd3 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java @@ -411,19 +411,19 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint protected void send(Object object) { this.initializeIfNecessary(); Assert.notNull(object, "request must not be null"); - MessageChannel requestChannel = getRequestChannel(); - Assert.state(requestChannel != null, + MessageChannel channel = getRequestChannel(); + Assert.state(channel != null, "send is not supported, because no request channel has been configured"); try { if (this.countsEnabled) { this.messageCount.incrementAndGet(); } - this.messagingTemplate.convertAndSend(requestChannel, object, this.historyWritingPostProcessor); + this.messagingTemplate.convertAndSend(channel, object, this.historyWritingPostProcessor); } catch (Exception e) { - MessageChannel errorChannel = getErrorChannel(); - if (errorChannel != null) { - this.messagingTemplate.send(errorChannel, new ErrorMessage(e)); + MessageChannel errorChan = getErrorChannel(); + if (errorChan != null) { + this.messagingTemplate.send(errorChan, new ErrorMessage(e)); } else { this.rethrow(e, "failed to send message"); @@ -434,37 +434,37 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint @Nullable protected Object receive() { this.initializeIfNecessary(); - MessageChannel replyChannel = getReplyChannel(); - Assert.state(replyChannel != null && (replyChannel instanceof PollableChannel), + MessageChannel channel = getReplyChannel(); + Assert.state(channel != null && (channel instanceof PollableChannel), "receive is not supported, because no pollable reply channel has been configured"); - return this.messagingTemplate.receiveAndConvert(replyChannel, Object.class); + return this.messagingTemplate.receiveAndConvert(channel, Object.class); } @Nullable protected Message receiveMessage() { initializeIfNecessary(); - MessageChannel replyChannel = getReplyChannel(); - Assert.state(replyChannel instanceof PollableChannel, + MessageChannel channel = getReplyChannel(); + Assert.state(channel instanceof PollableChannel, "receive is not supported, because no pollable reply channel has been configured"); - return this.messagingTemplate.receive(replyChannel); + return this.messagingTemplate.receive(channel); } @Nullable protected Object receive(long timeout) { this.initializeIfNecessary(); - MessageChannel replyChannel = getReplyChannel(); - Assert.state(replyChannel != null && (replyChannel instanceof PollableChannel), + MessageChannel channel = getReplyChannel(); + Assert.state(channel != null && (channel instanceof PollableChannel), "receive is not supported, because no pollable reply channel has been configured"); - return this.messagingTemplate.receiveAndConvert(replyChannel, timeout); + return this.messagingTemplate.receiveAndConvert(channel, timeout); } @Nullable protected Message receiveMessage(long timeout) { initializeIfNecessary(); - MessageChannel replyChannel = getReplyChannel(); - Assert.state(replyChannel instanceof PollableChannel, + MessageChannel channel = getReplyChannel(); + Assert.state(channel instanceof PollableChannel, "receive is not supported, because no pollable reply channel has been configured"); - return this.messagingTemplate.receive(replyChannel, timeout); + return this.messagingTemplate.receive(channel, timeout); } @Nullable @@ -482,8 +482,8 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint private Object doSendAndReceive(Object object, boolean shouldConvert) { this.initializeIfNecessary(); Assert.notNull(object, "request must not be null"); - MessageChannel requestChannel = getRequestChannel(); - if (requestChannel == null) { + MessageChannel channel = getRequestChannel(); + if (channel == null) { throw new MessagingException("No request channel available. Cannot send request message."); } @@ -497,7 +497,7 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint this.messageCount.incrementAndGet(); } if (shouldConvert) { - reply = this.messagingTemplate.convertSendAndReceive(requestChannel, object, Object.class, + reply = this.messagingTemplate.convertSendAndReceive(channel, object, Object.class, this.historyWritingPostProcessor); if (reply instanceof Throwable) { error = (Throwable) reply; @@ -508,7 +508,7 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint ? (Message) object : this.requestMapper.toMessage(object); Assert.state(requestMessage != null, () -> "request mapper resulted in no message for " + object); requestMessage = this.historyWritingPostProcessor.postProcessMessage(requestMessage); - reply = this.messagingTemplate.sendAndReceive(requestChannel, requestMessage); + reply = this.messagingTemplate.sendAndReceive(channel, requestMessage); if (reply instanceof ErrorMessage) { error = ((ErrorMessage) reply).getPayload(); } @@ -530,12 +530,12 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint } if (error != null) { - MessageChannel errorChannel = getErrorChannel(); - if (errorChannel != null) { + MessageChannel errorChan = getErrorChannel(); + if (errorChan != null) { ErrorMessage errorMessage = buildErrorMessage(requestMessage, error); Message errorFlowReply = null; try { - errorFlowReply = this.messagingTemplate.sendAndReceive(errorChannel, errorMessage); + errorFlowReply = this.messagingTemplate.sendAndReceive(errorChan, errorMessage); } catch (Exception errorFlowFailure) { throw new MessagingException(errorMessage, "failure occurred in error-handling flow", @@ -572,14 +572,14 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint protected Mono> sendAndReceiveMessageReactive(Object object) { initializeIfNecessary(); Assert.notNull(object, "request must not be null"); - MessageChannel requestChannel = getRequestChannel(); - if (requestChannel == null) { + MessageChannel channel = getRequestChannel(); + if (channel == null) { throw new MessagingException("No request channel available. Cannot send request message."); } registerReplyMessageCorrelatorIfNecessary(); - return doSendAndReceiveMessageReactive(requestChannel, object, false); + return doSendAndReceiveMessageReactive(channel, object, false); } @SuppressWarnings("unchecked") @@ -603,13 +603,13 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint Object originalReplyChannelHeader = message.getHeaders().getReplyChannel(); Object originalErrorChannelHeader = message.getHeaders().getErrorChannel(); - FutureReplyChannel replyChannel = new FutureReplyChannel(); + FutureReplyChannel replyChan = new FutureReplyChannel(); Message requestMessage = MutableMessageBuilder.fromMessage(message) - .setReplyChannel(replyChannel) + .setReplyChannel(replyChan) .setHeader(this.messagingTemplate.getSendTimeoutHeader(), null) .setHeader(this.messagingTemplate.getReceiveTimeoutHeader(), null) - .setErrorChannel(replyChannel) + .setErrorChannel(replyChan) .build(); if (requestChannel instanceof ReactiveStreamsSubscribableChannel) { @@ -631,7 +631,7 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint } } - return Mono.fromFuture(replyChannel.messageFuture) + return Mono.fromFuture(replyChan.messageFuture) .doOnSubscribe(s -> { if (!error && this.countsEnabled) { this.messageCount.incrementAndGet(); @@ -662,11 +662,11 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint if (logger.isDebugEnabled()) { logger.debug("failure occurred in gateway sendAndReceiveReactive: " + exception.getMessage()); } - MessageChannel errorChannel = getErrorChannel(); - if (errorChannel != null) { + MessageChannel channel = getErrorChannel(); + if (channel != null) { ErrorMessage errorMessage = buildErrorMessage(requestMessage, exception); try { - return doSendAndReceiveMessageReactive(errorChannel, errorMessage, true); + return doSendAndReceiveMessageReactive(channel, errorMessage, true); } catch (Exception errorFlowFailure) { throw new MessagingException(errorMessage, "failure occurred in error-handling flow", errorFlowFailure); @@ -741,8 +741,8 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint } protected void registerReplyMessageCorrelatorIfNecessary() { - MessageChannel replyChannel = getReplyChannel(); - if (replyChannel != null && this.replyMessageCorrelator == null) { + MessageChannel replyChan = getReplyChannel(); + if (replyChan != null && this.replyMessageCorrelator == null) { boolean shouldStartCorrelator; synchronized (this.replyMessageCorrelatorMonitor) { if (this.replyMessageCorrelator != null) { @@ -754,24 +754,24 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint handler.setBeanFactory(getBeanFactory()); } handler.afterPropertiesSet(); - if (replyChannel instanceof SubscribableChannel) { - correlator = new EventDrivenConsumer((SubscribableChannel) replyChannel, handler); + if (replyChan instanceof SubscribableChannel) { + correlator = new EventDrivenConsumer((SubscribableChannel) replyChan, handler); } - else if (replyChannel instanceof PollableChannel) { - PollingConsumer endpoint = new PollingConsumer((PollableChannel) replyChannel, handler); + else if (replyChan instanceof PollableChannel) { + PollingConsumer endpoint = new PollingConsumer((PollableChannel) replyChan, handler); endpoint.setBeanFactory(getBeanFactory()); endpoint.setReceiveTimeout(this.replyTimeout); endpoint.afterPropertiesSet(); correlator = endpoint; } - else if (replyChannel instanceof ReactiveStreamsSubscribableChannel) { + else if (replyChan instanceof ReactiveStreamsSubscribableChannel) { ReactiveStreamsConsumer endpoint = - new ReactiveStreamsConsumer(replyChannel, (Subscriber>) handler); + new ReactiveStreamsConsumer(replyChan, (Subscriber>) handler); endpoint.afterPropertiesSet(); correlator = endpoint; } else { - throw new MessagingException("Unsupported 'replyChannel' type [" + replyChannel.getClass() + "]." + throw new MessagingException("Unsupported 'replyChannel' type [" + replyChan.getClass() + "]." + "SubscribableChannel or PollableChannel type are supported."); } this.replyMessageCorrelator = correlator; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java index 43fdff213c..5cc1bb294a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java @@ -147,23 +147,23 @@ public abstract class AbstractMessageHandler extends IntegrationObjectSupport this.logger.debug(this + " received message: " + message); } MetricsContext start = null; - boolean countsEnabled = this.countsEnabled; - AbstractMessageHandlerMetrics handlerMetrics = this.handlerMetrics; + boolean countsAreEnabled = this.countsEnabled; + AbstractMessageHandlerMetrics metrics = this.handlerMetrics; SampleFacade sample = null; - if (countsEnabled && this.metricsCaptor != null) { + if (countsAreEnabled && this.metricsCaptor != null) { sample = this.metricsCaptor.start(); } try { if (this.shouldTrack) { message = MessageHistory.write(message, this, getMessageBuilderFactory()); } - if (countsEnabled) { - start = handlerMetrics.beforeHandle(); + if (countsAreEnabled) { + start = metrics.beforeHandle(); handleMessageInternal(message); if (sample != null) { sample.stop(sendTimer()); } - handlerMetrics.afterHandle(start, true); + metrics.afterHandle(start, true); } else { handleMessageInternal(message); @@ -173,8 +173,8 @@ public abstract class AbstractMessageHandler extends IntegrationObjectSupport if (sample != null) { sample.stop(buildSendTimer(false, e.getClass().getSimpleName())); } - if (countsEnabled) { - handlerMetrics.afterHandle(start, false); + if (countsAreEnabled) { + metrics.afterHandle(start, false); } throw IntegrationUtils.wrapInHandlingExceptionIfNecessary(message, () -> "error occurred in message handler [" + this + "]", e); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageProducingHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageProducingHandler.java index ef3fac14c9..acd795f80e 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageProducingHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageProducingHandler.java @@ -418,9 +418,9 @@ public abstract class AbstractMessageProducingHandler extends AbstractMessageHan */ protected void sendOutput(Object output, @Nullable Object replyChannelArg, boolean useArgChannel) { Object replyChannel = replyChannelArg; - MessageChannel outputChannel = getOutputChannel(); - if (!useArgChannel && outputChannel != null) { - replyChannel = outputChannel; + MessageChannel outChannel = getOutputChannel(); + if (!useArgChannel && outChannel != null) { + replyChannel = outChannel; } if (replyChannel == null) { throw new DestinationResolutionException("no output-channel or replyChannel header available"); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/DelayHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/DelayHandler.java index 7b7fc70d27..4d9108c7e2 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/DelayHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/DelayHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -299,16 +299,16 @@ public class DelayHandler extends AbstractReplyProducingMessageHandler implement } private MessageHandler createReleaseMessageTask() { - ReleaseMessageHandler releaseHandler = new ReleaseMessageHandler(); + ReleaseMessageHandler handler = new ReleaseMessageHandler(); if (!CollectionUtils.isEmpty(this.delayedAdviceChain)) { - ProxyFactory proxyFactory = new ProxyFactory(releaseHandler); + ProxyFactory proxyFactory = new ProxyFactory(handler); for (Advice advice : this.delayedAdviceChain) { proxyFactory.addAdvice(advice); } return (MessageHandler) proxyFactory.getProxy(getApplicationContext().getClassLoader()); } - return releaseHandler; + return handler; } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java index 418fb69cef..24cdfcc160 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -354,6 +354,7 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator private MessagingMethodInvokerHelper(Object targetObject, Class annotationType, String methodName, Class expectedType, boolean canProcessMessageList) { + this.annotationType = annotationType; this.methodName = methodName; this.canProcessMessageList = canProcessMessageList; @@ -367,15 +368,15 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator this.targetObject = targetObject; Map, HandlerMethod>> handlerMethodsForTarget = findHandlerMethodsForTarget(targetObject, annotationType, methodName, expectedType != null); - Map, HandlerMethod> handlerMethods = handlerMethodsForTarget.get(CANDIDATE_METHODS); - Map, HandlerMethod> handlerMessageMethods = handlerMethodsForTarget.get(CANDIDATE_MESSAGE_METHODS); - if ((handlerMethods.size() == 1 && handlerMessageMethods.isEmpty()) || - (handlerMessageMethods.size() == 1 && handlerMethods.isEmpty())) { - if (handlerMethods.size() == 1) { - this.handlerMethod = handlerMethods.values().iterator().next(); + Map, HandlerMethod> methods = handlerMethodsForTarget.get(CANDIDATE_METHODS); + Map, HandlerMethod> messageMethods = handlerMethodsForTarget.get(CANDIDATE_MESSAGE_METHODS); + if ((methods.size() == 1 && messageMethods.isEmpty()) || + (messageMethods.size() == 1 && methods.isEmpty())) { + if (methods.size() == 1) { + this.handlerMethod = methods.values().iterator().next(); } else { - this.handlerMethod = handlerMessageMethods.values().iterator().next(); + this.handlerMethod = messageMethods.values().iterator().next(); } this.handlerMethods = null; this.handlerMessageMethods = null; @@ -383,8 +384,8 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator } else { this.handlerMethod = null; - this.handlerMethods = handlerMethods; - this.handlerMessageMethods = handlerMessageMethods; + this.handlerMethods = methods; + this.handlerMessageMethods = messageMethods; this.handlerMethodsList = new LinkedList<>(); //TODO Consider to use global option to determine a precedence of methods @@ -440,12 +441,13 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator private boolean canReturnExpectedType(AnnotatedMethodFilter filter, Class targetType, TypeConverter typeConverter) { + if (this.expectedType == null) { return true; } List methods = filter.filter(Arrays.asList(ReflectionUtils.getAllDeclaredMethods(targetType))); - for (Method method : methods) { - if (typeConverter.canConvert(TypeDescriptor.valueOf(method.getReturnType()), this.expectedType)) { + for (Method candidate : methods) { + if (typeConverter.canConvert(TypeDescriptor.valueOf(candidate.getReturnType()), this.expectedType)) { return true; } } @@ -687,10 +689,10 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator } private Map, HandlerMethod>> findHandlerMethodsForTarget(final Object targetObject, - final Class annotationType, final String methodNameToUse, + final Class annotationType, final String methodNameArg, final boolean requiresReply) { - Map, HandlerMethod>> handlerMethods = new HashMap<>(); + Map, HandlerMethod>> methods = new HashMap<>(); final Map, HandlerMethod> candidateMethods = new HashMap<>(); final Map, HandlerMethod> candidateMessageMethods = new HashMap<>(); @@ -700,21 +702,21 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator final AtomicReference> ambiguousFallbackMessageGenericType = new AtomicReference<>(); final Class targetClass = getTargetClass(targetObject); - final String methodName; + final String methodNameToUse; - if (methodNameToUse == null) { + if (methodNameArg == null) { if (Function.class.isAssignableFrom(targetClass)) { - methodName = "apply"; + methodNameToUse = "apply"; } else if (Consumer.class.isAssignableFrom(targetClass)) { - methodName = "accept"; + methodNameToUse = "accept"; } else { - methodName = null; + methodNameToUse = null; } } else { - methodName = methodNameToUse; + methodNameToUse = methodNameArg; } @@ -739,10 +741,10 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator if (requiresReply && void.class.equals(method1.getReturnType())) { return; } - if (methodName != null && !methodName.equals(method1.getName())) { + if (methodNameToUse != null && !methodNameToUse.equals(method1.getName())) { return; } - if (methodName == null + if (methodNameToUse == null && ObjectUtils.containsElement(new String[] { "start", "stop", "isRunning" }, method1.getName())) { return; } @@ -820,14 +822,14 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator if (candidateMethods.isEmpty() && candidateMessageMethods.isEmpty() && fallbackMethods.isEmpty() && fallbackMessageMethods.isEmpty()) { - findSingleSpecifMethodOnInterfacesIfProxy(targetObject, methodName, candidateMessageMethods, + findSingleSpecifMethodOnInterfacesIfProxy(targetObject, methodNameToUse, candidateMessageMethods, candidateMethods); } if (!candidateMethods.isEmpty() || !candidateMessageMethods.isEmpty()) { - handlerMethods.put(CANDIDATE_METHODS, candidateMethods); - handlerMethods.put(CANDIDATE_MESSAGE_METHODS, candidateMessageMethods); - return handlerMethods; + methods.put(CANDIDATE_METHODS, candidateMethods); + methods.put(CANDIDATE_MESSAGE_METHODS, candidateMessageMethods); + return methods; } if ((ambiguousFallbackType.get() != null || ambiguousFallbackMessageGenericType.get() != null) @@ -855,16 +857,16 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator } } if (frameworkMethods.size() == 1) { - Method method = org.springframework.util.ClassUtils.getMostSpecificMethod(frameworkMethods.get(0), - targetObject.getClass()); + Method frameworkMethod = org.springframework.util.ClassUtils.getMostSpecificMethod( + frameworkMethods.get(0), targetObject.getClass()); InvocableHandlerMethod invocableHandlerMethod = this.messageHandlerMethodFactory.createInvocableHandlerMethod(targetObject, - method); - HandlerMethod handlerMethod = new HandlerMethod(invocableHandlerMethod, this.canProcessMessageList); - checkSpelInvokerRequired(targetClass, method, handlerMethod); - handlerMethods.put(CANDIDATE_METHODS, Collections.singletonMap(Object.class, handlerMethod)); - handlerMethods.put(CANDIDATE_MESSAGE_METHODS, candidateMessageMethods); - return handlerMethods; + frameworkMethod); + HandlerMethod theHandlerMethod = new HandlerMethod(invocableHandlerMethod, this.canProcessMessageList); + checkSpelInvokerRequired(targetClass, frameworkMethod, theHandlerMethod); + methods.put(CANDIDATE_METHODS, Collections.singletonMap(Object.class, theHandlerMethod)); + methods.put(CANDIDATE_MESSAGE_METHODS, candidateMessageMethods); + return methods; } } @@ -880,9 +882,9 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator + "] for method match: " + fallbackMethods.values()); - handlerMethods.put(CANDIDATE_METHODS, fallbackMethods); - handlerMethods.put(CANDIDATE_MESSAGE_METHODS, fallbackMessageMethods); - return handlerMethods; + methods.put(CANDIDATE_METHODS, fallbackMethods); + methods.put(CANDIDATE_MESSAGE_METHODS, fallbackMessageMethods); + return methods; } private void findSingleSpecifMethodOnInterfacesIfProxy(final Object targetObject, final String methodName, @@ -909,15 +911,15 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator .getMostSpecificMethod(theMethod, targetObject.getClass()); InvocableHandlerMethod invocableHandlerMethod = this.messageHandlerMethodFactory.createInvocableHandlerMethod(targetObject, theMethod); - HandlerMethod handlerMethod = new HandlerMethod(invocableHandlerMethod, this.canProcessMessageList); - checkSpelInvokerRequired(targetClass.get(), theMethod, handlerMethod); - Class targetParameterType = handlerMethod.getTargetParameterType(); - if (handlerMethod.isMessageMethod()) { + HandlerMethod theHandlerMethod = new HandlerMethod(invocableHandlerMethod, this.canProcessMessageList); + checkSpelInvokerRequired(targetClass.get(), theMethod, theHandlerMethod); + Class targetParameterType = theHandlerMethod.getTargetParameterType(); + if (theHandlerMethod.isMessageMethod()) { if (candidateMessageMethods.containsKey(targetParameterType)) { throw new IllegalArgumentException("Found more than one method match for type " + "[Message<" + targetParameterType + ">]"); } - candidateMessageMethods.put(targetParameterType, handlerMethod); + candidateMessageMethods.put(targetParameterType, theHandlerMethod); } else { if (candidateMethods.containsKey(targetParameterType)) { @@ -930,15 +932,15 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator } throw new IllegalArgumentException(exceptionMessage); } - candidateMethods.put(targetParameterType, handlerMethod); + candidateMethods.put(targetParameterType, theHandlerMethod); } } } } private void checkSpelInvokerRequired(final Class targetClass, Method methodArg, HandlerMethod handlerMethod) { - Method method = AopUtils.getMostSpecificMethod(methodArg, targetClass); - UseSpelInvoker useSpel = AnnotationUtils.findAnnotation(method, UseSpelInvoker.class); + UseSpelInvoker useSpel = AnnotationUtils.findAnnotation(AopUtils.getMostSpecificMethod(methodArg, targetClass), + UseSpelInvoker.class); if (useSpel == null) { useSpel = AnnotationUtils.findAnnotation(targetClass, UseSpelInvoker.class); } @@ -1019,14 +1021,14 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator } private HandlerMethod findClosestMatch(Class payloadType) { - for (Map, HandlerMethod> handlerMethods : this.handlerMethodsList) { - Set> candidates = handlerMethods.keySet(); + for (Map, HandlerMethod> methods : this.handlerMethodsList) { + Set> candidates = methods.keySet(); Class match = null; if (!CollectionUtils.isEmpty(candidates)) { match = ClassUtils.findClosestMatch(payloadType, candidates, true); } if (match != null) { - return handlerMethods.get(match); + return methods.get(match); } } return null; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java index 719831f5ef..58adec4c76 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -118,16 +118,16 @@ public class MessageHistoryConfigurer implements SmartLifecycle, BeanFactoryAwar Assert.notNull(componentNamePatternsSet, "'componentNamePatternsSet' must not be null"); Assert.state(!this.running, "'componentNamePatternsSet' cannot be changed without invoking stop() first"); for (String s : componentNamePatternsSet) { - String[] componentNamePatterns = StringUtils.delimitedListToStringArray(s, ",", " "); - Arrays.sort(componentNamePatterns); + String[] patterns = StringUtils.delimitedListToStringArray(s, ",", " "); + Arrays.sort(patterns); if (this.componentNamePatternsExplicitlySet - && !Arrays.equals(this.componentNamePatterns, componentNamePatterns)) { + && !Arrays.equals(this.componentNamePatterns, patterns)) { throw new BeanDefinitionValidationException("When more than one message history definition " + "(@EnableMessageHistory or )" + " is found in the context, they all must have the same 'componentNamePatterns'"); } else { - this.componentNamePatterns = componentNamePatterns; + this.componentNamePatterns = patterns; this.componentNamePatternsExplicitlySet = true; } } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java b/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java index 9092aa5bff..e570a69806 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -396,39 +396,39 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand * representing the bits that were set in the chmod value. */ BitSet bits = BitSet.valueOf(new byte[] { (byte) chmod, (byte) (chmod >> 8) }); - final Set permissions = new HashSet<>(); + final Set posixPermissions = new HashSet<>(); bits.stream().forEach(b -> { switch (b) { case 0: - permissions.add(PosixFilePermission.OTHERS_EXECUTE); + posixPermissions.add(PosixFilePermission.OTHERS_EXECUTE); break; case 1: - permissions.add(PosixFilePermission.OTHERS_WRITE); + posixPermissions.add(PosixFilePermission.OTHERS_WRITE); break; case 2: - permissions.add(PosixFilePermission.OTHERS_READ); + posixPermissions.add(PosixFilePermission.OTHERS_READ); break; case 3: - permissions.add(PosixFilePermission.GROUP_EXECUTE); + posixPermissions.add(PosixFilePermission.GROUP_EXECUTE); break; case 4: - permissions.add(PosixFilePermission.GROUP_WRITE); + posixPermissions.add(PosixFilePermission.GROUP_WRITE); break; case 5: - permissions.add(PosixFilePermission.GROUP_READ); + posixPermissions.add(PosixFilePermission.GROUP_READ); break; case 6: - permissions.add(PosixFilePermission.OWNER_EXECUTE); + posixPermissions.add(PosixFilePermission.OWNER_EXECUTE); break; case 7: - permissions.add(PosixFilePermission.OWNER_WRITE); + posixPermissions.add(PosixFilePermission.OWNER_WRITE); break; case 8: - permissions.add(PosixFilePermission.OWNER_READ); + posixPermissions.add(PosixFilePermission.OWNER_READ); break; } }); - this.permissions = permissions; + this.permissions = posixPermissions; } /** diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/HeadDirectoryScanner.java b/spring-integration-file/src/main/java/org/springframework/integration/file/HeadDirectoryScanner.java index e27f5e91a8..c7cb4e4005 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/HeadDirectoryScanner.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/HeadDirectoryScanner.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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. @@ -38,9 +38,8 @@ public class HeadDirectoryScanner extends DefaultDirectoryScanner { private final HeadFilter headFilter; public HeadDirectoryScanner(int maxNumberOfFiles) { - HeadFilter headFilter = new HeadFilter(maxNumberOfFiles); - this.headFilter = headFilter; - this.setFilter(headFilter); + this.headFilter = new HeadFilter(maxNumberOfFiles); + setFilter(this.headFilter); } @Override diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterFactoryBean.java b/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterFactoryBean.java index a9f4a45c72..6bdd90f9db 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterFactoryBean.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -63,7 +63,7 @@ public class FileTailInboundChannelAdapterFactoryBean extends AbstractFactoryBea private volatile Boolean reopen; - private volatile FileTailingMessageProducerSupport adapter; + private volatile FileTailingMessageProducerSupport tailAdapter; private volatile String beanName; @@ -158,40 +158,40 @@ public class FileTailInboundChannelAdapterFactoryBean extends AbstractFactoryBea @Override public void start() { - if (this.adapter != null) { - this.adapter.start(); + if (this.tailAdapter != null) { + this.tailAdapter.start(); } } @Override public void stop() { - if (this.adapter != null) { - this.adapter.stop(); + if (this.tailAdapter != null) { + this.tailAdapter.stop(); } } @Override public boolean isRunning() { - return this.adapter != null && this.adapter.isRunning(); + return this.tailAdapter != null && this.tailAdapter.isRunning(); } @Override public int getPhase() { - if (this.adapter != null) { - return this.adapter.getPhase(); + if (this.tailAdapter != null) { + return this.tailAdapter.getPhase(); } return 0; } @Override public boolean isAutoStartup() { - return this.adapter != null && this.adapter.isAutoStartup(); + return this.tailAdapter != null && this.tailAdapter.isAutoStartup(); } @Override public void stop(Runnable callback) { - if (this.adapter != null) { - this.adapter.stop(callback); + if (this.tailAdapter != null) { + this.tailAdapter.stop(callback); } else { callback.run(); @@ -200,7 +200,7 @@ public class FileTailInboundChannelAdapterFactoryBean extends AbstractFactoryBea @Override public Class getObjectType() { - return this.adapter == null ? FileTailingMessageProducerSupport.class : this.adapter.getClass(); + return this.tailAdapter == null ? FileTailingMessageProducerSupport.class : this.tailAdapter.getClass(); } @Override @@ -256,7 +256,7 @@ public class FileTailInboundChannelAdapterFactoryBean extends AbstractFactoryBea adapter.setBeanFactory(getBeanFactory()); // NOSONAR never null } adapter.afterPropertiesSet(); - this.adapter = adapter; + this.tailAdapter = adapter; return adapter; } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java index b25eecc9d1..1ef050e45d 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java @@ -239,19 +239,18 @@ public class RemoteFileTemplate implements RemoteFileOperations, Initializ @Override public void afterPropertiesSet() { - BeanFactory beanFactory = this.beanFactory; - if (beanFactory != null) { + if (this.beanFactory != null) { if (this.directoryExpressionProcessor != null) { - this.directoryExpressionProcessor.setBeanFactory(beanFactory); + this.directoryExpressionProcessor.setBeanFactory(this.beanFactory); } if (this.temporaryDirectoryExpressionProcessor != null) { - this.temporaryDirectoryExpressionProcessor.setBeanFactory(beanFactory); + this.temporaryDirectoryExpressionProcessor.setBeanFactory(this.beanFactory); } if (!this.fileNameGeneratorSet && this.fileNameGenerator instanceof BeanFactoryAware) { - ((BeanFactoryAware) this.fileNameGenerator).setBeanFactory(beanFactory); + ((BeanFactoryAware) this.fileNameGenerator).setBeanFactory(this.beanFactory); } if (this.fileNameProcessor != null) { - this.fileNameProcessor.setBeanFactory(beanFactory); + this.fileNameProcessor.setBeanFactory(this.beanFactory); } } if (this.autoCreateDirectory) { diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java index 3afcd43fd6..8fd74bdfc1 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -891,11 +891,11 @@ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReply } File localFile = new File(generateLocalDirectory(message, remoteDir), generateLocalFileName(message, remoteFilename)); - FileExistsMode fileExistsMode = this.fileExistsMode; - boolean appending = FileExistsMode.APPEND.equals(fileExistsMode); + FileExistsMode existsMode = this.fileExistsMode; + boolean appending = FileExistsMode.APPEND.equals(existsMode); boolean exists = localFile.exists(); - boolean replacing = FileExistsMode.REPLACE.equals(fileExistsMode) - || (exists && FileExistsMode.REPLACE_IF_MODIFIED.equals(fileExistsMode) + boolean replacing = FileExistsMode.REPLACE.equals(existsMode) + || (exists && FileExistsMode.REPLACE_IF_MODIFIED.equals(existsMode) && localFile.lastModified() != getModified(fileInfo)); if (!exists || appending || replacing) { OutputStream outputStream; @@ -939,7 +939,7 @@ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReply throw new MessagingException("Failed to rename local file"); } if (this.options.contains(Option.PRESERVE_TIMESTAMP) - || FileExistsMode.REPLACE_IF_MODIFIED.equals(fileExistsMode)) { + || FileExistsMode.REPLACE_IF_MODIFIED.equals(existsMode)) { localFile.setLastModified(getModified(fileInfo)); } if (this.options.contains(Option.DELETE)) { @@ -952,7 +952,7 @@ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReply } } } - else if (FileExistsMode.REPLACE_IF_MODIFIED.equals(fileExistsMode)) { + else if (FileExistsMode.REPLACE_IF_MODIFIED.equals(existsMode)) { if (logger.isDebugEnabled()) { logger.debug("Local file '" + localFile + "' has the same modified timestamp, ignored"); } @@ -960,7 +960,7 @@ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReply localFile = null; } } - else if (!FileExistsMode.IGNORE.equals(fileExistsMode)) { + else if (!FileExistsMode.IGNORE.equals(existsMode)) { throw new MessageHandlingException(message, "Local file " + localFile + " already exists"); } else { diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/CachingSessionFactory.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/CachingSessionFactory.java index 20445a7723..32fbfc03e0 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/CachingSessionFactory.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/CachingSessionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -153,7 +153,7 @@ public class CachingSessionFactory implements SessionFactory, DisposableBe if (this.isSharedSessionCapable && ((SharedSessionCapable) this.sessionFactory).isSharedSession()) { ((SharedSessionCapable) this.sessionFactory).resetSharedSession(); } - long sharedSessionEpoch = System.nanoTime(); + long epoch = System.nanoTime(); /* * Spin until we get a new value - nano precision but may be lower resolution. * We reset the epoch AFTER resetting the shared session so there is no possibility @@ -161,10 +161,10 @@ public class CachingSessionFactory implements SessionFactory, DisposableBe * that a "new" session might appear in the old epoch and thus be closed when returned to * the cache. */ - while (sharedSessionEpoch == this.sharedSessionEpoch) { - sharedSessionEpoch = System.nanoTime(); + while (epoch == this.sharedSessionEpoch) { + epoch = System.nanoTime(); } - this.sharedSessionEpoch = sharedSessionEpoch; + this.sharedSessionEpoch = epoch; this.pool.removeAllIdleItems(); } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/splitter/FileSplitter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/splitter/FileSplitter.java index 62529c1162..05e7fd9023 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/splitter/FileSplitter.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/splitter/FileSplitter.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2018 the original author or authors. + * Copyright 2015-2019 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. @@ -78,7 +78,7 @@ public class FileSplitter extends AbstractMessageSplitter { private static final JsonObjectMapper objectMapper = JsonObjectMapperProvider.jsonAvailable() ? JsonObjectMapperProvider.newInstance() : null; - private final boolean iterator; + private final boolean returnIterator; private final boolean markers; @@ -135,7 +135,7 @@ public class FileSplitter extends AbstractMessageSplitter { * @since 4.2.7 */ public FileSplitter(boolean iterator, boolean markers, boolean markersJson) { - this.iterator = iterator; + this.returnIterator = iterator; this.markers = markers; if (markers) { setApplySequence(false); @@ -359,7 +359,7 @@ public class FileSplitter extends AbstractMessageSplitter { }; - if (this.iterator) { + if (this.returnIterator) { return iterator; } else { diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/tail/ApacheCommonsFileTailingMessageProducer.java b/spring-integration-file/src/main/java/org/springframework/integration/file/tail/ApacheCommonsFileTailingMessageProducer.java index d51309e462..d7e5f26f66 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/tail/ApacheCommonsFileTailingMessageProducer.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/tail/ApacheCommonsFileTailingMessageProducer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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. @@ -71,9 +71,9 @@ public class ApacheCommonsFileTailingMessageProducer extends FileTailingMessageP @Override protected void doStart() { super.doStart(); - Tailer tailer = new Tailer(this.getFile(), this, this.pollingDelay, this.end, this.reopen); - this.getTaskExecutor().execute(tailer); - this.tailer = tailer; + Tailer theTailer = new Tailer(this.getFile(), this, this.pollingDelay, this.end, this.reopen); + this.getTaskExecutor().execute(theTailer); + this.tailer = theTailer; } @Override diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/tail/FileTailingMessageProducerSupport.java b/spring-integration-file/src/main/java/org/springframework/integration/file/tail/FileTailingMessageProducerSupport.java index 4785b145c1..97f8d82a48 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/tail/FileTailingMessageProducerSupport.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/tail/FileTailingMessageProducerSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -149,11 +149,11 @@ public abstract class FileTailingMessageProducerSupport extends MessageProducerS this.idleEventScheduledFuture = getTaskScheduler().scheduleWithFixedDelay(() -> { long now = System.currentTimeMillis(); long lastAlertAt = this.lastNoMessageAlert.get(); - long lastProduce = this.lastProduce; - if (now > lastProduce + this.idleEventInterval + long lastSend = this.lastProduce; + if (now > lastSend + this.idleEventInterval && now > lastAlertAt + this.idleEventInterval && this.lastNoMessageAlert.compareAndSet(lastAlertAt, now)) { - publishIdleEvent(now - lastProduce); + publishIdleEvent(now - lastSend); } }, this.idleEventInterval); } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/tail/OSDelegatingFileTailingMessageProducer.java b/spring-integration-file/src/main/java/org/springframework/integration/file/tail/OSDelegatingFileTailingMessageProducer.java index 23997a550b..b57f19a08e 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/tail/OSDelegatingFileTailingMessageProducer.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/tail/OSDelegatingFileTailingMessageProducer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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. @@ -39,7 +39,7 @@ import org.springframework.util.Assert; public class OSDelegatingFileTailingMessageProducer extends FileTailingMessageProducerSupport implements SchedulingAwareRunnable { - private volatile Process process; + private volatile Process nativeTailProcess; private volatile String options = "-F -n 0"; @@ -47,7 +47,7 @@ public class OSDelegatingFileTailingMessageProducer extends FileTailingMessagePr private volatile boolean enableStatusReader = true; - private volatile BufferedReader reader; + private volatile BufferedReader stdOutReader; public void setOptions(String options) { if (options == null) { @@ -103,10 +103,10 @@ public class OSDelegatingFileTailingMessageProducer extends FileTailingMessagePr } private void destroyProcess() { - Process process = this.process; + Process process = this.nativeTailProcess; if (process != null) { process.destroy(); - this.process = null; + this.nativeTailProcess = null; } } @@ -121,12 +121,12 @@ public class OSDelegatingFileTailingMessageProducer extends FileTailingMessagePr try { Process process = Runtime.getRuntime().exec(this.command); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); - this.process = process; + this.nativeTailProcess = process; this.startProcessMonitor(); if (this.enableStatusReader) { startStatusReader(); } - this.reader = reader; + this.stdOutReader = reader; this.getTaskExecutor().execute(this); } catch (IOException e) { @@ -140,7 +140,7 @@ public class OSDelegatingFileTailingMessageProducer extends FileTailingMessagePr */ private void startProcessMonitor() { this.getTaskExecutor().execute(() -> { - Process process = OSDelegatingFileTailingMessageProducer.this.process; + Process process = OSDelegatingFileTailingMessageProducer.this.nativeTailProcess; if (process == null) { if (logger.isDebugEnabled()) { logger.debug("Process destroyed before starting process monitor"); @@ -181,7 +181,7 @@ public class OSDelegatingFileTailingMessageProducer extends FileTailingMessagePr * (file not available, rotations etc) are sent to stderr. */ private void startStatusReader() { - Process process = this.process; + Process process = this.nativeTailProcess; if (process == null) { if (logger.isDebugEnabled()) { logger.debug("Process destroyed before starting stderr reader"); @@ -230,7 +230,7 @@ public class OSDelegatingFileTailingMessageProducer extends FileTailingMessagePr if (logger.isDebugEnabled()) { logger.debug("Reading stdout"); } - while ((line = this.reader.readLine()) != null) { + while ((line = this.stdOutReader.readLine()) != null) { this.send(line); } } @@ -239,7 +239,7 @@ public class OSDelegatingFileTailingMessageProducer extends FileTailingMessagePr logger.debug("Exception on tail reader", e); } try { - this.reader.close(); + this.stdOutReader.close(); } catch (IOException e1) { if (logger.isDebugEnabled()) { diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileSplitterParserTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileSplitterParserTests.java index aa6712c0a6..bd58927461 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileSplitterParserTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileSplitterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-2019 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. @@ -60,7 +60,7 @@ public class FileSplitterParserTests { @Test public void testComplete() { - assertFalse(TestUtils.getPropertyValue(this.splitter, "iterator", Boolean.class)); + assertFalse(TestUtils.getPropertyValue(this.splitter, "returnIterator", Boolean.class)); assertTrue(TestUtils.getPropertyValue(this.splitter, "markers", Boolean.class)); assertTrue(TestUtils.getPropertyValue(this.splitter, "markersJson", Boolean.class)); assertTrue(TestUtils.getPropertyValue(this.splitter, "requiresReply", Boolean.class)); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java index c6c4f27470..8e0dc76c38 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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. @@ -95,7 +95,7 @@ public class FileTailingMessageProducerTests { public void testOS() throws Exception { OSDelegatingFileTailingMessageProducer adapter = new OSDelegatingFileTailingMessageProducer(); adapter.setOptions(TAIL_OPTIONS_FOLLOW_NAME_ALL_LINES); - testGuts(adapter, "reader"); + testGuts(adapter, "stdOutReader"); } @Test diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/gateway/FtpOutboundGateway.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/gateway/FtpOutboundGateway.java index 87b0e7bc9f..11b5032fbf 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/gateway/FtpOutboundGateway.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/gateway/FtpOutboundGateway.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -261,15 +261,15 @@ public class FtpOutboundGateway extends AbstractRemoteFileOutboundGateway V doInWorkingDirectory(Message message, Session session, Callable task) throws IOException { - Expression workingDirExpression = this.workingDirExpression; + Expression workDirExpression = this.workingDirExpression; FTPClient ftpClient = (FTPClient) session.getClientInstance(); String currentWorkingDirectory = null; boolean restoreWorkingDirectory = false; try { - if (workingDirExpression != null) { + if (workDirExpression != null) { currentWorkingDirectory = ftpClient.printWorkingDirectory(); String newWorkingDirectory = - workingDirExpression.getValue(this.evaluationContext, message, String.class); + workDirExpression.getValue(this.evaluationContext, message, String.class); if (!Objects.equals(currentWorkingDirectory, newWorkingDirectory)) { ftpClient.changeWorkingDirectory(newWorkingDirectory); restoreWorkingDirectory = true; diff --git a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/GroovyScriptExecutingMessageProcessor.java b/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/GroovyScriptExecutingMessageProcessor.java index 7268a0c020..1eb0ce4c9a 100644 --- a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/GroovyScriptExecutingMessageProcessor.java +++ b/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/GroovyScriptExecutingMessageProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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. @@ -145,13 +145,13 @@ public class GroovyScriptExecutingMessageProcessor extends AbstractScriptExecuti ((ConfigurableListableBeanFactory) this.beanFactory).ignoreDependencyType(MetaClass.class); } - CompilerConfiguration compilerConfiguration = this.compilerConfiguration; - if (compilerConfiguration == null && this.compileStatic) { - compilerConfiguration = new CompilerConfiguration(); - compilerConfiguration.addCompilationCustomizers(new ASTTransformationCustomizer(CompileStatic.class)); + CompilerConfiguration compilerConfig = this.compilerConfiguration; + if (compilerConfig == null && this.compileStatic) { + compilerConfig = new CompilerConfiguration(); + compilerConfig.addCompilationCustomizers(new ASTTransformationCustomizer(CompileStatic.class)); } - this.groovyClassLoader = new GroovyClassLoader(this.beanClassLoader, compilerConfiguration); + this.groovyClassLoader = new GroovyClassLoader(this.beanClassLoader, compilerConfig); } @Override diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/HttpRequestHandlingEndpointSupport.java b/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/HttpRequestHandlingEndpointSupport.java index 9b929e4271..415fa7e5be 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/HttpRequestHandlingEndpointSupport.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/HttpRequestHandlingEndpointSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -222,12 +222,12 @@ public abstract class HttpRequestHandlingEndpointSupport extends BaseHttpInbound BeanFactory beanFactory = getBeanFactory(); if (this.multipartResolver == null && beanFactory != null) { try { - MultipartResolver multipartResolver = beanFactory.getBean( + MultipartResolver resolver = beanFactory.getBean( DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME, MultipartResolver.class); if (logger.isDebugEnabled()) { - logger.debug("Using MultipartResolver [" + multipartResolver + "]"); + logger.debug("Using MultipartResolver [" + resolver + "]"); } - this.multipartResolver = multipartResolver; + this.multipartResolver = resolver; } catch (NoSuchBeanDefinitionException e) { if (logger.isDebugEnabled()) { diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/config/TcpConnectionFactoryFactoryBean.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/config/TcpConnectionFactoryFactoryBean.java index 8e9c699cb7..07d2aba916 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/config/TcpConnectionFactoryFactoryBean.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/config/TcpConnectionFactoryFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -157,20 +157,19 @@ public class TcpConnectionFactoryFactoryBean extends AbstractFactoryBean message) throws Exception { - DatagramSocket socket; + DatagramSocket datagramSocket; if (this.socketExpression != null) { - socket = this.socketExpression.getValue(this.evaluationContext, message, DatagramSocket.class); + datagramSocket = this.socketExpression.getValue(this.evaluationContext, message, DatagramSocket.class); } else { - socket = getSocket(); + datagramSocket = getSocket(); } SocketAddress destinationAddress; if (this.destinationExpression != null) { @@ -353,7 +353,7 @@ public class UnicastSendingMessageHandler extends DatagramPacket packet = this.mapper.fromMessage(message); if (packet != null) { packet.setSocketAddress(destinationAddress); - socket.send(packet); + datagramSocket.send(packet); if (logger.isDebugEnabled()) { logger.debug("Sent packet for message " + message + " to " + packet.getSocketAddress()); } @@ -463,9 +463,9 @@ public class UnicastSendingMessageHandler extends * @return the ackPort */ public int getAckPort() { - DatagramSocket socket = this.socket; - if (this.ackPort == 0 && socket != null) { - return socket.getLocalPort(); + DatagramSocket datagramSocket = this.socket; + if (this.ackPort == 0 && datagramSocket != null) { + return datagramSocket.getLocalPort(); } else { return this.ackPort; diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/JdbcPollingChannelAdapter.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/JdbcPollingChannelAdapter.java index 84c75f5ce0..22dfa1d6f2 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/JdbcPollingChannelAdapter.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/JdbcPollingChannelAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -101,10 +101,14 @@ public class JdbcPollingChannelAdapter extends AbstractMessageSource { }; this.selectQuery = selectQuery; + this.rowMapper = new ColumnMapRowMapper(); } public void setRowMapper(RowMapper rowMapper) { this.rowMapper = rowMapper; + if (rowMapper == null) { + this.rowMapper = new ColumnMapRowMapper(); + } } public void setUpdateSql(String updateSql) { @@ -187,13 +191,11 @@ public class JdbcPollingChannelAdapter extends AbstractMessageSource { } protected List doPoll(SqlParameterSource sqlQueryParameterSource) { - final RowMapper rowMapper = this.rowMapper == null ? new ColumnMapRowMapper() : this.rowMapper; - if (sqlQueryParameterSource != null) { - return this.jdbcOperations.query(this.selectQuery, sqlQueryParameterSource, rowMapper); + return this.jdbcOperations.query(this.selectQuery, sqlQueryParameterSource, this.rowMapper); } else { - return this.jdbcOperations.query(this.selectQuery, rowMapper); + return this.jdbcOperations.query(this.selectQuery, this.rowMapper); } } diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsMessageDrivenEndpoint.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsMessageDrivenEndpoint.java index 66ed29326a..7989804e60 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsMessageDrivenEndpoint.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsMessageDrivenEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -172,12 +172,12 @@ public class JmsMessageDrivenEndpoint extends MessageProducerSupport implements if (!this.listenerContainer.isActive()) { this.listenerContainer.afterPropertiesSet(); } - String sessionAcknowledgeMode = this.sessionAcknowledgeMode; - if (sessionAcknowledgeMode == null && !this.externalContainer + String sessionAckeMode = this.sessionAcknowledgeMode; + if (sessionAckeMode == null && !this.externalContainer && DefaultMessageListenerContainer.class.isAssignableFrom(this.listenerContainer.getClass())) { - sessionAcknowledgeMode = JmsAdapterUtils.SESSION_TRANSACTED_STRING; + sessionAckeMode = JmsAdapterUtils.SESSION_TRANSACTED_STRING; } - Integer acknowledgeMode = JmsAdapterUtils.parseAcknowledgeMode(sessionAcknowledgeMode); + Integer acknowledgeMode = JmsAdapterUtils.parseAcknowledgeMode(sessionAckeMode); if (acknowledgeMode != null) { if (JmsAdapterUtils.SESSION_TRANSACTED == acknowledgeMode) { this.listenerContainer.setSessionTransacted(true); diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java index ad4a3b6314..9e84b1483d 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -123,7 +123,7 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp private volatile long timeToLive = javax.jms.Message.DEFAULT_TIME_TO_LIVE; - private volatile int priority = javax.jms.Message.DEFAULT_PRIORITY; + private volatile int defaultPriority = javax.jms.Message.DEFAULT_PRIORITY; private volatile boolean explicitQosEnabled; @@ -302,13 +302,30 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp } /** - * Specify the JMS priority to use when sending request Messages. + * Specify the default JMS priority to use when sending request Messages with + * no {@link IntegrationMessageHeaderAccessor#PRIORITY} header. + * * The value should be within the range of 0-9. * * @param priority The priority. + * @deprecated in favor of {@link #setDefaultPriority(int)}. */ + @Deprecated public void setPriority(int priority) { - this.priority = priority; + this.defaultPriority = priority; + } + + /** + * Specify the default JMS priority to use when sending request Messages with + * no {@link IntegrationMessageHeaderAccessor#PRIORITY} header. + * + * The value should be within the range of 0-9. + * + * @param priority The priority. + * @since 5.1.2 + */ + public void setDefaultPriority(int priority) { + this.defaultPriority = priority; } /** @@ -826,9 +843,9 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp Integer priority = new IntegrationMessageHeaderAccessor(requestMessage).getPriority(); if (priority == null) { - priority = this.priority; + priority = this.defaultPriority; } - Destination requestDestination = this.determineRequestDestination(requestMessage, session); + Destination destination = determineRequestDestination(requestMessage, session); Object reply = null; if (this.correlationKey == null) { @@ -837,10 +854,10 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp * (it will be restored in the reply by normal ARPMH header processing). */ jmsRequest.setJMSCorrelationID(null); - reply = doSendAndReceiveAsyncDefaultCorrelation(requestDestination, jmsRequest, session, priority); + reply = doSendAndReceiveAsyncDefaultCorrelation(destination, jmsRequest, session, priority); } else { - reply = doSendAndReceiveAsync(requestDestination, jmsRequest, session, priority); + reply = doSendAndReceiveAsync(destination, jmsRequest, session, priority); } /* * Remove the gateway's internal correlation Id to avoid conflicts with an upstream @@ -883,20 +900,20 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp Integer priority = new IntegrationMessageHeaderAccessor(requestMessage).getPriority(); if (priority == null) { - priority = this.priority; + priority = this.defaultPriority; } javax.jms.Message replyMessage = null; - Destination requestDestination = this.determineRequestDestination(requestMessage, session); + Destination destination = this.determineRequestDestination(requestMessage, session); if (this.correlationKey != null) { - replyMessage = doSendAndReceiveWithGeneratedCorrelationId(requestDestination, jmsRequest, replyTo, + replyMessage = doSendAndReceiveWithGeneratedCorrelationId(destination, jmsRequest, replyTo, session, priority); } else if (replyTo instanceof TemporaryQueue || replyTo instanceof TemporaryTopic) { - replyMessage = doSendAndReceiveWithTemporaryReplyToDestination(requestDestination, jmsRequest, replyTo, + replyMessage = doSendAndReceiveWithTemporaryReplyToDestination(destination, jmsRequest, replyTo, session, priority); } else { - replyMessage = doSendAndReceiveWithMessageIdCorrelation(requestDestination, jmsRequest, replyTo, + replyMessage = doSendAndReceiveWithMessageIdCorrelation(destination, jmsRequest, replyTo, session, priority); } return replyMessage; @@ -920,15 +937,15 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp Assert.state(this.correlationKey != null, "correlationKey must not be null"); String messageSelector = null; if (!this.correlationKey.equals("JMSCorrelationID*") || jmsRequest.getJMSCorrelationID() == null) { - String correlationId = UUID.randomUUID().toString().replaceAll("'", "''"); + String correlation = UUID.randomUUID().toString().replaceAll("'", "''"); if (this.correlationKey.equals("JMSCorrelationID")) { - jmsRequest.setJMSCorrelationID(correlationId); - messageSelector = "JMSCorrelationID = '" + correlationId + "'"; + jmsRequest.setJMSCorrelationID(correlation); + messageSelector = "JMSCorrelationID = '" + correlation + "'"; } else { - jmsRequest.setStringProperty(this.correlationKey, correlationId); + jmsRequest.setStringProperty(this.correlationKey, correlation); jmsRequest.setJMSCorrelationID(null); - messageSelector = this.correlationKey + " = '" + correlationId + "'"; + messageSelector = this.correlationKey + " = '" + correlation + "'"; } } else { @@ -1064,16 +1081,17 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp private Object doSendAndReceiveAsync(Destination requestDestination, javax.jms.Message jmsRequest, Session session, int priority) throws JMSException { - String correlationId = null; + + String correlation = null; MessageProducer messageProducer = null; try { messageProducer = session.createProducer(requestDestination); - correlationId = this.gatewayCorrelation + "_" + Long.toString(this.correlationId.incrementAndGet()); + correlation = this.gatewayCorrelation + "_" + Long.toString(this.correlationId.incrementAndGet()); if (this.correlationKey.equals("JMSCorrelationID")) { - jmsRequest.setJMSCorrelationID(correlationId); + jmsRequest.setJMSCorrelationID(correlation); } else { - jmsRequest.setStringProperty(this.correlationKey, correlationId); + jmsRequest.setStringProperty(this.correlationKey, correlation); /* * Remove any existing correlation id that was mapped from the inbound message * (it will be restored in the reply by normal ARPMH header processing). @@ -1082,16 +1100,16 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp } LinkedBlockingQueue replyQueue = null; if (logger.isDebugEnabled()) { - logger.debug(this.getComponentName() + " Sending message with correlationId " + correlationId); + logger.debug(this.getComponentName() + " Sending message with correlationId " + correlation); } SettableListenableFuture> future = null; boolean async = isAsync(); if (!async) { replyQueue = new LinkedBlockingQueue(1); - this.replies.put(correlationId, replyQueue); + this.replies.put(correlation, replyQueue); } else { - future = createFuture(correlationId); + future = createFuture(correlation); } this.sendRequestMessage(jmsRequest, messageProducer, priority); @@ -1100,20 +1118,21 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp return future; } else { - return obtainReplyFromContainer(correlationId, replyQueue); + return obtainReplyFromContainer(correlation, replyQueue); } } finally { JmsUtils.closeMessageProducer(messageProducer); - if (correlationId != null && !isAsync()) { - this.replies.remove(correlationId); + if (correlation != null && !isAsync()) { + this.replies.remove(correlation); } } } private javax.jms.Message doSendAndReceiveAsyncDefaultCorrelation(Destination requestDestination, javax.jms.Message jmsRequest, Session session, int priority) throws JMSException { - String correlationId = null; + + String correlation = null; MessageProducer messageProducer = null; try { @@ -1122,32 +1141,32 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp this.sendRequestMessage(jmsRequest, messageProducer, priority); - correlationId = jmsRequest.getJMSMessageID(); + correlation = jmsRequest.getJMSMessageID(); if (logger.isDebugEnabled()) { - logger.debug(this.getComponentName() + " Sent message with correlationId " + correlationId); + logger.debug(this.getComponentName() + " Sent message with correlationId " + correlation); } - this.replies.put(correlationId, replyQueue); + this.replies.put(correlation, replyQueue); /* * Check to see if the reply arrived before we obtained the correlationId */ synchronized (this.earlyOrLateReplies) { - TimedReply timedReply = this.earlyOrLateReplies.remove(correlationId); + TimedReply timedReply = this.earlyOrLateReplies.remove(correlation); if (timedReply != null) { if (logger.isDebugEnabled()) { - logger.debug("Found early reply with correlationId " + correlationId); + logger.debug("Found early reply with correlationId " + correlation); } replyQueue.add(timedReply.getReply()); } } - return obtainReplyFromContainer(correlationId, replyQueue); + return obtainReplyFromContainer(correlation, replyQueue); } finally { JmsUtils.closeMessageProducer(messageProducer); - if (correlationId != null) { - this.replies.remove(correlationId); + if (correlation != null) { + this.replies.remove(correlation); } } } @@ -1266,7 +1285,7 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp @Override public void onMessage(javax.jms.Message message) { - String correlationId = null; + String correlation = null; try { if (logger.isTraceEnabled()) { logger.trace(this.getComponentName() + " Received " + message); @@ -1274,22 +1293,22 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp if (this.correlationKey == null || this.correlationKey.equals("JMSCorrelationID") || this.correlationKey.equals("JMSCorrelationID*")) { - correlationId = message.getJMSCorrelationID(); + correlation = message.getJMSCorrelationID(); } else { - correlationId = message.getStringProperty(this.correlationKey); + correlation = message.getStringProperty(this.correlationKey); } - Assert.state(correlationId != null, "Message with no correlationId received"); + Assert.state(correlation != null, "Message with no correlationId received"); if (isAsync()) { - onMessageAsync(message, correlationId); + onMessageAsync(message, correlation); } else { - onMessageSync(message, correlationId); + onMessageSync(message, correlation); } } catch (Exception e) { if (logger.isWarnEnabled()) { - logger.warn("Failed to consume reply with correlationId " + correlationId, e); + logger.warn("Failed to consume reply with correlationId " + correlation, e); } } } diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsSendingMessageHandler.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsSendingMessageHandler.java index 4dc3180702..54eee09944 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsSendingMessageHandler.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsSendingMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -157,7 +157,6 @@ public class JmsSendingMessageHandler extends AbstractMessageHandler { @Override protected void handleMessageInternal(final Message message) { - Object destination = this.determineDestination(message); Object objectToSend = (this.extractPayload) ? message.getPayload() : message; MessagePostProcessor messagePostProcessor = new HeaderMappingMessagePostProcessor(message, this.headerMapper); @@ -182,7 +181,7 @@ public class JmsSendingMessageHandler extends AbstractMessageHandler { } } try { - send(destination, objectToSend, messagePostProcessor); + send(determineDestination(message), objectToSend, messagePostProcessor); } finally { DynamicJmsTemplateProperties.clearPriority(); diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsChannelFactoryBean.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsChannelFactoryBean.java index 8029aa2074..e3bc9320af 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsChannelFactoryBean.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsChannelFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -64,7 +64,7 @@ public class JmsChannelFactoryBean extends AbstractFactoryBean containerType; @@ -375,8 +375,8 @@ public class JmsChannelFactoryBean extends AbstractFactoryBean objectNames = this.retrieveMBeanNames(); if (objectNames.size() < 1) { this.logger.error("No MBeans found matching ObjectName pattern(s): " + - Arrays.asList(this.objectNames)); + Arrays.asList(this.mBeanObjectNames)); } for (ObjectName objectName : objectNames) { this.server.addNotificationListener(objectName, this, this.filter, this.handback); @@ -182,7 +182,7 @@ public class NotificationListeningMessageProducer extends MessageProducerSupport @Override protected void doStop() { this.logger.debug("Unregistering notifications"); - if (this.server != null && this.objectNames != null) { + if (this.server != null && this.mBeanObjectNames != null) { Collection objectNames = this.retrieveMBeanNames(); for (ObjectName objectName : objectNames) { try { @@ -203,7 +203,7 @@ public class NotificationListeningMessageProducer extends MessageProducerSupport protected Collection retrieveMBeanNames() { List objectNames = new ArrayList(); - for (ObjectName pattern : this.objectNames) { + for (ObjectName pattern : this.mBeanObjectNames) { Set mBeanInfos; try { mBeanInfos = this.server.queryMBeans(pattern, null); diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/OperationInvokingMessageHandler.java b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/OperationInvokingMessageHandler.java index f808845ed8..7ab2d461f6 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/OperationInvokingMessageHandler.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/OperationInvokingMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -65,7 +65,7 @@ public class OperationInvokingMessageHandler extends AbstractReplyProducingMessa private volatile MBeanServerConnection server; - private volatile ObjectName objectName; + private volatile ObjectName defaultObjectName; private volatile String operationName; @@ -88,7 +88,7 @@ public class OperationInvokingMessageHandler extends AbstractReplyProducingMessa public void setObjectName(String objectName) { try { if (objectName != null) { - this.objectName = ObjectNameManager.getInstance(objectName); + this.defaultObjectName = ObjectNameManager.getInstance(objectName); } } catch (MalformedObjectNameException e) { @@ -118,15 +118,15 @@ public class OperationInvokingMessageHandler extends AbstractReplyProducingMessa @Override protected Object handleRequestMessage(Message requestMessage) { - ObjectName objectName = this.resolveObjectName(requestMessage); - String operationName = this.resolveOperationName(requestMessage); + ObjectName objectName = resolveObjectName(requestMessage); + String operation = resolveOperationName(requestMessage); Map paramsFromMessage = this.resolveParameters(requestMessage); try { MBeanInfo mbeanInfo = this.server.getMBeanInfo(objectName); MBeanOperationInfo[] opInfoArray = mbeanInfo.getOperations(); boolean hasNoArgOption = false; for (MBeanOperationInfo opInfo : opInfoArray) { - if (operationName.equals(opInfo.getName())) { + if (operation.equals(opInfo.getName())) { MBeanParameterInfo[] paramInfoArray = opInfo.getSignature(); if (paramInfoArray.length == 0) { hasNoArgOption = true; @@ -152,21 +152,21 @@ public class OperationInvokingMessageHandler extends AbstractReplyProducingMessa } } if (index == paramInfoArray.length) { - return this.server.invoke(objectName, operationName, values, signature); + return this.server.invoke(objectName, operation, values, signature); } } } } if (hasNoArgOption) { - return this.server.invoke(objectName, operationName, null, null); + return this.server.invoke(objectName, operation, null, null); } throw new MessagingException(requestMessage, "failed to find JMX operation '" - + operationName + "' on MBean [" + objectName + "] of type [" + mbeanInfo.getClassName() + + operation + "' on MBean [" + objectName + "] of type [" + mbeanInfo.getClassName() + "] with " + paramsFromMessage.size() + " parameters: " + paramsFromMessage); } catch (JMException e) { throw new MessageHandlingException(requestMessage, "failed to invoke JMX operation '" + - operationName + "' on MBean [" + objectName + "]" + " with " + + operation + "' on MBean [" + objectName + "]" + " with " + paramsFromMessage.size() + " parameters: " + paramsFromMessage, e); } catch (IOException e) { @@ -189,7 +189,7 @@ public class OperationInvokingMessageHandler extends AbstractReplyProducingMessa * First checks if defaultObjectName is set, otherwise falls back on {@link JmxHeaders#OBJECT_NAME} header. */ private ObjectName resolveObjectName(Message message) { - ObjectName objectName = this.objectName; + ObjectName objectName = this.defaultObjectName; if (objectName == null) { Object objectNameHeader = message.getHeaders().get(JmxHeaders.OBJECT_NAME); if (objectNameHeader instanceof ObjectName) { @@ -212,12 +212,12 @@ public class OperationInvokingMessageHandler extends AbstractReplyProducingMessa * First checks if defaultOperationName is set, otherwise falls back on {@link JmxHeaders#OPERATION_NAME} header. */ private String resolveOperationName(Message message) { - String operationName = this.operationName; - if (operationName == null) { - operationName = message.getHeaders().get(JmxHeaders.OPERATION_NAME, String.class); + String operation = this.operationName; + if (operation == null) { + operation = message.getHeaders().get(JmxHeaders.OPERATION_NAME, String.class); } - Assert.notNull(operationName, "Failed to resolve operation name."); - return operationName; + Assert.notNull(operation, "Failed to resolve operation name."); + return operation; } @SuppressWarnings({ "unchecked", "rawtypes" }) diff --git a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/JpaExecutor.java b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/JpaExecutor.java index c171a0f4c5..4c2dc4d9e4 100644 --- a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/JpaExecutor.java +++ b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/JpaExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -429,18 +429,18 @@ public class JpaExecutor implements InitializingBean, BeanFactoryAware { final Object result; - ParameterSource parameterSource = null; + ParameterSource paramSource = null; if (this.jpaQuery != null || this.nativeQuery != null || this.namedQuery != null) { - parameterSource = determineParameterSource(message); + paramSource = determineParameterSource(message); } if (this.jpaQuery != null) { - result = this.jpaOperations.executeUpdate(this.jpaQuery, parameterSource); + result = this.jpaOperations.executeUpdate(this.jpaQuery, paramSource); } else if (this.nativeQuery != null) { - result = this.jpaOperations.executeUpdateWithNativeQuery(this.nativeQuery, parameterSource); + result = this.jpaOperations.executeUpdateWithNativeQuery(this.nativeQuery, paramSource); } else if (this.namedQuery != null) { - result = this.jpaOperations.executeUpdateWithNamedQuery(this.namedQuery, parameterSource); + result = this.jpaOperations.executeUpdateWithNamedQuery(this.namedQuery, paramSource); } else { switch (this.persistMode) { @@ -492,11 +492,11 @@ public class JpaExecutor implements InitializingBean, BeanFactoryAware { if (this.idExpression != null) { Object id = this.idExpression.getValue(this.evaluationContext, requestMessage); // NOSONAR It can be null Assert.state(id != null, "The 'idExpression' cannot evaluate to null."); - Class entityClass = this.entityClass; - if (entityClass == null && requestMessage != null) { - entityClass = requestMessage.getPayload().getClass(); + Class entityClazz = this.entityClass; + if (entityClazz == null && requestMessage != null) { + entityClazz = requestMessage.getPayload().getClass(); } - payload = this.jpaOperations.find(entityClass, id); + payload = this.jpaOperations.find(entityClazz, id); } else { final List result; @@ -624,14 +624,12 @@ public class JpaExecutor implements InitializingBean, BeanFactoryAware { } private ParameterSource determineParameterSource(final Message requestMessage) { - ParameterSource parameterSource; if (this.usePayloadAsParameterSource) { - parameterSource = this.parameterSourceFactory.createParameterSource(requestMessage.getPayload()); + return this.parameterSourceFactory.createParameterSource(requestMessage.getPayload()); } else { - parameterSource = this.parameterSourceFactory.createParameterSource(requestMessage); + return this.parameterSourceFactory.createParameterSource(requestMessage); } - return parameterSource; } }