Skip to content

Commit 7cfab7b

Browse files
artembilangaryrussell
authored andcommitted
Fix RESOLVABLE_TYPE header population
* We should not build a RESOLVABLE_TYPE header when we map requests. Only for replies. See: spring-projects/spring-integration-samples#277 * We should log `ClassNotFoundException` only at debug level - to noise with info or warn **Cherry-pick to 5.2.x**
1 parent 37a0c40 commit 7cfab7b

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

spring-integration-core/src/main/java/org/springframework/integration/json/JsonToObjectTransformer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private ResolvableType obtainResolvableType(Message<?> message) {
197197
}
198198
catch (Exception ex) {
199199
if (ex.getCause() instanceof ClassNotFoundException) {
200-
logger.info("Cannot build a ResolvableType from the request message '" + message +
200+
logger.debug("Cannot build a ResolvableType from the request message '" + message +
201201
"' evaluating expression '" + this.valueTypeExpression.getExpressionString() + "'", ex);
202202
return null;
203203
}

spring-integration-core/src/main/java/org/springframework/integration/mapping/AbstractHeaderMapper.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ private void copyHeaders(Map<String, Object> source, Map<String, Object> target,
278278
if (shouldMapHeader(headerName, headerMatcher)) {
279279
Object value = entry.getValue();
280280
target.put(headerName, value);
281-
if (JsonHeaders.TYPE_ID.equals(headerName) && value != null) {
281+
if (this.replyHeaderMatcher == headerMatcher &&
282+
JsonHeaders.TYPE_ID.equals(headerName) && value != null) {
283+
282284
ResolvableType resolvableType =
283285
createJsonResolvableTypHeaderInAny(value, source.get(JsonHeaders.CONTENT_TYPE_ID),
284286
source.get(JsonHeaders.KEY_TYPE_ID));
@@ -303,11 +305,10 @@ private ResolvableType createJsonResolvableTypHeaderInAny(Object typeId, @Nullab
303305
@Nullable Object keyId) {
304306

305307
try {
306-
return JsonHeaders.buildResolvableType(getClassLoader(), typeId,
307-
contentId, keyId);
308+
return JsonHeaders.buildResolvableType(getClassLoader(), typeId, contentId, keyId);
308309
}
309310
catch (Exception e) {
310-
this.logger.warn("Cannot build a ResolvableType from 'json__TypeId__' header", e);
311+
this.logger.debug("Cannot build a ResolvableType from 'json__TypeId__' header", e);
311312
}
312313
return null;
313314
}

spring-integration-core/src/test/java/org/springframework/integration/json/JsonToObjectTransformerParserTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void testDefaultObjectMapper() {
9393
assertThat(person.getAddress().toString()).isEqualTo("123 Main Street");
9494

9595
ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
96-
verify(logger).info(stringArgumentCaptor.capture(), any(Exception.class));
96+
verify(logger).debug(stringArgumentCaptor.capture(), any(Exception.class));
9797
String logMessage = stringArgumentCaptor.getValue();
9898

9999
assertThat(logMessage).startsWith("Cannot build a ResolvableType from the request message");

0 commit comments

Comments
 (0)