Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Feature/AppConfig as PropertySource #652

Open
wants to merge 74 commits into
base: 2.3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
a6e7c73
Fix AwsSecretsManagerProperties.prefix javadoc
sixcorners Aug 20, 2019
d52dae1
Bumping versions
spring-builds Jan 20, 2020
33e1535
Bumping versions
spring-builds Jan 21, 2020
328b130
Updated docs
marcingrzejszczak Apr 1, 2020
9294f1c
Merge branch '2.2.x'
spencergibb Apr 22, 2020
5ac4cdb
Bumps versions to 3.0.0-SNAPHOT
spencergibb Apr 22, 2020
6d84666
Merge pull request #484 from sixcorners/patch-1
maciejwalkowiak May 29, 2020
e540b7c
Update of documentation regarding supported DB engines that Amazon RD…
DJakosa Mar 27, 2019
37b1251
Fix "Sending a message" reference documentation code samples.
luramarchanjo May 30, 2020
c935e72
Fixes SNS auto configuration when Spring WebMvc is not on the classpath.
kingbbode May 1, 2020
5f5d8bc
Remove the misleading property in documentation of spring-cloud-aws-rds.
SenthilPanneerselvam Apr 22, 2020
e805878
Rename config properties in ContextCredentialsAutoConfiguration to ke…
lukasznyrc Jun 18, 2019
4c11014
Add tests for relaxed binding support in "cloud.aws.credentials".
tac-yacht Mar 28, 2020
6e3f32d
Allow ConditionalOnAwsCloudEnvironment to be used on method level.
bsamartins Mar 13, 2019
e72a3d2
Set CloudWatchProperties default batch size to API max.
bsamartins Mar 14, 2019
159200b
Add option to use default AWS region provider chain.
maciejwalkowiak May 31, 2020
f6100dd
Add logging to AWSParameterStorePropertySource.
cschroedl-gov Feb 27, 2020
6da9925
Update documentation on how to hide warning message logged by AWS SDK…
maciejwalkowiak May 31, 2020
8caf811
Fix typo in the exception text
tmnuwan12 May 31, 2020
7a052a5
Bump AWS Java SDK dependency version to 1.11.792.
maciejwalkowiak May 31, 2020
f2ab807
Update reference documentation on how to upgrade AWS SDK dependency.
maciejwalkowiak May 31, 2020
58e636d
Fix S3 object key encoding in `SimpleStorageResource.getURL`.
Jun 1, 2020
deb9088
Fix duplicate error logging when processing exception thrown in SQS l…
sayembd Mar 29, 2019
76df24c
Allow to specify PropertySource name returned by AwsSecretsManagerPro…
cbm-afoulfoin Jun 25, 2019
eb4d65a
Add a dependency to JUnit 4.
maciejwalkowiak Jun 6, 2020
f61178d
Document default credentials chain for auto-configuration.
maciejwalkowiak Jun 6, 2020
211990c
Add CloudWatch integration documentation to the reference.
maciejwalkowiak Jun 6, 2020
2a59abf
Add a method to get S3 URI from a SimpleStorageResource.
tmnuwan12 Jun 6, 2020
647375b
Fix StackResourceRegistry creation when CloudFormation support is tur…
maciejwalkowiak Jun 7, 2020
38c7e6a
Drop XML support in all modules and integration tests.
maciejwalkowiak Jun 1, 2020
8af3aca
Changed packaging to jar
marcingrzejszczak Jun 8, 2020
6a7580b
Remove Autowired annotations
eddumelendez Jun 7, 2020
80391e9
Enforce spring-javaformat plugin
eddumelendez Jun 9, 2020
650cc69
Use DefaultAWSCredentialsProvider and DefaultAWSRegionProviderChain b…
maciejwalkowiak Jun 8, 2020
68799fb
Migrate to JUnit 5.
DarrenForsythe Jun 8, 2020
0c84250
Merge branch '2.3.x'
eddumelendez Jun 12, 2020
11e5078
Merge branch '2.3.x'
eddumelendez Jun 12, 2020
7817a37
Configure SQS to use existing ObjectMapper if present in application …
maciejwalkowiak Jun 12, 2020
ddde60b
Drop dependency to javax.validation in Parameter Store and Secrets Ma…
MatejNedic Jun 8, 2020
dea203b
Merge branch '2.3.x'
maciejwalkowiak Jun 17, 2020
babe84f
Merge branch '2.3.x'
maciejwalkowiak Jun 18, 2020
6148d73
Merge branch '2.3.x'
maciejwalkowiak Jun 18, 2020
fec66b9
Merge branch '2.3.x'
maciejwalkowiak Jun 19, 2020
eea7e8f
Merge branch '2.3.x'
maciejwalkowiak Jun 19, 2020
9e5c01c
Merge branch '2.3.x'
maciejwalkowiak Jun 19, 2020
045fd9c
Merge branch '2.3.x'
maciejwalkowiak Jun 20, 2020
582fdc6
Merge branch '2.3.x'
maciejwalkowiak Jun 21, 2020
53275a2
Merge branch '2.3.x'
maciejwalkowiak Jun 21, 2020
2f63fe3
Merge branch '2.3.x'
maciejwalkowiak Jun 26, 2020
2b26b92
Merge branch '2.3.x'
eddumelendez Jun 27, 2020
82a873c
Merge branch '2.3.x'
maciejwalkowiak Jul 7, 2020
7f01157
Merge branch '2.3.x'
eddumelendez Jul 8, 2020
ff28c4b
Update version
eddumelendez Jul 8, 2020
7244864
Merge branch '2.3.x'
eddumelendez Jul 8, 2020
fcbb893
Merge branch '2.3.x'
maciejwalkowiak Jul 8, 2020
26c5435
Merge branch '2.3.x'
eddumelendez Jul 9, 2020
6f67aeb
Merge branch '2.3.x'
eddumelendez Jul 13, 2020
e72fce9
Merge branch '2.3.x'
eddumelendez Jul 13, 2020
926a6ca
Merge branch '2.3.x'
maciejwalkowiak Jul 14, 2020
10d2b77
Merge branch '2.3.x'
maciejwalkowiak Jul 26, 2020
b506a9f
Merge branch '2.3.x'
maciejwalkowiak Aug 7, 2020
24b2068
Merge branch '2.3.x' into master
Aug 10, 2020
4d0b386
feat(aws-appconfig): add appconfig & starter-appconfig modules
jarpz Sep 7, 2020
7eba07c
feat(aws-appconfig): add aws appconfig component
jarpz Sep 7, 2020
241d6d3
feat(aws-appconfig): add starter appconfig
jarpz Sep 7, 2020
33d2559
feat(aws-appconfig): rename module removing config suffix
jarpz Sep 15, 2020
d21e4dc
feat(aws-appconfig): move classes & fix comments
jarpz Sep 15, 2020
ebd950e
feat(aws-appconfig): remove unused dependencies
jarpz Sep 16, 2020
c373eec
test(aws-appconfig): change tests to use ApplicationContextRunner
jarpz Sep 17, 2020
fd58ab1
feat(aws-appconfig): change properties prefix to spring.cloud.aws.* +…
jarpz Sep 22, 2020
2cbf279
feat(aws-appconfig): use assert when appName is empty or null
jarpz Sep 25, 2020
33d96f5
feat(aws-appconfig): rename accountId as clientId + allow default ran…
jarpz Nov 30, 2020
b2cad8d
Merge branch 'master' of https://github.com/jarpz/spring-cloud-aws in…
jarpz Nov 5, 2021
e3cfc4d
feat: Align code with master branch & fix code style
jarpz Nov 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Configure SQS to use existing ObjectMapper if present in application …
…context.

