Skip to content

Commit 71310c8

Browse files
authored
Merge branch 'master' into micronaut-flow-support
2 parents 2c7abce + 0e274fe commit 71310c8

File tree

29 files changed

+676
-351
lines changed

29 files changed

+676
-351
lines changed

aop/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ ext {
44
dependencies {
55
api project(':inject')
66
api project(':core')
7-
}
7+
}

benchmarks/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ jmh {
2727
iterations = 3
2828
fork = 1
2929
// jvmArgs = ["-agentpath:/Applications/YourKit-Java-Profiler-2018.04.app/Contents/Resources/bin/mac/libyjpagent.jnilib"]
30-
}
30+
}

build.gradle

+9-4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ ext {
9191
name : 'jackson-datatype-jdk8',
9292
modules: ['jackson-datatype-jsr310']
9393
],
94+
'jackson.dataformat' : [
95+
version : jacksonVersion,
96+
group : 'com.fasterxml.jackson.dataformat',
97+
modules : ['jackson-dataformat-xml'],
98+
],
9499
jaeger : [
95100
version: jaegerVersion,
96101
group : 'io.jaegertracing',
@@ -652,8 +657,8 @@ subprojects { Project subproject ->
652657

653658
tasks.withType(Test) {
654659
jvmArgs '-Duser.country=US', '-Duser.language=en', '-Xmx2048m'
655-
reports.html.enabled = !System.getenv("TRAVIS")
656-
reports.junitXml.enabled = !System.getenv("TRAVIS")
660+
reports.html.enabled = !System.getenv("GITHUB_ACTIONS")
661+
reports.junitXml.enabled = !System.getenv("GITHUB_ACTIONS")
657662
testLogging {
658663
exceptionFormat = 'full'
659664
}
@@ -667,8 +672,8 @@ subprojects { Project subproject ->
667672

668673
tasks.withType(Checkstyle) {
669674
reports {
670-
xml.enabled = !System.getenv("TRAVIS")
671-
html.enabled = !System.getenv("TRAVIS")
675+
xml.enabled = !System.getenv("GITHUB_ACTIONS")
676+
html.enabled = !System.getenv("GITHUB_ACTIONS")
672677
}
673678
}
674679

core/src/main/java/io/micronaut/core/annotation/AnnotationClassValue.java

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
@UsedByGeneratedCode
3434
public final class AnnotationClassValue<T> implements CharSequence, Named {
3535

36+
/**
37+
* An empty array of class values.
38+
*/
39+
public static final AnnotationClassValue<?>[] EMPTY_ARRAY = new AnnotationClassValue[0];
40+
3641
private final String name;
3742
private final Class<T> theClass;
3843
private final T instance;

core/src/main/java/io/micronaut/core/annotation/AnnotationValue.java

+30
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,36 @@ public Class<?>[] classValues(@Nonnull String member) {
358358
return ReflectionUtils.EMPTY_CLASS_ARRAY;
359359
}
360360

361+
@Nonnull
362+
@Override
363+
public AnnotationClassValue<?>[] annotationClassValues(@Nonnull String member) {
364+
if (StringUtils.isNotEmpty(member)) {
365+
Object o = values.get(member);
366+
if (o instanceof AnnotationClassValue) {
367+
return new AnnotationClassValue[] {(AnnotationClassValue) o};
368+
} else if (o instanceof AnnotationClassValue[]) {
369+
return (AnnotationClassValue<?>[]) o;
370+
}
371+
}
372+
return AnnotationClassValue.EMPTY_ARRAY;
373+
}
374+
375+
@Override
376+
public Optional<AnnotationClassValue<?>> annotationClassValue(@Nonnull String member) {
377+
if (StringUtils.isNotEmpty(member)) {
378+
Object o = values.get(member);
379+
if (o instanceof AnnotationClassValue) {
380+
return Optional.of((AnnotationClassValue<?>) o);
381+
} else if (o instanceof AnnotationClassValue[]) {
382+
AnnotationClassValue[] a = (AnnotationClassValue[]) o;
383+
if (a.length > 0) {
384+
return Optional.of(a[0]);
385+
}
386+
}
387+
}
388+
return Optional.empty();
389+
}
390+
361391
/**
362392
* The integer value of the given member.
363393
*

core/src/main/java/io/micronaut/core/annotation/AnnotationValueResolver.java

+20-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ default Optional<Class<?>> classValue() {
9090
/**
9191
* The value of the annotation as a Class.
9292
*
93-
* @return An {@link Optional} class
93+
* @return An array of classes
9494
*/
9595
@Nonnull
9696
default Class<?>[] classValues() {
@@ -101,10 +101,28 @@ default Class<?>[] classValues() {
101101
* The value of the given annotation member as a Class.
102102
*
103103
* @param member The annotation member
104-
* @return An {@link Optional} class
104+
* @return An array of classes
105105
*/
106106
@Nonnull Class<?>[] classValues(@Nonnull String member);
107107

108+
109+
/**
110+
* The {@link AnnotationClassValue} instances for the given member. Unlike {@link #classValues(String)} this may
111+
* include classes that are no the classpath.
112+
*
113+
* @param member The annotation member
114+
* @return An array of class values
115+
*/
116+
@Nonnull AnnotationClassValue<?>[] annotationClassValues(@Nonnull String member);
117+
118+
/**
119+
* The {@link AnnotationClassValue} instance for the given member.
120+
*
121+
* @param member The annotation member
122+
* @return An annotation class value
123+
*/
124+
Optional<AnnotationClassValue<?>> annotationClassValue(@Nonnull String member);
125+
108126
/**
109127
* The integer value of the given member.
110128
*

core/src/main/java/io/micronaut/core/convert/DefaultConversionService.java

+36-13
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,48 @@ public <T> Optional<T> convert(Object object, Class<T> targetType, ConversionCon
9898
return Optional.of((T) object);
9999
}
100100

101-
Optional<String> formattingAnn = context.getAnnotationMetadata().getAnnotationNameByStereotype(Format.class);
102-
String formattingAnnotation = formattingAnn.orElse(null);
103-
ConvertiblePair pair = new ConvertiblePair(sourceType, targetType, formattingAnnotation);
104-
TypeConverter typeConverter = converterCache.get(pair);
105-
if (typeConverter == null) {
106-
typeConverter = findTypeConverter(sourceType, targetType, formattingAnnotation);
101+
final AnnotationMetadata annotationMetadata = context.getAnnotationMetadata();
102+
if (annotationMetadata.hasStereotype(Format.class)) {
103+
Optional<String> formattingAnn = annotationMetadata.getAnnotationNameByStereotype(Format.class);
104+
String formattingAnnotation = formattingAnn.orElse(null);
105+
ConvertiblePair pair = new ConvertiblePair(sourceType, targetType, formattingAnnotation);
106+
TypeConverter typeConverter = converterCache.get(pair);
107107
if (typeConverter == null) {
108-
return Optional.empty();
109-
} else {
110-
converterCache.put(pair, typeConverter);
111-
if (typeConverter == UNCONVERTIBLE) {
108+
typeConverter = findTypeConverter(sourceType, targetType, formattingAnnotation);
109+
if (typeConverter == null) {
110+
return Optional.empty();
111+
} else {
112+
converterCache.put(pair, typeConverter);
113+
if (typeConverter == UNCONVERTIBLE) {
114+
return Optional.empty();
115+
} else {
116+
return typeConverter.convert(object, targetType, context);
117+
}
118+
}
119+
} else if (typeConverter != UNCONVERTIBLE) {
120+
return typeConverter.convert(object, targetType, context);
121+
}
122+
} else {
123+
ConvertiblePair pair = new ConvertiblePair(sourceType, targetType, null);
124+
TypeConverter typeConverter = converterCache.get(pair);
125+
if (typeConverter == null) {
126+
typeConverter = findTypeConverter(sourceType, targetType, null);
127+
if (typeConverter == null) {
128+
converterCache.put(pair, UNCONVERTIBLE);
112129
return Optional.empty();
113130
} else {
114-
return typeConverter.convert(object, targetType, context);
131+
converterCache.put(pair, typeConverter);
132+
if (typeConverter == UNCONVERTIBLE) {
133+
return Optional.empty();
134+
} else {
135+
return typeConverter.convert(object, targetType, context);
136+
}
115137
}
138+
} else if (typeConverter != UNCONVERTIBLE) {
139+
return typeConverter.convert(object, targetType, context);
116140
}
117-
} else if (typeConverter != UNCONVERTIBLE) {
118-
return typeConverter.convert(object, targetType, context);
119141
}
142+
120143
return Optional.empty();
121144
}
122145

discovery-client/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies {
1111
exclude module:'micronaut-inject'
1212
}
1313
compileOnly group: 'com.amazonaws', name: 'aws-java-sdk-route53', version: '1.11.683'
14-
compileOnly group: 'com.amazonaws', name: 'aws-java-sdk-core', version: '1.11.689'
14+
compileOnly group: 'com.amazonaws', name: 'aws-java-sdk-core', version: '1.11.696'
1515
compileOnly group: 'com.amazonaws', name: 'jmespath-java', version: '1.11.297'
1616
compileOnly group: 'com.amazonaws', name: 'aws-java-sdk-servicediscovery', version: '1.11.688'
1717

gradle.properties

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ micronautSpringVersion=1.0.2
3939
micronautGcpVersion=1.1.0
4040
micronautAwsVersion=1.3.5
4141
micronautCacheVersion=1.0.0.M1
42-
micronautGrpcVersion=1.1.0
42+
micronautGrpcVersion=1.1.1
4343
micronautOpenApi=1.3.1
4444
micronautRedisVersion=1.2.0
4545
micronautMongoVersion=1.2.0
4646
micronautNeo4jVersion=1.2.0
4747
micronautSqlVersion=1.3.0.RC1
48-
micronautViewsVersion=1.3.0.RC1
48+
micronautViewsVersion=1.3.0
4949
micronautMicrometerVersion=1.3.0
5050
micronautKafkaVersion=1.3.0
5151
micronautSecurityVersion=1.2.2
@@ -115,7 +115,7 @@ tomcatJdbcVersion=9.0.21
115115
liquibaseVersion=3.6.3
116116
flywayVersion=5.2.4
117117
jcacheVersion=1.1.0
118-
hibernateVersion=5.4.9.Final
118+
hibernateVersion=5.4.10.Final
119119
methvinDirectoryWatcherVersion=0.9.6
120120
jnaVersion=5.3.1
121121
elasticsearchVersion=6.4.0

gradle/publishing.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,4 @@ if (!project.version.endsWith("-SNAPSHOT")) {
279279
// disable remote publish for non-snapshot versions
280280
// since releases are published to bintray
281281
publishMavenPublicationToMavenRepository.enabled = false
282-
}
282+
}

http-client/src/main/java/io/micronaut/http/client/DefaultHttpClient.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ private <T> Flowable<T> connectWebSocket(URI uri, MutableHttpRequest<?> request,
767767
int maxFramePayloadLength = finalWebSocketBean.messageMethod()
768768
.map(m -> m.intValue(OnMessage.class, "maxPayloadLength")
769769
.orElse(65536)).orElse(65536);
770+
String subprotocol = finalWebSocketBean.getBeanDefinition().stringValue(ClientWebSocket.class, "subprotocol").orElse(StringUtils.EMPTY_STRING);
770771

771772
RequestKey requestKey;
772773
try {
@@ -809,12 +810,15 @@ protected void addFinalHandler(ChannelPipeline pipeline) {
809810
if (headers instanceof NettyHttpHeaders) {
810811
customHeaders = ((NettyHttpHeaders) headers).getNettyHeaders();
811812
}
813+
if (StringUtils.isNotEmpty(subprotocol)) {
814+
customHeaders.add("Sec-WebSocket-Protocol", subprotocol);
815+
}
812816

813817
webSocketHandler = new NettyWebSocketClientHandler<>(
814818
request,
815819
finalWebSocketBean,
816820
WebSocketClientHandshakerFactory.newHandshaker(
817-
webSocketURL, protocolVersion, null, false, customHeaders, maxFramePayloadLength),
821+
webSocketURL, protocolVersion, subprotocol, false, customHeaders, maxFramePayloadLength),
818822
requestBinderRegistry,
819823
mediaTypeCodecRegistry,
820824
emitter);

http-client/src/main/java/io/micronaut/http/client/interceptor/HttpClientIntroductionAdvice.java

+40-29
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import io.micronaut.inject.qualifiers.Qualifiers;
6262
import io.micronaut.jackson.ObjectMapperFactory;
6363
import io.micronaut.jackson.annotation.JacksonFeatures;
64+
import io.micronaut.jackson.codec.JacksonMediaTypeCodec;
6465
import io.micronaut.jackson.codec.JsonMediaTypeCodec;
6566
import io.micronaut.runtime.ApplicationConfiguration;
6667
import io.reactivex.Completable;
@@ -225,7 +226,7 @@ public Object intercept(MethodInvocationContext<Object, Object> context) {
225226
configuration.getParameters()
226227
.forEach(parameter -> queryParams.put(parameter, version));
227228
});
228-
229+
229230
Map<String, Object> attributes = new LinkedHashMap<>(ATTRIBUTES_INITIAL_CAPACITY);
230231

231232
List<AnnotationValue<RequestAttribute>> attributeAnnotations = context.getAnnotationValuesByType(RequestAttribute.class);
@@ -646,11 +647,11 @@ private HttpClient getClient(MethodInvocationContext<Object, Object> context, An
646647

647648
return clients.computeIfAbsent(clientKey, integer -> {
648649
HttpClient clientBean = beanContext.findBean(HttpClient.class, Qualifiers.byName(NameUtils.hyphenate(clientId))).orElse(null);
649-
AnnotationValue<JacksonFeatures> jacksonFeatures = context.findAnnotation(JacksonFeatures.class).orElse(null);
650+
AnnotationValue<JacksonFeatures> jacksonFeaturesAnn = context.findAnnotation(JacksonFeatures.class).orElse(null);
650651
Optional<Class<?>> configurationClass = clientAnn.classValue("configuration");
651652

652653
if (null != clientBean) {
653-
if (path == null && jacksonFeatures == null && !configurationClass.isPresent()) {
654+
if (path == null && jacksonFeaturesAnn == null && !configurationClass.isPresent()) {
654655
return clientBean;
655656
}
656657
}
@@ -688,60 +689,70 @@ private HttpClient getClient(MethodInvocationContext<Object, Object> context, An
688689
DefaultHttpClient defaultClient = (DefaultHttpClient) client;
689690
defaultClient.setClientIdentifiers(clientId);
690691

691-
if (jacksonFeatures != null) {
692-
Optional<MediaTypeCodec> existingCodec = defaultClient.getMediaTypeCodecRegistry().findCodec(MediaType.APPLICATION_JSON_TYPE);
693-
ObjectMapper objectMapper = null;
694-
if (existingCodec.isPresent()) {
695-
MediaTypeCodec existing = existingCodec.get();
696-
if (existing instanceof JsonMediaTypeCodec) {
697-
objectMapper = ((JsonMediaTypeCodec) existing).getObjectMapper().copy();
698-
}
699-
}
700-
if (objectMapper == null) {
701-
objectMapper = new ObjectMapperFactory().objectMapper(null, null);
702-
}
692+
if (jacksonFeaturesAnn != null) {
693+
io.micronaut.jackson.codec.JacksonFeatures jacksonFeatures = new io.micronaut.jackson.codec.JacksonFeatures();
703694

704-
SerializationFeature[] enabledSerializationFeatures = jacksonFeatures.get("enabledSerializationFeatures", SerializationFeature[].class).orElse(null);
695+
696+
SerializationFeature[] enabledSerializationFeatures = jacksonFeaturesAnn.get("enabledSerializationFeatures", SerializationFeature[].class).orElse(null);
705697
if (enabledSerializationFeatures != null) {
706698
for (SerializationFeature serializationFeature : enabledSerializationFeatures) {
707-
objectMapper.configure(serializationFeature, true);
699+
jacksonFeatures.addFeature(serializationFeature, true);
708700
}
709701
}
710702

711-
DeserializationFeature[] enabledDeserializationFeatures = jacksonFeatures.get("enabledDeserializationFeatures", DeserializationFeature[].class).orElse(null);
703+
DeserializationFeature[] enabledDeserializationFeatures = jacksonFeaturesAnn.get("enabledDeserializationFeatures", DeserializationFeature[].class).orElse(null);
712704

713705
if (enabledDeserializationFeatures != null) {
714-
for (DeserializationFeature serializationFeature : enabledDeserializationFeatures) {
715-
objectMapper.configure(serializationFeature, true);
706+
for (DeserializationFeature deserializationFeature : enabledDeserializationFeatures) {
707+
jacksonFeatures.addFeature(deserializationFeature, true);
716708
}
717709
}
718710

719-
SerializationFeature[] disabledSerializationFeatures = jacksonFeatures.get("disabledSerializationFeatures", SerializationFeature[].class).orElse(null);
711+
SerializationFeature[] disabledSerializationFeatures = jacksonFeaturesAnn.get("disabledSerializationFeatures", SerializationFeature[].class).orElse(null);
720712
if (disabledSerializationFeatures != null) {
721713
for (SerializationFeature serializationFeature : disabledSerializationFeatures) {
722-
objectMapper.configure(serializationFeature, false);
714+
jacksonFeatures.addFeature(serializationFeature, false);
723715
}
724716
}
725717

726-
DeserializationFeature[] disabledDeserializationFeatures = jacksonFeatures.get("disabledDeserializationFeatures", DeserializationFeature[].class).orElse(null);
718+
DeserializationFeature[] disabledDeserializationFeatures = jacksonFeaturesAnn.get("disabledDeserializationFeatures", DeserializationFeature[].class).orElse(null);
727719

728720
if (disabledDeserializationFeatures != null) {
729721
for (DeserializationFeature feature : disabledDeserializationFeatures) {
730-
objectMapper.configure(feature, false);
722+
jacksonFeatures.addFeature(feature, false);
731723
}
732724
}
733725

734-
defaultClient.setMediaTypeCodecRegistry(
735-
MediaTypeCodecRegistry.of(
736-
new JsonMediaTypeCodec(objectMapper,
737-
beanContext.getBean(ApplicationConfiguration.class),
738-
beanContext.findBean(CodecConfiguration.class, Qualifiers.byName(JsonMediaTypeCodec.CONFIGURATION_QUALIFIER)).orElse(null))));
726+
List<MediaTypeCodec> codecs = new ArrayList<>(2);
727+
MediaTypeCodecRegistry codecRegistry = defaultClient.getMediaTypeCodecRegistry();
728+
for (MediaTypeCodec codec: codecRegistry.getCodecs()) {
729+
if (codec instanceof JacksonMediaTypeCodec) {
730+
codecs.add(((JacksonMediaTypeCodec) codec).cloneWithFeatures(jacksonFeatures));
731+
} else {
732+
codecs.add(codec);
733+
}
734+
}
735+
if (!codecRegistry.findCodec(MediaType.APPLICATION_JSON_TYPE).isPresent()) {
736+
codecs.add(createNewJsonCodec(beanContext, jacksonFeatures));
737+
}
738+
defaultClient.setMediaTypeCodecRegistry(MediaTypeCodecRegistry.of(codecs));
739739
}
740740
}
741741
return client;
742742
});
743743
}
744744

745+
private static MediaTypeCodec createNewJsonCodec(BeanContext beanContext, io.micronaut.jackson.codec.JacksonFeatures jacksonFeatures) {
746+
ObjectMapper objectMapper = new ObjectMapperFactory().objectMapper(null, null);
747+
748+
jacksonFeatures.getDeserializationFeatures().forEach(objectMapper::configure);
749+
jacksonFeatures.getSerializationFeatures().forEach(objectMapper::configure);
750+
751+
return new JsonMediaTypeCodec(objectMapper,
752+
beanContext.getBean(ApplicationConfiguration.class),
753+
beanContext.findBean(CodecConfiguration.class, Qualifiers.byName(JsonMediaTypeCodec.CONFIGURATION_QUALIFIER)).orElse(null));
754+
}
755+
745756
private String getClientId(AnnotationValue<Client> clientAnn) {
746757
String clientId = clientAnn.stringValue().orElse(null);
747758
if (clientId == null) {

http-client/src/test/groovy/io/micronaut/http/client/StreamRequestSpec.groovy

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import java.time.Duration
4444
* @author graemerocher
4545
* @since 1.0
4646
*/
47-
//@IgnoreIf({env["TRAVIS"]})
4847
class StreamRequestSpec extends Specification {
4948
@Shared @AutoCleanup EmbeddedServer embeddedServer =
5049
ApplicationContext.run(EmbeddedServer)

0 commit comments

Comments
 (0)