Add Javadoc and remove message converter from base class

Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
SirWayne
2016-03-01 08:37:50 +01:00
parent 895a78fee8
commit 5973413cbe
8 changed files with 46 additions and 49 deletions

View File

@@ -122,11 +122,11 @@ public class AmqpConfiguration {
/**
* Create amqp handler service bean.
*
* @return
* @return handler service bean
*/
@Bean
public AmqpMessageHandlerService amqpMessageHandlerService() {
return new AmqpMessageHandlerService(jsonMessageConverter(), rabbitTemplate);
return new AmqpMessageHandlerService(rabbitTemplate);
}
/**

View File

@@ -29,7 +29,6 @@ import org.eclipse.hawkbit.util.ArtifactUrlHandler;
import org.eclipse.hawkbit.util.IpUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
@@ -52,9 +51,15 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
@Autowired
private AmqpSenderService amqpSenderService;
/**
* Constructor.
*
* @param messageConverter
* message converter
*/
@Autowired
public AmqpMessageDispatcherService(final MessageConverter messageConverter, final RabbitTemplate defaultTemplate) {
super(messageConverter, defaultTemplate);
public AmqpMessageDispatcherService(final MessageConverter messageConverter) {
super(messageConverter);
}
/**

View File

@@ -49,7 +49,6 @@ import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.Cache;
@@ -97,16 +96,17 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
@Autowired
private HostnameResolver hostnameResolver;
private final RabbitTemplate internalAmqpTemplate;
/**
* Constructor.
*
* @param messageConverter
* the message converter.
* @param defaultTemplate
* the configured amqp template.
*/
public AmqpMessageHandlerService(final MessageConverter messageConverter, final RabbitTemplate defaultTemplate) {
super(messageConverter, defaultTemplate);
public AmqpMessageHandlerService(final RabbitTemplate defaultTemplate) {
super(defaultTemplate.getMessageConverter());
this.internalAmqpTemplate = defaultTemplate;
}
@RabbitListener(queues = "${hawkbit.dmf.rabbitmq.receiverQueue}", containerFactory = "listenerContainerFactory")
@@ -346,11 +346,6 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
return controllerManagement.addUpdateActionStatus(actionStatus, action);
}
/**
* @param message
* @param actionUpdateStatus
* @return
*/
private Action checkActionExist(final Message message, final ActionUpdateStatus actionUpdateStatus) {
final Long actionId = actionUpdateStatus.getActionId();
LOG.debug("Target notifies intermediate about action {} with status {}.", actionId,
@@ -383,17 +378,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
}
}
/**
* Is needed to verify if an incoming message has the content type json.
*
* @param message
* the to verify
* @param contentType
* the content type
* @return true if the content type has json, false it not.
*/
private static void checkContentTypeJson(final Message message) {
private void checkContentTypeJson(final Message message) {
final MessageProperties messageProperties = message.getMessageProperties();
if (messageProperties.getContentType() != null && messageProperties.getContentType().contains("json")) {
return;
@@ -409,14 +394,6 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
this.hostnameResolver = hostnameResolver;
}
void setMessageConverter(final MessageConverter messageConverter) {
this.messageConverter = messageConverter;
}
MessageConverter getMessageConverter() {
return messageConverter;
}
void setAuthenticationManager(final AmqpControllerAuthentfication authenticationManager) {
this.authenticationManager = authenticationManager;
}

View File

@@ -20,7 +20,7 @@ public interface AmqpSenderService {
/**
* Send the given message to the given uri. The uri contains the (virtual)
* host and exchange.
* host and exchange e.g amqp://host/exchange.
*
* @param message
* the amqp message

View File

@@ -16,7 +16,6 @@ import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.AbstractJavaTypeMapper;
import org.springframework.amqp.support.converter.MessageConverter;
@@ -28,14 +27,23 @@ public class BaseAmqpService {
private static final Logger LOGGER = LoggerFactory.getLogger(BaseAmqpService.class);
protected MessageConverter messageConverter;
protected RabbitTemplate internalAmqpTemplate;
public BaseAmqpService(final MessageConverter messageConverter, final RabbitTemplate defaultTemplate) {
/**
* Constructor.
*
* @param messageConverter
* the message messageConverter.
*/
public BaseAmqpService(final MessageConverter messageConverter) {
this.messageConverter = messageConverter;
internalAmqpTemplate = defaultTemplate;
}
protected void cleanMessage(final Message message) {
/**
* Clean message properties before sending a message.
*
* @param message
* the message to cleaned up
*/
protected void cleanMessageHeaderProperties(final Message message) {
message.getMessageProperties().getHeaders().remove(AbstractJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME);
}
@@ -46,7 +54,7 @@ public class BaseAmqpService {
* the message to convert.
* @param clazz
* the class of the originally object.
* @return
* @return the converted object
*/
@SuppressWarnings("unchecked")
protected <T> T convertMessage(final Message message, final Class<T> clazz) {
@@ -66,7 +74,7 @@ public class BaseAmqpService {
* the message to convert.
* @param clazz
* the class of the list content.
* @return
* @return the list of converted objects
*/
@SuppressWarnings("unchecked")
protected <T> List<T> convertMessageList(final Message message, final Class<T> clazz) {
@@ -80,7 +88,12 @@ public class BaseAmqpService {
return (List<T>) messageConverter.fromMessage(message);
}
protected String getStringHeaderKey(final Message message, final String key, final String errorMessageIfNull) {
public MessageConverter getMessageConverter() {
return messageConverter;
}
protected final String getStringHeaderKey(final Message message, final String key,
final String errorMessageIfNull) {
final Map<String, Object> header = message.getMessageProperties().getHeaders();
final Object value = header.get(key);
if (value == null) {
@@ -89,7 +102,7 @@ public class BaseAmqpService {
return value.toString();
}
protected void logAndThrowMessageError(final Message message, final String error) {
protected final void logAndThrowMessageError(final Message message, final String error) {
LOGGER.error("Error \"{}\" reported by message {}", error, message.getMessageProperties().getMessageId());
throw new IllegalArgumentException(error);
}

View File

@@ -61,7 +61,9 @@ public class AmqpControllerAuthentficationTest {
@Before
public void before() throws Exception {
messageConverter = new Jackson2JsonMessageConverter();
amqpMessageHandlerService = new AmqpMessageHandlerService(messageConverter, mock(RabbitTemplate.class));
final RabbitTemplate rabbitTemplate = mock(RabbitTemplate.class);
when(rabbitTemplate.getMessageConverter()).thenReturn(messageConverter);
amqpMessageHandlerService = new AmqpMessageHandlerService(rabbitTemplate);
authenticationManager = new AmqpControllerAuthentfication();
authenticationManager.setControllerManagement(mock(ControllerManagement.class));

View File

@@ -70,8 +70,7 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit
super.before();
this.rabbitTemplate = Mockito.mock(RabbitTemplate.class);
when(rabbitTemplate.getMessageConverter()).thenReturn(new Jackson2JsonMessageConverter());
amqpMessageDispatcherService = new AmqpMessageDispatcherService(new Jackson2JsonMessageConverter(),
rabbitTemplate);
amqpMessageDispatcherService = new AmqpMessageDispatcherService(new Jackson2JsonMessageConverter());
amqpMessageDispatcherService = spy(amqpMessageDispatcherService);
senderService = Mockito.mock(DefaultAmqpSenderService.class);

View File

@@ -105,7 +105,8 @@ public class AmqpMessageHandlerServiceTest {
@Before
public void before() throws Exception {
messageConverter = new Jackson2JsonMessageConverter();
amqpMessageHandlerService = new AmqpMessageHandlerService(messageConverter, rabbitTemplate);
when(rabbitTemplate.getMessageConverter()).thenReturn(messageConverter);
amqpMessageHandlerService = new AmqpMessageHandlerService(rabbitTemplate);
amqpMessageHandlerService.setControllerManagement(controllerManagementMock);
amqpMessageHandlerService.setAuthenticationManager(authenticationManagerMock);
amqpMessageHandlerService.setArtifactManagement(artifactManagementMock);