Fix new Sonar smells

This commit is contained in:
Artem Bilan
2020-07-20 11:05:23 -04:00
parent 8d3d871996
commit 44a4523586
6 changed files with 87 additions and 78 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 the original author or authors.
* Copyright 2015-2020 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.
@@ -32,7 +32,7 @@ import com.esotericsoftware.kryo.Registration;
*/
public abstract class AbstractKryoRegistrar implements KryoRegistrar {
protected static final Kryo kryo = new Kryo(); // NOSONAR TODO uppercase in 5.2
protected static final Kryo KRYO = new Kryo();
protected final Log log = LogFactory.getLog(getClass()); // NOSONAR property is final

View File

@@ -68,7 +68,7 @@ public class KryoClassListRegistrar extends AbstractKryoRegistrar {
if (!CollectionUtils.isEmpty(this.registeredClasses)) {
for (int i = 0; i < this.registeredClasses.size(); i++) {
registrations.add(new Registration(this.registeredClasses.get(i),
kryo.getSerializer(this.registeredClasses.get(i)), i + this.initialValue));
KRYO.getSerializer(this.registeredClasses.get(i)), i + this.initialValue));
}
}
return registrations;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 the original author or authors.
* Copyright 2015-2020 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.
@@ -46,7 +46,7 @@ public class KryoClassMapRegistrar extends AbstractKryoRegistrar {
if (!CollectionUtils.isEmpty(this.registeredClasses)) {
for (Map.Entry<Integer, Class<?>> entry : this.registeredClasses.entrySet()) {
registrations.add(
new Registration(entry.getValue(), kryo.getSerializer(entry.getValue()), entry.getKey()));
new Registration(entry.getValue(), KRYO.getSerializer(entry.getValue()), entry.getKey()));
}
}
return registrations;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 the original author or authors.
* Copyright 2014-2020 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.
@@ -37,7 +37,7 @@ import org.springframework.integration.http.inbound.IntegrationRequestMappingHan
*/
public class HttpIntegrationConfigurationInitializer implements IntegrationConfigurationInitializer {
private static final Log logger = LogFactory.getLog(HttpIntegrationConfigurationInitializer.class);
private static final Log LOGGER = LogFactory.getLog(HttpIntegrationConfigurationInitializer.class);
@Override
public void initialize(ConfigurableListableBeanFactory beanFactory) throws BeansException {
@@ -45,7 +45,7 @@ public class HttpIntegrationConfigurationInitializer implements IntegrationConfi
registerRequestMappingHandlerMappingIfNecessary((BeanDefinitionRegistry) beanFactory);
}
else {
logger.warn("'IntegrationRequestMappingHandlerMapping' isn't registered because 'beanFactory'" +
LOGGER.warn("'IntegrationRequestMappingHandlerMapping' isn't registered because 'beanFactory'" +
" isn't an instance of `BeanDefinitionRegistry`.");
}
}

View File

@@ -172,45 +172,49 @@ public final class IntegrationRequestMappingHandlerMapping extends RequestMappin
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) {
CrossOrigin crossOrigin = ((BaseHttpInboundEndpoint) handler).getCrossOrigin();
if (crossOrigin != null) {
CorsConfiguration config = new CorsConfiguration();
for (RequestMethod requestMethod : crossOrigin.getMethod()) {
config.addAllowedMethod(requestMethod.name());
}
config.setAllowedHeaders(Arrays.asList(crossOrigin.getAllowedHeaders()));
config.setExposedHeaders(Arrays.asList(crossOrigin.getExposedHeaders()));
Boolean allowCredentials = crossOrigin.getAllowCredentials();
config.setAllowCredentials(allowCredentials);
List<String> allowedOrigins = Arrays.asList(crossOrigin.getOrigin());
if (Boolean.TRUE.equals(allowCredentials)
&& CollectionUtils.contains(allowedOrigins.iterator(), CorsConfiguration.ALL)) {
config.setAllowedOriginPatterns(allowedOrigins);
}
else {
config.setAllowedOrigins(allowedOrigins);
}
if (crossOrigin.getMaxAge() != -1) {
config.setMaxAge(crossOrigin.getMaxAge());
}
if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
config.addAllowedMethod(allowedMethod.name());
}
}
if (CollectionUtils.isEmpty(config.getAllowedHeaders())) {
for (NameValueExpression<String> headerExpression :
mappingInfo.getHeadersCondition().getExpressions()) {
if (!headerExpression.isNegated()) {
config.addAllowedHeader(headerExpression.getName());
}
}
}
return config.applyPermitDefaultValues();
return buildCorsConfiguration(crossOrigin, mappingInfo);
}
return null;
}
private static CorsConfiguration buildCorsConfiguration(CrossOrigin crossOrigin, RequestMappingInfo mappingInfo) {
CorsConfiguration config = new CorsConfiguration();
for (RequestMethod requestMethod : crossOrigin.getMethod()) {
config.addAllowedMethod(requestMethod.name());
}
config.setAllowedHeaders(Arrays.asList(crossOrigin.getAllowedHeaders()));
config.setExposedHeaders(Arrays.asList(crossOrigin.getExposedHeaders()));
Boolean allowCredentials = crossOrigin.getAllowCredentials();
config.setAllowCredentials(allowCredentials);
List<String> allowedOrigins = Arrays.asList(crossOrigin.getOrigin());
if (Boolean.TRUE.equals(allowCredentials)
&& CollectionUtils.contains(allowedOrigins.iterator(), CorsConfiguration.ALL)) {
config.setAllowedOriginPatterns(allowedOrigins);
}
else {
config.setAllowedOrigins(allowedOrigins);
}
if (crossOrigin.getMaxAge() != -1) {
config.setMaxAge(crossOrigin.getMaxAge());
}
if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
config.addAllowedMethod(allowedMethod.name());
}
}
if (CollectionUtils.isEmpty(config.getAllowedHeaders())) {
for (NameValueExpression<String> headerExpression :
mappingInfo.getHeadersCondition().getExpressions()) {
if (!headerExpression.isNegated()) {
config.addAllowedHeader(headerExpression.getName());
}
}
}
return config.applyPermitDefaultValues();
}
/**
* Created a {@link RequestMappingInfo} from a
* 'Spring Integration HTTP Inbound Endpoint' {@link RequestMapping}.

View File

@@ -148,45 +148,50 @@ public class WebFluxIntegrationRequestMappingHandlerMapping extends RequestMappi
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) {
CrossOrigin crossOrigin = ((BaseHttpInboundEndpoint) handler).getCrossOrigin();
if (crossOrigin != null) {
CorsConfiguration config = new CorsConfiguration();
for (RequestMethod requestMethod : crossOrigin.getMethod()) {
config.addAllowedMethod(requestMethod.name());
}
config.setAllowedHeaders(Arrays.asList(crossOrigin.getAllowedHeaders()));
config.setExposedHeaders(Arrays.asList(crossOrigin.getExposedHeaders()));
Boolean allowCredentials = crossOrigin.getAllowCredentials();
config.setAllowCredentials(allowCredentials);
List<String> allowedOrigins = Arrays.asList(crossOrigin.getOrigin());
if (Boolean.TRUE.equals(allowCredentials)
&& CollectionUtils.contains(allowedOrigins.iterator(), CorsConfiguration.ALL)) {
config.setAllowedOriginPatterns(allowedOrigins);
}
else {
config.setAllowedOrigins(allowedOrigins);
}
if (crossOrigin.getMaxAge() != -1) {
config.setMaxAge(crossOrigin.getMaxAge());
}
if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
config.addAllowedMethod(allowedMethod.name());
}
}
if (CollectionUtils.isEmpty(config.getAllowedHeaders())) {
for (NameValueExpression<String> headerExpression :
mappingInfo.getHeadersCondition().getExpressions()) {
if (!headerExpression.isNegated()) {
config.addAllowedHeader(headerExpression.getName());
}
}
}
return config.applyPermitDefaultValues();
return buildCorsConfiguration(crossOrigin, mappingInfo);
}
return null;
}
private static CorsConfiguration buildCorsConfiguration(CrossOrigin crossOrigin, RequestMappingInfo mappingInfo) {
CorsConfiguration config = new CorsConfiguration();
for (RequestMethod requestMethod : crossOrigin.getMethod()) {
config.addAllowedMethod(requestMethod.name());
}
config.setAllowedHeaders(Arrays.asList(crossOrigin.getAllowedHeaders()));
config.setExposedHeaders(Arrays.asList(crossOrigin.getExposedHeaders()));
Boolean allowCredentials = crossOrigin.getAllowCredentials();
config.setAllowCredentials(allowCredentials);
List<String> allowedOrigins = Arrays.asList(crossOrigin.getOrigin());
if (Boolean.TRUE.equals(allowCredentials)
&& CollectionUtils.contains(allowedOrigins.iterator(), CorsConfiguration.ALL)) {
config.setAllowedOriginPatterns(allowedOrigins);
}
else {
config.setAllowedOrigins(allowedOrigins);
}
if (crossOrigin.getMaxAge() != -1) {
config.setMaxAge(crossOrigin.getMaxAge());
}
if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
config.addAllowedMethod(allowedMethod.name());
}
}
if (CollectionUtils.isEmpty(config.getAllowedHeaders())) {
for (NameValueExpression<String> headerExpression :
mappingInfo.getHeadersCondition().getExpressions()) {
if (!headerExpression.isNegated()) {
config.addAllowedHeader(headerExpression.getName());
}
}
}
return config.applyPermitDefaultValues();
}
/**
* {@link org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport}s
* may depend on auto-created {@code requestChannel}s, so MVC Handlers detection should be postponed