Fix new Sonar smells

* Some code clean up in the affected classes
This commit is contained in:
Artem Bilan
2019-12-31 11:35:47 -05:00
parent fc4c85a860
commit 5eb3bfe1c3
3 changed files with 21 additions and 23 deletions

View File

@@ -36,6 +36,7 @@ import org.springframework.integration.gateway.MessagingGatewaySupport;
import org.springframework.integration.http.support.DefaultHttpHeaderMapper;
import org.springframework.integration.http.support.IntegrationWebExchangeBindException;
import org.springframework.integration.mapping.HeaderMapper;
import org.springframework.lang.Nullable;
import org.springframework.messaging.MessageHeaders;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -190,7 +191,7 @@ public class BaseHttpInboundEndpoint extends MessagingGatewaySupport implements
* Specify the type of payload to be generated when the inbound HTTP request
* content is read by the converters/encoders.
* By default this value is null which means at runtime any "text" Content-Type will
* result in String while all others default to <code>byte[].class</code>.
* result in String while all others default to {@code byte[].class}.
* @param requestPayloadType The payload type.
*/
public void setRequestPayloadTypeClass(Class<?> requestPayloadType) {
@@ -201,7 +202,7 @@ public class BaseHttpInboundEndpoint extends MessagingGatewaySupport implements
* Specify the type of payload to be generated when the inbound HTTP request
* content is read by the converters/encoders.
* By default this value is null which means at runtime any "text" Content-Type will
* result in String while all others default to <code>byte[].class</code>.
* result in String while all others default to {@code byte[].class}.
* @param requestPayloadType The payload type.
*/
public void setRequestPayloadType(ResolvableType requestPayloadType) {
@@ -350,15 +351,6 @@ public class BaseHttpInboundEndpoint extends MessagingGatewaySupport implements
return this.expectReply ? super.getIntegrationPatternType() : IntegrationPatternType.inbound_channel_adapter;
}
/**
* Checks if the request has a readable body (not a GET, HEAD, or OPTIONS request).
* @param httpMethod the HTTP method to check
* @return true or false if HTTP request can contain the body
*/
protected boolean isReadable(HttpMethod httpMethod) {
return !(CollectionUtils.containsInstance(NON_READABLE_BODY_HTTP_METHODS, httpMethod));
}
protected void validate(Object value) {
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(value, "requestPayload");
ValidationUtils.invokeValidator(this.validator, value, errors);
@@ -367,4 +359,13 @@ public class BaseHttpInboundEndpoint extends MessagingGatewaySupport implements
}
}
/**
* Checks if the request has a readable body (not a GET, HEAD, or OPTIONS request).
* @param httpMethod the HTTP method to check
* @return true or false if HTTP request can contain the body
*/
protected static boolean isReadable(@Nullable HttpMethod httpMethod) {
return !(CollectionUtils.containsInstance(NON_READABLE_BODY_HTTP_METHODS, httpMethod));
}
}

View File

@@ -68,10 +68,7 @@ public class ExpressionEvaluatingParameterSourceFactory implements ParameterSour
*/
public void setParameters(List<JpaParameter> parameters) {
Assert.notEmpty(parameters, "parameters must not be null or empty.");
for (JpaParameter parameter : parameters) {
Assert.notNull(parameter, "The provided list (parameters) cannot contain null values.");
}
Assert.noNullElements(parameters, "The provided list (parameters) cannot contain null values.");
this.parameters.addAll(parameters);
this.expressionEvaluator.getEvaluationContext().setVariable("staticParameters",
@@ -108,12 +105,11 @@ public class ExpressionEvaluatingParameterSourceFactory implements ParameterSour
this.parametersMap.put(parameter.getName(), parameter);
}
this.values.putAll(ExpressionEvaluatingParameterSourceUtils.convertStaticParameters(parameters));
}
@Override
@Nullable
public Object getValueByPosition(int position) {
Assert.isTrue(position >= 0, "The position must be non-negative.");
if (position <= this.parameters.size()) {
@@ -148,10 +144,10 @@ public class ExpressionEvaluatingParameterSourceFactory implements ParameterSour
}
return null;
}
@Override
@Nullable
public Object getValue(String paramName) {
if (this.values.containsKey(paramName)) {
return this.values.get(paramName);

View File

@@ -167,13 +167,14 @@ public class WebFluxInboundEndpoint extends BaseHttpInboundEndpoint implements W
}
private Mono<?> extractRequestBody(ServerWebExchange exchange) {
if (isReadable(exchange.getRequest().getMethod())) {
ServerHttpRequest request = exchange.getRequest();
if (isReadable(request.getMethod())) {
return extractReadableRequestBody(exchange)
.cast(Object.class)
.switchIfEmpty(queryParams(exchange));
.switchIfEmpty(queryParams(request));
}
else {
return queryParams(exchange);
return queryParams(request);
}
}
@@ -515,8 +516,8 @@ public class WebFluxInboundEndpoint extends BaseHttpInboundEndpoint implements W
return (mediaTypes != null ? new ArrayList<>(mediaTypes) : producibleTypesSupplier.get());
}
private static Mono<?> queryParams(ServerWebExchange exchange) {
return Mono.just(exchange.getRequest().getQueryParams());
private static Mono<?> queryParams(ServerHttpRequest request) {
return Mono.just(request.getQueryParams());
}
private static MediaType selectMoreSpecificMediaType(MediaType acceptable, MediaType producible) {