Skip to content

Commit

Permalink
Fix new Sonar smells
Browse files Browse the repository at this point in the history
* Some code clean up in the affected classes
  • Loading branch information
artembilan committed Dec 31, 2019
1 parent fc4c85a commit 5eb3bfe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
Expand Up @@ -36,6 +36,7 @@
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;
Expand Down Expand Up @@ -190,7 +191,7 @@ protected HeaderMapper<HttpHeaders> getHeaderMapper() {
* 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) {
Expand All @@ -201,7 +202,7 @@ public void setRequestPayloadTypeClass(Class<?> requestPayloadType) {
* 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) {
Expand Down Expand Up @@ -350,15 +351,6 @@ public IntegrationPatternType getIntegrationPatternType() {
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);
Expand All @@ -367,4 +359,13 @@ protected void validate(Object value) {
}
}

/**
* 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));
}

}
Expand Up @@ -68,10 +68,7 @@ public ExpressionEvaluatingParameterSourceFactory(@Nullable BeanFactory beanFact
*/
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",
Expand Down Expand Up @@ -108,12 +105,11 @@ protected ExpressionEvaluatingParameterSource(Object input, List<JpaParameter> p
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()) {
Expand Down Expand Up @@ -148,10 +144,10 @@ public Object getValueByPosition(int position) {
}

return null;

}

@Override
@Nullable
public Object getValue(String paramName) {
if (this.values.containsKey(paramName)) {
return this.values.get(paramName);
Expand Down
Expand Up @@ -167,13 +167,14 @@ private Mono<Void> doHandle(ServerWebExchange exchange) {
}

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);
}
}

Expand Down Expand Up @@ -515,8 +516,8 @@ private static List<MediaType> getProducibleTypes(ServerWebExchange exchange,
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) {
Expand Down

0 comments on commit 5eb3bfe

Please sign in to comment.