Skip to content

Commit 8f86ef9

Browse files
artembilangaryrussell
authored andcommitted
Fix Sonar smells for HTTP & WebFlux modules (#2810)
* Fix Sonar smells for HTTP & WebFlux modules * * Fix more HTTP Sonar smells * * Remove unused import * Fix complexity in the `IntegrationMBeanExporter.enhanceSourceMonitor()` * * Remove unused `IntegrationMBeanExporter.getField()` method * * Remove unused import in the `IntegrationMBeanExporter`
1 parent 3751505 commit 8f86ef9

File tree

7 files changed

+194
-220
lines changed

7 files changed

+194
-220
lines changed

spring-integration-http/src/main/java/org/springframework/integration/http/inbound/BaseHttpInboundEndpoint.java

+14-16
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.http.HttpEntity;
2929
import org.springframework.http.HttpHeaders;
3030
import org.springframework.http.HttpMethod;
31-
import org.springframework.http.HttpRequest;
3231
import org.springframework.http.HttpStatus;
3332
import org.springframework.integration.context.OrderlyShutdownCapable;
3433
import org.springframework.integration.expression.ExpressionUtils;
@@ -51,20 +50,20 @@
5150
*/
5251
public class BaseHttpInboundEndpoint extends MessagingGatewaySupport implements OrderlyShutdownCapable {
5352

54-
protected static final boolean jaxb2Present = // NOSONAR lower case static
53+
protected static final boolean JAXB_PRESENT =
5554
ClassUtils.isPresent("javax.xml.bind.Binder",
5655
BaseHttpInboundEndpoint.class.getClassLoader());
5756

58-
protected static final boolean romeToolsPresent = // NOSONAR lower case static
57+
protected static final boolean ROME_TOOLS_PRESENT =
5958
ClassUtils.isPresent("com.rometools.rome.feed.atom.Feed",
6059
BaseHttpInboundEndpoint.class.getClassLoader());
6160

62-
protected static final List<HttpMethod> nonReadableBodyHttpMethods = // NOSONAR lower case static
61+
protected static final List<HttpMethod> NON_READABLE_BODY_HTTP_METHODS =
6362
Arrays.asList(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.OPTIONS);
6463

65-
protected final boolean expectReply;
64+
protected final AtomicInteger activeCount = new AtomicInteger(); // NOSONAR
6665

67-
protected final AtomicInteger activeCount = new AtomicInteger();
66+
private final boolean expectReply;
6867

6968
private ResolvableType requestPayloadType = null;
7069

@@ -268,13 +267,12 @@ protected void onInit() {
268267
}
269268

270269
private void validateSupportedMethods() {
271-
if (this.requestPayloadType != null
272-
&& CollectionUtils.containsAny(nonReadableBodyHttpMethods,
273-
Arrays.asList(getRequestMapping().getMethods()))) {
274-
if (logger.isWarnEnabled()) {
275-
logger.warn("The 'requestPayloadType' attribute will have no relevance for one " +
276-
"of the specified HTTP methods '" + nonReadableBodyHttpMethods + "'");
277-
}
270+
if (this.requestPayloadType != null && logger.isWarnEnabled() &&
271+
CollectionUtils.containsAny(NON_READABLE_BODY_HTTP_METHODS,
272+
Arrays.asList(getRequestMapping().getMethods()))) {
273+
274+
logger.warn("The 'requestPayloadType' attribute will have no relevance for one " +
275+
"of the specified HTTP methods '" + NON_READABLE_BODY_HTTP_METHODS + "'");
278276
}
279277
}
280278

@@ -329,11 +327,11 @@ public String getComponentType() {
329327

330328
/**
331329
* Checks if the request has a readable body (not a GET, HEAD, or OPTIONS request).
332-
* @param request the HTTP request to check the method
330+
* @param httpMethod the HTTP method to check
333331
* @return true or false if HTTP request can contain the body
334332
*/
335-
protected boolean isReadable(HttpRequest request) {
336-
return !(CollectionUtils.containsInstance(nonReadableBodyHttpMethods, request.getMethod()));
333+
protected boolean isReadable(HttpMethod httpMethod) {
334+
return !(CollectionUtils.containsInstance(NON_READABLE_BODY_HTTP_METHODS, httpMethod));
337335
}
338336

339337
}

spring-integration-http/src/main/java/org/springframework/integration/http/inbound/HttpRequestHandlingController.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,9 +45,9 @@
4545
* <p>
4646
* This endpoint will have request/reply behavior by default. That can be overridden by passing <code>false</code> to
4747
* the constructor. In the request/reply case, the core map will be passed to the view, and it will contain either the
48-
* reply Message or payload depending on the value of {@link #extractReplyPayload} (true by default, meaning just the
49-
* payload). The corresponding key in the map is determined by the {@link #replyKey} property (with a default of
50-
* "reply").
48+
* reply Message or payload depending on the value of {@link #setExtractReplyPayload(boolean)}
49+
* (true by default, meaning just the payload).
50+
* The corresponding key in the map is determined by the {@link #replyKey} property (with a default of "reply").
5151
*
5252
* @author Mark Fisher
5353
* @author Gary Russell
@@ -72,15 +72,15 @@ public class HttpRequestHandlingController extends HttpRequestHandlingEndpointSu
7272
*/
7373
public static final String DEFAULT_ERRORS_KEY = "errors";
7474

75-
private volatile Expression viewExpression;
75+
private Expression viewExpression;
7676

77-
private volatile StandardEvaluationContext evaluationContext;
77+
private StandardEvaluationContext evaluationContext;
7878

79-
private volatile String replyKey = DEFAULT_REPLY_KEY;
79+
private String replyKey = DEFAULT_REPLY_KEY;
8080

81-
private volatile String errorsKey = DEFAULT_ERRORS_KEY;
81+
private String errorsKey = DEFAULT_ERRORS_KEY;
8282

83-
private volatile String errorCode = DEFAULT_ERROR_CODE;
83+
private String errorCode = DEFAULT_ERROR_CODE;
8484

8585
public HttpRequestHandlingController() {
8686
this(true);
@@ -157,7 +157,7 @@ public final ModelAndView handleRequest(HttpServletRequest servletRequest, HttpS
157157

158158
RequestEntity<Object> httpEntity = prepareRequestEntity(request);
159159

160-
Message<?> replyMessage = doHandleRequest(servletRequest, httpEntity, servletResponse);
160+
Message<?> replyMessage = doHandleRequest(servletRequest, httpEntity);
161161
ServletServerHttpResponse response = new ServletServerHttpResponse(servletResponse);
162162
if (replyMessage != null) {
163163
Object reply = setupResponseAndConvertReply(response, replyMessage);

0 commit comments

Comments
 (0)