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. * Create amqp handler service bean.
* *
* @return * @return handler service bean
*/ */
@Bean @Bean
public AmqpMessageHandlerService amqpMessageHandlerService() { 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.eclipse.hawkbit.util.IpUtil;
import org.springframework.amqp.core.Message; import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.MessageConverter; import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -52,9 +51,15 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
@Autowired @Autowired
private AmqpSenderService amqpSenderService; private AmqpSenderService amqpSenderService;
/**
* Constructor.
*
* @param messageConverter
* message converter
*/
@Autowired @Autowired
public AmqpMessageDispatcherService(final MessageConverter messageConverter, final RabbitTemplate defaultTemplate) { public AmqpMessageDispatcherService(final MessageConverter messageConverter) {
super(messageConverter, defaultTemplate); super(messageConverter);
} }
/** /**

View File

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

View File

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

View File

@@ -61,7 +61,9 @@ public class AmqpControllerAuthentficationTest {
@Before @Before
public void before() throws Exception { public void before() throws Exception {
messageConverter = new Jackson2JsonMessageConverter(); 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 = new AmqpControllerAuthentfication();
authenticationManager.setControllerManagement(mock(ControllerManagement.class)); authenticationManager.setControllerManagement(mock(ControllerManagement.class));

View File

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

View File

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