Skip to content

Fix Sonar smells for HTTP & WebFlux modules #2810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpRequest;
import org.springframework.http.HttpStatus;
import org.springframework.integration.context.OrderlyShutdownCapable;
import org.springframework.integration.expression.ExpressionUtils;
Expand All @@ -51,20 +50,20 @@
*/
public class BaseHttpInboundEndpoint extends MessagingGatewaySupport implements OrderlyShutdownCapable {

protected static final boolean jaxb2Present = // NOSONAR lower case static
protected static final boolean JAXB_PRESENT =
ClassUtils.isPresent("javax.xml.bind.Binder",
BaseHttpInboundEndpoint.class.getClassLoader());

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

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

protected final boolean expectReply;
protected final AtomicInteger activeCount = new AtomicInteger(); // NOSONAR

protected final AtomicInteger activeCount = new AtomicInteger();
private final boolean expectReply;

private ResolvableType requestPayloadType = null;

Expand Down Expand Up @@ -268,13 +267,12 @@ protected void onInit() {
}

private void validateSupportedMethods() {
if (this.requestPayloadType != null
&& CollectionUtils.containsAny(nonReadableBodyHttpMethods,
Arrays.asList(getRequestMapping().getMethods()))) {
if (logger.isWarnEnabled()) {
logger.warn("The 'requestPayloadType' attribute will have no relevance for one " +
"of the specified HTTP methods '" + nonReadableBodyHttpMethods + "'");
}
if (this.requestPayloadType != null && logger.isWarnEnabled() &&
CollectionUtils.containsAny(NON_READABLE_BODY_HTTP_METHODS,
Arrays.asList(getRequestMapping().getMethods()))) {

logger.warn("The 'requestPayloadType' attribute will have no relevance for one " +
"of the specified HTTP methods '" + NON_READABLE_BODY_HTTP_METHODS + "'");
}
}

Expand Down Expand Up @@ -329,11 +327,11 @@ public String getComponentType() {

/**
* Checks if the request has a readable body (not a GET, HEAD, or OPTIONS request).
* @param request the HTTP request to check the method
* @param httpMethod the HTTP method to check
* @return true or false if HTTP request can contain the body
*/
protected boolean isReadable(HttpRequest request) {
return !(CollectionUtils.containsInstance(nonReadableBodyHttpMethods, request.getMethod()));
protected boolean isReadable(HttpMethod httpMethod) {
return !(CollectionUtils.containsInstance(NON_READABLE_BODY_HTTP_METHODS, httpMethod));
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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 Down Expand Up @@ -45,9 +45,9 @@
* <p>
* This endpoint will have request/reply behavior by default. That can be overridden by passing <code>false</code> to
* the constructor. In the request/reply case, the core map will be passed to the view, and it will contain either the
* reply Message or payload depending on the value of {@link #extractReplyPayload} (true by default, meaning just the
* payload). The corresponding key in the map is determined by the {@link #replyKey} property (with a default of
* "reply").
* reply Message or payload depending on the value of {@link #setExtractReplyPayload(boolean)}
* (true by default, meaning just the payload).
* The corresponding key in the map is determined by the {@link #replyKey} property (with a default of "reply").
*
* @author Mark Fisher
* @author Gary Russell
Expand All @@ -72,15 +72,15 @@ public class HttpRequestHandlingController extends HttpRequestHandlingEndpointSu
*/
public static final String DEFAULT_ERRORS_KEY = "errors";

private volatile Expression viewExpression;
private Expression viewExpression;

private volatile StandardEvaluationContext evaluationContext;
private StandardEvaluationContext evaluationContext;

private volatile String replyKey = DEFAULT_REPLY_KEY;
private String replyKey = DEFAULT_REPLY_KEY;

private volatile String errorsKey = DEFAULT_ERRORS_KEY;
private String errorsKey = DEFAULT_ERRORS_KEY;

private volatile String errorCode = DEFAULT_ERROR_CODE;
private String errorCode = DEFAULT_ERROR_CODE;

public HttpRequestHandlingController() {
this(true);
Expand Down Expand Up @@ -157,7 +157,7 @@ public final ModelAndView handleRequest(HttpServletRequest servletRequest, HttpS

RequestEntity<Object> httpEntity = prepareRequestEntity(request);

Message<?> replyMessage = doHandleRequest(servletRequest, httpEntity, servletResponse);
Message<?> replyMessage = doHandleRequest(servletRequest, httpEntity);
ServletServerHttpResponse response = new ServletServerHttpResponse(servletResponse);
if (replyMessage != null) {
Object reply = setupResponseAndConvertReply(response, replyMessage);
Expand Down
Loading