Skip to content

Commit

Permalink
AMQP Sonar Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
garyrussell committed Oct 26, 2018
1 parent 7702a6f commit 1555a13
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 15 deletions.
Expand Up @@ -23,6 +23,7 @@
import org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.integration.amqp.inbound.AmqpMessageSource.AmqpAckCallbackFactory;
import org.springframework.lang.Nullable;

/**
* Factory class for AMQP components.
Expand Down Expand Up @@ -278,7 +279,9 @@ public static AmqpPollableMessageChannelSpec<?> pollableChannel(ConnectionFactor
* @param connectionFactory the connectionFactory.
* @return the AmqpPollableMessageChannelSpec.
*/
public static AmqpPollableMessageChannelSpec<?> pollableChannel(String id, ConnectionFactory connectionFactory) {
public static AmqpPollableMessageChannelSpec<?> pollableChannel(@Nullable String id,
ConnectionFactory connectionFactory) {

return new AmqpPollableMessageChannelSpec<>(connectionFactory)
.id(id);
}
Expand All @@ -298,7 +301,7 @@ public static AmqpMessageChannelSpec<?> channel(ConnectionFactory connectionFact
* @param connectionFactory the connectionFactory.
* @return the AmqpMessageChannelSpec.
*/
public static AmqpMessageChannelSpec<?> channel(String id, ConnectionFactory connectionFactory) {
public static AmqpMessageChannelSpec<?> channel(@Nullable String id, ConnectionFactory connectionFactory) {
return new AmqpMessageChannelSpec<>(connectionFactory)
.id(id);
}
Expand All @@ -318,7 +321,7 @@ public static AmqpPublishSubscribeMessageChannelSpec publishSubscribeChannel(Con
* @param connectionFactory the connectionFactory.
* @return the AmqpPublishSubscribeMessageChannelSpec.
*/
public static AmqpPublishSubscribeMessageChannelSpec publishSubscribeChannel(String id,
public static AmqpPublishSubscribeMessageChannelSpec publishSubscribeChannel(@Nullable String id,
ConnectionFactory connectionFactory) {

return new AmqpPublishSubscribeMessageChannelSpec(connectionFactory).id(id);
Expand Down
Expand Up @@ -159,7 +159,7 @@ public String getComponentType() {

@Override
protected AbstractIntegrationMessageBuilder<Object> doReceive() {
Connection connection = this.connectionFactory.createConnection();
Connection connection = this.connectionFactory.createConnection(); // NOSONAR - RabbitUtils
Channel channel = connection.createChannel(this.transacted);
try {
GetResponse resp = channel.basicGet(this.queue, false);
Expand Down
Expand Up @@ -307,7 +307,7 @@ public void setErrorMessageStrategy(ErrorMessageStrategy errorMessageStrategy) {
this.errorMessageStrategy = errorMessageStrategy;
}

protected final void setConnectionFactory(ConnectionFactory connectionFactory) {
protected synchronized final void setConnectionFactory(ConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}

Expand Down
Expand Up @@ -51,7 +51,12 @@ public ErrorMessage buildErrorMessage(Throwable throwable, @Nullable AttributeAc
: context.getAttribute(ErrorMessageUtils.INPUT_MESSAGE_CONTEXT_KEY);
Map<String, Object> headers = context == null ? new HashMap<String, Object>() :
Collections.singletonMap(AMQP_RAW_MESSAGE, context.getAttribute(AMQP_RAW_MESSAGE));
return new ErrorMessage(throwable, headers, inputMessage instanceof Message ? (Message<?>) inputMessage : null);
if (inputMessage instanceof Message) {
return new ErrorMessage(throwable, headers, (Message<?>) inputMessage);
}
else {
return new ErrorMessage(throwable, headers);
}
}

}
Expand Up @@ -46,6 +46,7 @@
import org.springframework.integration.support.management.metrics.SampleFacade;
import org.springframework.integration.support.management.metrics.TimerFacade;
import org.springframework.integration.support.utils.IntegrationUtils;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageDeliveryException;
Expand Down Expand Up @@ -620,8 +621,9 @@ public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
}
}

public void afterSendCompletion(Message<?> message, MessageChannel channel, boolean sent, Exception ex,
Deque<ChannelInterceptor> interceptorStack) {
public void afterSendCompletion(Message<?> message, MessageChannel channel, boolean sent,
@Nullable Exception ex, Deque<ChannelInterceptor> interceptorStack) {

for (Iterator<ChannelInterceptor> iterator = interceptorStack.descendingIterator(); iterator.hasNext(); ) {
ChannelInterceptor interceptor = iterator.next();
try {
Expand Down Expand Up @@ -658,8 +660,9 @@ public Message<?> postReceive(Message<?> message, MessageChannel channel) {
return message;
}

public void afterReceiveCompletion(Message<?> message, MessageChannel channel, Exception ex,
Deque<ChannelInterceptor> interceptorStack) {
public void afterReceiveCompletion(@Nullable Message<?> message, MessageChannel channel,
@Nullable Exception ex, Deque<ChannelInterceptor> interceptorStack) {

for (Iterator<ChannelInterceptor> iterator = interceptorStack.descendingIterator(); iterator.hasNext(); ) {
ChannelInterceptor interceptor = iterator.next();
try {
Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.springframework.integration.support;

import org.springframework.core.AttributeAccessor;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.ErrorMessage;

Expand All @@ -36,7 +37,7 @@
public class DefaultErrorMessageStrategy implements ErrorMessageStrategy {

@Override
public ErrorMessage buildErrorMessage(Throwable throwable, AttributeAccessor attributes) {
public ErrorMessage buildErrorMessage(Throwable throwable, @Nullable AttributeAccessor attributes) {
Object inputMessage = attributes == null ? null
: attributes.getAttribute(ErrorMessageUtils.INPUT_MESSAGE_CONTEXT_KEY);
return new ErrorMessage(throwable, inputMessage instanceof Message ? (Message<?>) inputMessage : null);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
package org.springframework.integration.support;

import org.springframework.core.AttributeAccessor;
import org.springframework.lang.Nullable;
import org.springframework.messaging.support.ErrorMessage;

/**
Expand Down Expand Up @@ -44,6 +45,6 @@ public interface ErrorMessageStrategy {
* @param attributes the attributes.
* @return the ErrorMessage.
*/
ErrorMessage buildErrorMessage(Throwable payload, AttributeAccessor attributes);
ErrorMessage buildErrorMessage(Throwable payload, @Nullable AttributeAccessor attributes);

}
@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,7 @@

import org.springframework.core.AttributeAccessor;
import org.springframework.core.AttributeAccessorSupport;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;

/**
Expand Down Expand Up @@ -49,7 +50,9 @@ private ErrorMessageUtils() {
* @param failedMessage the failed message.
* @return the context.
*/
public static AttributeAccessor getAttributeAccessor(Message<?> inputMessage, Message<?> failedMessage) {
public static AttributeAccessor getAttributeAccessor(@Nullable Message<?> inputMessage,
@Nullable Message<?> failedMessage) {

AttributeAccessorSupport attributes = new ErrorMessageAttributes();
if (inputMessage != null) {
attributes.setAttribute(INPUT_MESSAGE_CONTEXT_KEY, inputMessage);
Expand Down

0 comments on commit 1555a13

Please sign in to comment.