Fix new Sonar smells

This commit is contained in:
Artem Bilan
2020-02-24 11:57:02 -05:00
parent 50ac603d6c
commit 7dbdbdee3f
7 changed files with 86 additions and 95 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 the original author or authors.
* Copyright 2017-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.
@@ -17,6 +17,7 @@
package org.springframework.integration.webflux.inbound;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import org.springframework.beans.BeansException;
@@ -83,8 +84,8 @@ import org.springframework.web.server.WebHandler;
public class WebFluxIntegrationRequestMappingHandlerMapping extends RequestMappingHandlerMapping
implements ApplicationListener<ContextRefreshedEvent>, DestructionAwareBeanPostProcessor {
private static final Method HANDLER_METHOD = ReflectionUtils.findMethod(WebHandler.class,
"handle", ServerWebExchange.class);
private static final Method HANDLER_METHOD =
ReflectionUtils.findMethod(WebHandler.class, "handle", ServerWebExchange.class);
private final AtomicBoolean initialized = new AtomicBoolean();
@@ -98,7 +99,6 @@ public class WebFluxIntegrationRequestMappingHandlerMapping extends RequestMappi
}
@Override
@SuppressWarnings("unchecked")
public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException {
if (isHandler(bean.getClass())) {
unregisterMapping(getMappingForEndpoint((WebFluxInboundEndpoint) bean));
@@ -148,21 +148,13 @@ public class WebFluxIntegrationRequestMappingHandlerMapping extends RequestMappi
CrossOrigin crossOrigin = ((BaseHttpInboundEndpoint) handler).getCrossOrigin();
if (crossOrigin != null) {
CorsConfiguration config = new CorsConfiguration();
for (String origin : crossOrigin.getOrigin()) {
config.addAllowedOrigin(origin);
}
for (RequestMethod requestMethod : crossOrigin.getMethod()) {
config.addAllowedMethod(requestMethod.name());
}
for (String header : crossOrigin.getAllowedHeaders()) {
config.addAllowedHeader(header);
}
for (String header : crossOrigin.getExposedHeaders()) {
config.addExposedHeader(header);
}
if (crossOrigin.getAllowCredentials() != null) {
config.setAllowCredentials(crossOrigin.getAllowCredentials());
}
config.setAllowedOrigins(Arrays.asList(crossOrigin.getOrigin()));
config.setAllowedHeaders(Arrays.asList(crossOrigin.getAllowedHeaders()));
config.setExposedHeaders(Arrays.asList(crossOrigin.getExposedHeaders()));
config.setAllowCredentials(crossOrigin.getAllowCredentials());
if (crossOrigin.getMaxAge() != -1) {
config.setMaxAge(crossOrigin.getMaxAge());
}
@@ -172,7 +164,9 @@ public class WebFluxIntegrationRequestMappingHandlerMapping extends RequestMappi
}
}
if (CollectionUtils.isEmpty(config.getAllowedHeaders())) {
for (NameValueExpression<String> headerExpression : mappingInfo.getHeadersCondition().getExpressions()) {
for (NameValueExpression<String> headerExpression :
mappingInfo.getHeadersCondition().getExpressions()) {
if (!headerExpression.isNegated()) {
config.addAllowedHeader(headerExpression.getName());
}