Skip to content

Commit 5b84936

Browse files
artembilangaryrussell
authored andcommitted
Fix new Sonar smells
1 parent 5421574 commit 5b84936

File tree

3 files changed

+38
-39
lines changed

3 files changed

+38
-39
lines changed

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

+16-15
Original file line numberDiff line numberDiff line change
@@ -146,23 +146,24 @@ protected Object doTransform(Message<?> message) {
146146

147147

148148
private ResolvableType obtainResolvableTypeFromHeadersIfAny(MessageHeaders headers) {
149-
ResolvableType valueType = null;
150-
if (headers.containsKey(JsonHeaders.TYPE_ID) || headers.containsKey(JsonHeaders.RESOLVABLE_TYPE)) {
151-
valueType = headers.get(JsonHeaders.RESOLVABLE_TYPE, ResolvableType.class);
152-
if (valueType == null) {
153-
Class<?> targetClass = getClassForValue(headers.get(JsonHeaders.TYPE_ID));
154-
Class<?> contentClass = null;
155-
Class<?> keyClass = null;
156-
if (headers.containsKey(JsonHeaders.CONTENT_TYPE_ID)) {
157-
contentClass = getClassForValue(headers.get(JsonHeaders.CONTENT_TYPE_ID));
158-
}
159-
if (headers.containsKey(JsonHeaders.KEY_TYPE_ID)) {
160-
keyClass = getClassForValue(headers.get(JsonHeaders.KEY_TYPE_ID));
161-
}
162-
163-
valueType = JsonObjectMapper.buildResolvableType(targetClass, contentClass, keyClass);
149+
ResolvableType valueType = headers.get(JsonHeaders.RESOLVABLE_TYPE, ResolvableType.class);
150+
Object typeIdHeader = headers.get(JsonHeaders.TYPE_ID);
151+
if (valueType == null && typeIdHeader != null) {
152+
Class<?> targetClass = getClassForValue(typeIdHeader);
153+
Class<?> contentClass = null;
154+
Class<?> keyClass = null;
155+
Object contentTypeHeader = headers.get(JsonHeaders.CONTENT_TYPE_ID);
156+
if (contentTypeHeader != null) {
157+
contentClass = getClassForValue(contentTypeHeader);
164158
}
159+
Object keyTypeHeader = headers.get(JsonHeaders.KEY_TYPE_ID);
160+
if (keyTypeHeader != null) {
161+
keyClass = getClassForValue(keyTypeHeader);
162+
}
163+
164+
valueType = JsonObjectMapper.buildResolvableType(targetClass, contentClass, keyClass);
165165
}
166+
166167
return valueType;
167168
}
168169

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,9 @@ protected Object doTransform(Message<?> message) {
120120
headers.putAll(message.getHeaders());
121121

122122
if (headers.containsKey(MessageHeaders.CONTENT_TYPE)) {
123-
if (this.contentTypeExplicitlySet) {
124-
// override, unless empty
125-
if (StringUtils.hasLength(this.contentType)) {
126-
headers.put(MessageHeaders.CONTENT_TYPE, this.contentType);
127-
}
123+
// override, unless empty
124+
if (this.contentTypeExplicitlySet && StringUtils.hasLength(this.contentType)) {
125+
headers.put(MessageHeaders.CONTENT_TYPE, this.contentType);
128126
}
129127
}
130128
else if (StringUtils.hasLength(this.contentType)) {

spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMBeanExporter.java

+19-19
Original file line numberDiff line numberDiff line change
@@ -1038,26 +1038,10 @@ private MessageSourceMetrics enhanceSourceMonitor(MessageSourceMetrics monitor)
10381038

10391039
String endpointName = null;
10401040
String source = "endpoint";
1041-
Object endpoint = null;
1041+
AbstractEndpoint endpoint = getEndpointForMonitor(monitor);
10421042

1043-
String[] names = this.applicationContext.getBeanNamesForType(AbstractEndpoint.class);
1044-
for (String beanName : names) {
1045-
endpoint = this.applicationContext.getBean(beanName);
1046-
Object target = null;
1047-
if (monitor instanceof MessagingGatewaySupport && endpoint.equals(monitor)) {
1048-
target = monitor;
1049-
}
1050-
else if (endpoint instanceof SourcePollingChannelAdapter) {
1051-
target = ((SourcePollingChannelAdapter) endpoint).getMessageSource();
1052-
}
1053-
if (monitor.equals(target)) {
1054-
endpointName = beanName;
1055-
break;
1056-
}
1057-
}
1058-
1059-
if (endpointName == null) {
1060-
endpoint = null;
1043+
if (endpoint != null) {
1044+
endpointName = endpoint.getBeanName();
10611045
}
10621046
if (endpointName != null && endpointName.startsWith('_' + SI_PACKAGE)) {
10631047
endpointName = getInternalComponentName(endpointName);
@@ -1072,6 +1056,22 @@ else if (endpoint instanceof SourcePollingChannelAdapter) {
10721056
return messageSourceMetrics;
10731057
}
10741058

1059+
private AbstractEndpoint getEndpointForMonitor(MessageSourceMetrics monitor) {
1060+
for (AbstractEndpoint endpoint : this.applicationContext.getBeansOfType(AbstractEndpoint.class).values()) {
1061+
Object target = null;
1062+
if (monitor instanceof MessagingGatewaySupport && endpoint.equals(monitor)) {
1063+
target = monitor;
1064+
}
1065+
else if (endpoint instanceof SourcePollingChannelAdapter) {
1066+
target = ((SourcePollingChannelAdapter) endpoint).getMessageSource();
1067+
}
1068+
if (monitor.equals(target)) {
1069+
return endpoint;
1070+
}
1071+
}
1072+
return null;
1073+
}
1074+
10751075
private MessageSourceMetrics buildMessageSourceMetricsIfAny(MessageSourceMetrics monitor, String name,
10761076
String source, Object endpoint) {
10771077

0 commit comments

Comments
 (0)