Sonar Fixes
Critical smells `o.s.i.h*`.
This commit is contained in:
committed by
Artem Bilan
parent
536b6b1786
commit
4760c54097
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.integration.http.config;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -55,6 +56,9 @@ class IntegrationGraphControllerRegistrar implements ImportBeanDefinitionRegistr
|
||||
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
|
||||
Map<String, Object> annotationAttributes =
|
||||
importingClassMetadata.getAnnotationAttributes(EnableIntegrationGraphController.class.getName());
|
||||
if (annotationAttributes == null) {
|
||||
annotationAttributes = Collections.emptyMap(); // To satisfy sonar for subsequent references
|
||||
}
|
||||
|
||||
if (!registry.containsBeanDefinition(IntegrationContextUtils.INTEGRATION_GRAPH_SERVER_BEAN_NAME)) {
|
||||
registry.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_GRAPH_SERVER_BEAN_NAME,
|
||||
|
||||
@@ -52,13 +52,15 @@ import org.springframework.util.CollectionUtils;
|
||||
*/
|
||||
public class BaseHttpInboundEndpoint extends MessagingGatewaySupport implements OrderlyShutdownCapable {
|
||||
|
||||
protected static final boolean jaxb2Present = ClassUtils.isPresent("javax.xml.bind.Binder",
|
||||
BaseHttpInboundEndpoint.class.getClassLoader());
|
||||
protected static final boolean jaxb2Present = // NOSONAR lower case static
|
||||
ClassUtils.isPresent("javax.xml.bind.Binder",
|
||||
BaseHttpInboundEndpoint.class.getClassLoader());
|
||||
|
||||
protected static final boolean romeToolsPresent = ClassUtils.isPresent("com.rometools.rome.feed.atom.Feed",
|
||||
BaseHttpInboundEndpoint.class.getClassLoader());
|
||||
protected static final boolean romeToolsPresent = // NOSONAR lower case static
|
||||
ClassUtils.isPresent("com.rometools.rome.feed.atom.Feed",
|
||||
BaseHttpInboundEndpoint.class.getClassLoader());
|
||||
|
||||
protected static final List<HttpMethod> nonReadableBodyHttpMethods =
|
||||
protected static final List<HttpMethod> nonReadableBodyHttpMethods = // NOSONAR lower case static
|
||||
Arrays.asList(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.OPTIONS);
|
||||
|
||||
protected final boolean expectReply;
|
||||
@@ -327,6 +329,8 @@ public class BaseHttpInboundEndpoint extends MessagingGatewaySupport implements
|
||||
* @return true or false if HTTP request can contain the body
|
||||
*/
|
||||
protected boolean isReadable(HttpRequest request) {
|
||||
return !(CollectionUtils.containsInstance(nonReadableBodyHttpMethods, request.getMethod()));
|
||||
HttpMethod method = request.getMethod();
|
||||
return method == null ? false : !(CollectionUtils.containsInstance(nonReadableBodyHttpMethods, method));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -34,6 +34,7 @@ import org.springframework.core.ResolvableType;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.RequestEntity;
|
||||
@@ -339,14 +340,19 @@ public abstract class HttpRequestHandlingEndpointSupport extends BaseHttpInbound
|
||||
.copyHeadersIfAbsent(headers);
|
||||
}
|
||||
else {
|
||||
Assert.state(payload != null, "payload cannot be null");
|
||||
messageBuilder = this.getMessageBuilderFactory().withPayload(payload).copyHeaders(headers);
|
||||
}
|
||||
|
||||
HttpMethod method = httpEntity.getMethod();
|
||||
if (method != null) {
|
||||
messageBuilder.setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_METHOD,
|
||||
method.toString());
|
||||
}
|
||||
|
||||
Message<?> message = messageBuilder
|
||||
.setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_URL,
|
||||
httpEntity.getUrl().toString())
|
||||
.setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_METHOD,
|
||||
httpEntity.getMethod().toString())
|
||||
.setHeader(org.springframework.integration.http.HttpHeaders.USER_PRINCIPAL,
|
||||
servletRequest.getUserPrincipal())
|
||||
.build();
|
||||
|
||||
@@ -26,9 +26,11 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@@ -76,6 +78,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
|
||||
* them during the {@link BaseHttpInboundEndpoint} destruction.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
@@ -100,10 +103,12 @@ public final class IntegrationRequestMappingHandlerMapping extends RequestMappin
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException {
|
||||
if (isHandler(bean.getClass())) {
|
||||
unregisterMapping(getMappingForEndpoint((BaseHttpInboundEndpoint) bean));
|
||||
RequestMappingInfo mapping = getMappingForEndpoint((BaseHttpInboundEndpoint) bean);
|
||||
if (mapping != null) {
|
||||
unregisterMapping(mapping);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,11 +146,19 @@ public final class IntegrationRequestMappingHandlerMapping extends RequestMappin
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void detectHandlerMethods(Object handler) {
|
||||
protected void detectHandlerMethods(Object handlerArg) {
|
||||
Object handler = handlerArg;
|
||||
if (handler instanceof String) {
|
||||
handler = this.getApplicationContext().getBean((String) handler);
|
||||
ApplicationContext applicationContext = getApplicationContext();
|
||||
if (applicationContext != null) {
|
||||
handler = applicationContext.getBean((String) handler);
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("No application context available to lookup bean '"
|
||||
+ handler + "'");
|
||||
}
|
||||
}
|
||||
RequestMappingInfo mapping = this.getMappingForEndpoint((BaseHttpInboundEndpoint) handler);
|
||||
RequestMappingInfo mapping = getMappingForEndpoint((BaseHttpInboundEndpoint) handler);
|
||||
if (mapping != null) {
|
||||
registerMapping(mapping, handler, HANDLE_REQUEST_METHOD);
|
||||
}
|
||||
@@ -196,6 +209,7 @@ public final class IntegrationRequestMappingHandlerMapping extends RequestMappin
|
||||
* 'Spring Integration HTTP Inbound Endpoint' {@link RequestMapping}.
|
||||
* @see RequestMappingHandlerMapping#getMappingForMethod
|
||||
*/
|
||||
@Nullable
|
||||
private RequestMappingInfo getMappingForEndpoint(BaseHttpInboundEndpoint endpoint) {
|
||||
final RequestMapping requestMapping = endpoint.getRequestMapping();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -29,6 +29,7 @@ import org.springframework.web.util.WebUtils;
|
||||
* content directly as either a String or byte array depending on the Content-Type.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Gary Russell
|
||||
* @since 2.0
|
||||
*/
|
||||
public class SimpleMultipartFileReader implements MultipartFileReader<Object> {
|
||||
@@ -49,8 +50,9 @@ public class SimpleMultipartFileReader implements MultipartFileReader<Object> {
|
||||
|
||||
@Override
|
||||
public Object readMultipartFile(MultipartFile multipartFile) throws IOException {
|
||||
if (multipartFile.getContentType() != null && multipartFile.getContentType().startsWith("text")) {
|
||||
MediaType contentType = MediaType.parseMediaType(multipartFile.getContentType());
|
||||
String mpContentType = multipartFile.getContentType();
|
||||
if (mpContentType != null && mpContentType.startsWith("text")) {
|
||||
MediaType contentType = MediaType.parseMediaType(mpContentType);
|
||||
Charset charset = contentType.getCharset();
|
||||
if (charset == null) {
|
||||
charset = this.defaultCharset;
|
||||
|
||||
@@ -325,7 +325,7 @@ public abstract class AbstractHttpRequestExecutingMessageHandler extends Abstrac
|
||||
Object responseBody = httpResponse.getBody();
|
||||
replyBuilder = (responseBody instanceof Message<?>)
|
||||
? messageBuilderFactory.fromMessage((Message<?>) responseBody)
|
||||
: messageBuilderFactory.withPayload(responseBody);
|
||||
: messageBuilderFactory.withPayload(responseBody); // NOSONAR - hasBody()
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user