If ObjectMapper is not present, creates default Jackson ObjectMapper without the dependency to spring-web module.

Fixes gh-533
Fixes gh-522
Fixes gh-540
Closes gh-592
  • Loading branch information
maciejwalkowiak committed Jun 12, 2020
commit 7817a371ad911472901495d24fdf4a69add1c2b5
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2020 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 @@ -21,6 +21,7 @@

import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.AmazonSQSAsync;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.cloud.aws.core.env.ResourceIdResolver;
Expand Down Expand Up @@ -55,6 +56,8 @@ public class QueueMessageHandlerFactory {

private List<MessageConverter> messageConverters;

private ObjectMapper objectMapper;

public void setArgumentResolvers(
List<HandlerMethodArgumentResolver> argumentResolvers) {
this.argumentResolvers = argumentResolvers;
Expand Down Expand Up @@ -123,10 +126,20 @@ public void setBeanFactory(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}

/**
* Configures an {@link ObjectMapper} that is used by default
* {@link MappingJackson2MessageConverter} created if no {@link #messageConverters}
* are set.
* @param objectMapper - object mapper, can be null
*/
public void setObjectMapper(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}

public QueueMessageHandler createQueueMessageHandler() {
QueueMessageHandler queueMessageHandler = new QueueMessageHandler(
CollectionUtils.isEmpty(this.messageConverters)
? Arrays.asList(getDefaultMappingJackson2MessageConverter())
CollectionUtils.isEmpty(this.messageConverters) ? Arrays.asList(
getDefaultMappingJackson2MessageConverter(this.objectMapper))
: this.messageConverters);

if (!CollectionUtils.isEmpty(this.argumentResolvers)) {
Expand Down Expand Up @@ -159,7 +172,7 @@ public QueueMessageHandler createQueueMessageHandler() {
private QueueMessagingTemplate getDefaultSendToQueueMessagingTemplate(
AmazonSQSAsync amazonSqs, ResourceIdResolver resourceIdResolver) {
return new QueueMessagingTemplate(amazonSqs, resourceIdResolver,
getDefaultMappingJackson2MessageConverter());
getDefaultMappingJackson2MessageConverter(this.objectMapper));
}

public List<MessageConverter> getMessageConverters() {
Expand All @@ -176,10 +189,16 @@ public void setMessageConverters(List<MessageConverter> messageConverters) {
this.messageConverters = messageConverters;
}

private MappingJackson2MessageConverter getDefaultMappingJackson2MessageConverter() {
private MappingJackson2MessageConverter getDefaultMappingJackson2MessageConverter(
ObjectMapper objectMapper) {
MappingJackson2MessageConverter jacksonMessageConverter = new MappingJackson2MessageConverter();
jacksonMessageConverter.setSerializedPayloadClass(String.class);
jacksonMessageConverter.setStrictContentTypeMatch(true);

if (objectMapper != null) {
jacksonMessageConverter.setObjectMapper(objectMapper);
}

return jacksonMessageConverter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Arrays;

import com.amazonaws.services.sqs.AmazonSQSAsync;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ObjectProvider;
Expand Down Expand Up @@ -54,12 +55,15 @@ public class SqsConfiguration {

private final MappingJackson2MessageConverter mappingJackson2MessageConverter;

private final ObjectMapper objectMapper;

public SqsConfiguration(
ObjectProvider<SimpleMessageListenerContainerFactory> simpleMessageListenerContainerFactory,
ObjectProvider<QueueMessageHandlerFactory> queueMessageHandlerFactory,
BeanFactory beanFactory,
ObjectProvider<ResourceIdResolver> resourceIdResolver,
ObjectProvider<MappingJackson2MessageConverter> mappingJackson2MessageConverter) {
ObjectProvider<MappingJackson2MessageConverter> mappingJackson2MessageConverter,
ObjectProvider<ObjectMapper> objectMapper) {
this.simpleMessageListenerContainerFactory = simpleMessageListenerContainerFactory
.getIfAvailable(SimpleMessageListenerContainerFactory::new);
this.queueMessageHandlerFactory = queueMessageHandlerFactory
Expand All @@ -68,6 +72,7 @@ public SqsConfiguration(
this.resourceIdResolver = resourceIdResolver.getIfAvailable();
this.mappingJackson2MessageConverter = mappingJackson2MessageConverter
.getIfAvailable();
this.objectMapper = objectMapper.getIfAvailable();
}

@Bean
Expand Down Expand Up @@ -111,6 +116,7 @@ private QueueMessageHandler getMessageHandler(AmazonSQSAsync amazonSqs) {
}

this.queueMessageHandlerFactory.setBeanFactory(this.beanFactory);
this.queueMessageHandlerFactory.setObjectMapper(this.objectMapper);

return this.queueMessageHandlerFactory.createQueueMessageHandler();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2020 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 @@ -20,7 +20,6 @@
import java.util.List;
import java.util.Map;

import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessagingException;
Expand All @@ -33,7 +32,6 @@
import org.springframework.messaging.core.DestinationResolver;
import org.springframework.messaging.core.DestinationResolvingMessageSendingOperations;
import org.springframework.messaging.core.MessagePostProcessor;
import org.springframework.util.ClassUtils;

/**
* @param <D> message channel type
Expand All @@ -45,10 +43,6 @@ public abstract class AbstractMessageChannelMessagingSendingTemplate<D extends M
extends AbstractMessageSendingTemplate<D>
implements DestinationResolvingMessageSendingOperations<D> {

private static final boolean JACKSON_2_PRESENT = ClassUtils.isPresent(
"com.fasterxml.jackson.databind.ObjectMapper",
AbstractMessageChannelMessagingSendingTemplate.class.getClassLoader());

private final DestinationResolver<String> destinationResolver;

protected AbstractMessageChannelMessagingSendingTemplate(
Expand Down Expand Up @@ -120,10 +114,8 @@ protected void initMessageConverter(MessageConverter messageConverter) {
if (messageConverter != null) {
messageConverters.add(messageConverter);
}
else if (JACKSON_2_PRESENT) {
else {
MappingJackson2MessageConverter mappingJackson2MessageConverter = new MappingJackson2MessageConverter();
mappingJackson2MessageConverter
.setObjectMapper(Jackson2ObjectMapperBuilder.json().build());
mappingJackson2MessageConverter.setSerializedPayloadClass(String.class);
messageConverters.add(mappingJackson2MessageConverter);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2020 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.cloud.aws.messaging.config.annotation;

import java.util.Collections;
import java.util.List;

import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
Expand All @@ -25,6 +26,7 @@
import com.amazonaws.services.sqs.AmazonSQSAsync;
import com.amazonaws.services.sqs.AmazonSQSAsyncClient;
import com.amazonaws.services.sqs.buffered.AmazonSQSBufferedAsyncClient;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

import org.springframework.cloud.aws.context.config.annotation.EnableContextRegion;
Expand All @@ -40,6 +42,8 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
import org.springframework.messaging.converter.MessageConverter;
import org.springframework.messaging.core.DestinationResolver;
import org.springframework.messaging.core.DestinationResolvingMessageSendingOperations;
import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver;
Expand All @@ -52,6 +56,7 @@

/**
* @author Alain Sahli
* @author Maciej Walkowiak
*/
class SqsConfigurationTest {

Expand Down Expand Up @@ -194,6 +199,25 @@ void queueMessageHandlerBeanMustBeSetOnContainer() throws Exception {
"messageHandler")).isEqualTo(queueMessageHandler);
}

@Test
void configuration_withObjectMapper_shouldSetObjectMapperOnQueueMessageHandler()
throws Exception {
// Arrange & Act
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
ConfigurationWithObjectMapper.class);
QueueMessageHandler queueMessageHandler = applicationContext
.getBean(QueueMessageHandler.class);
ObjectMapper objectMapper = applicationContext.getBean(ObjectMapper.class);
List<MessageConverter> converters = (List<MessageConverter>) ReflectionTestUtils
.getField(queueMessageHandler, "messageConverters");
MappingJackson2MessageConverter mappingJackson2MessageConverter = (MappingJackson2MessageConverter) converters
.get(0);

// Assert
assertThat(mappingJackson2MessageConverter.getObjectMapper())
.isEqualTo(objectMapper);
}

@Test
void configuration_withoutAwsCredentials_shouldCreateAClientWithDefaultCredentialsProvider()
throws Exception {
Expand Down Expand Up @@ -375,4 +399,16 @@ static class ConfigurationWithRegionProvider {

}

@EnableSqs
@EnableContextRegion(region = "eu-west-1")
@Configuration(proxyBeanMethods = false)
static class ConfigurationWithObjectMapper {

@Bean
ObjectMapper objectMapper() {
return new ObjectMapper();
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.springframework.cloud.aws.messaging.core;

import java.io.IOException;
import java.time.LocalDate;
import java.util.Locale;

Expand All @@ -27,12 +26,10 @@
import com.amazonaws.services.sqs.model.ReceiveMessageResult;
import com.amazonaws.services.sqs.model.SendMessageRequest;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;

import org.springframework.cloud.aws.core.env.ResourceIdResolver;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.converter.CompositeMessageConverter;
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
Expand Down Expand Up @@ -205,72 +202,26 @@ void instantiation_withConverter_shouldAddItToTheCompositeConverter() {
// Assert
assertThat(
((CompositeMessageConverter) queueMessagingTemplate.getMessageConverter())
.getConverters().size()).isEqualTo(2);
.getConverters()).hasSize(2);
assertThat(
((CompositeMessageConverter) queueMessagingTemplate.getMessageConverter())
.getConverters().get(1)).isEqualTo(simpleMessageConverter);
}

@Test
void instantiation_WithCustomJacksonConverterThatSupportsJava8Types_shouldConvertMessageToString()
throws IOException {

// Arrange
AmazonSQSAsync amazonSqs = createAmazonSqs();

ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();

MappingJackson2MessageConverter simpleMessageConverter = new MappingJackson2MessageConverter();
simpleMessageConverter.setSerializedPayloadClass(String.class);
simpleMessageConverter.setObjectMapper(objectMapper);

QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate(
amazonSqs, (ResourceIdResolver) null, simpleMessageConverter);

void instantiation_withoutConverter_shouldAddDefaultJacksonConverterToTheCompositeConverter() {
// Act
queueMessagingTemplate.convertAndSend("test",
new TestPerson("Agim", "Emruli", LocalDate.of(2017, 1, 1)));

// Assert
ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor
.forClass(SendMessageRequest.class);
verify(amazonSqs).sendMessage(sendMessageRequestArgumentCaptor.capture());
TestPerson testPerson = objectMapper.readValue(
sendMessageRequestArgumentCaptor.getValue().getMessageBody(),
TestPerson.class);

assertThat(testPerson.getFirstName()).isEqualTo("Agim");
assertThat(testPerson.getLastName()).isEqualTo("Emruli");
assertThat(testPerson.getActiveSince()).isEqualTo(LocalDate.of(2017, 1, 1));
}

@Test
void instantiation_withDefaultMapping2JacksonConverter_shouldSupportJava8Types()
throws IOException {

// Arrange
AmazonSQSAsync amazonSqs = createAmazonSqs();

ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();

QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate(
amazonSqs);

// Act
queueMessagingTemplate.convertAndSend("test",
new TestPerson("Agim", "Emruli", LocalDate.of(2017, 1, 1)));
createAmazonSqs(), (ResourceIdResolver) null, null);

// Assert
ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor
.forClass(SendMessageRequest.class);
verify(amazonSqs).sendMessage(sendMessageRequestArgumentCaptor.capture());
TestPerson testPerson = objectMapper.readValue(
sendMessageRequestArgumentCaptor.getValue().getMessageBody(),
TestPerson.class);

assertThat(testPerson.getFirstName()).isEqualTo("Agim");
assertThat(testPerson.getLastName()).isEqualTo("Emruli");
assertThat(testPerson.getActiveSince()).isEqualTo(LocalDate.of(2017, 1, 1));
assertThat(
((CompositeMessageConverter) queueMessagingTemplate.getMessageConverter())
.getConverters()).hasSize(2);
assertThat(
((CompositeMessageConverter) queueMessagingTemplate.getMessageConverter())
.getConverters().get(1))
.isInstanceOf(MappingJackson2MessageConverter.class);
}

private AmazonSQSAsync createAmazonSqs() {
Expand Down