Skip to content

Commit 44a4523

Browse files
committed
Fix new Sonar smells
1 parent 8d3d871 commit 44a4523

File tree

6 files changed

+79
-70
lines changed

6 files changed

+79
-70
lines changed

spring-integration-core/src/main/java/org/springframework/integration/codec/kryo/AbstractKryoRegistrar.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2019 the original author or authors.
2+
* Copyright 2015-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@
3232
*/
3333
public abstract class AbstractKryoRegistrar implements KryoRegistrar {
3434

35-
protected static final Kryo kryo = new Kryo(); // NOSONAR TODO uppercase in 5.2
35+
protected static final Kryo KRYO = new Kryo();
3636

3737
protected final Log log = LogFactory.getLog(getClass()); // NOSONAR property is final
3838

spring-integration-core/src/main/java/org/springframework/integration/codec/kryo/KryoClassListRegistrar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public List<Registration> getRegistrations() {
6868
if (!CollectionUtils.isEmpty(this.registeredClasses)) {
6969
for (int i = 0; i < this.registeredClasses.size(); i++) {
7070
registrations.add(new Registration(this.registeredClasses.get(i),
71-
kryo.getSerializer(this.registeredClasses.get(i)), i + this.initialValue));
71+
KRYO.getSerializer(this.registeredClasses.get(i)), i + this.initialValue));
7272
}
7373
}
7474
return registrations;

spring-integration-core/src/main/java/org/springframework/integration/codec/kryo/KryoClassMapRegistrar.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2019 the original author or authors.
2+
* Copyright 2015-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,7 +46,7 @@ public List<Registration> getRegistrations() {
4646
if (!CollectionUtils.isEmpty(this.registeredClasses)) {
4747
for (Map.Entry<Integer, Class<?>> entry : this.registeredClasses.entrySet()) {
4848
registrations.add(
49-
new Registration(entry.getValue(), kryo.getSerializer(entry.getValue()), entry.getKey()));
49+
new Registration(entry.getValue(), KRYO.getSerializer(entry.getValue()), entry.getKey()));
5050
}
5151
}
5252
return registrations;

spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpIntegrationConfigurationInitializer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,15 +37,15 @@
3737
*/
3838
public class HttpIntegrationConfigurationInitializer implements IntegrationConfigurationInitializer {
3939

40-
private static final Log logger = LogFactory.getLog(HttpIntegrationConfigurationInitializer.class);
40+
private static final Log LOGGER = LogFactory.getLog(HttpIntegrationConfigurationInitializer.class);
4141

4242
@Override
4343
public void initialize(ConfigurableListableBeanFactory beanFactory) throws BeansException {
4444
if (beanFactory instanceof BeanDefinitionRegistry) {
4545
registerRequestMappingHandlerMappingIfNecessary((BeanDefinitionRegistry) beanFactory);
4646
}
4747
else {
48-
logger.warn("'IntegrationRequestMappingHandlerMapping' isn't registered because 'beanFactory'" +
48+
LOGGER.warn("'IntegrationRequestMappingHandlerMapping' isn't registered because 'beanFactory'" +
4949
" isn't an instance of `BeanDefinitionRegistry`.");
5050
}
5151
}

spring-integration-http/src/main/java/org/springframework/integration/http/inbound/IntegrationRequestMappingHandlerMapping.java

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -172,43 +172,47 @@ protected void detectHandlerMethods(Object handlerArg) {
172172
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) {
173173
CrossOrigin crossOrigin = ((BaseHttpInboundEndpoint) handler).getCrossOrigin();
174174
if (crossOrigin != null) {
175-
CorsConfiguration config = new CorsConfiguration();
176-
for (RequestMethod requestMethod : crossOrigin.getMethod()) {
177-
config.addAllowedMethod(requestMethod.name());
178-
}
179-
config.setAllowedHeaders(Arrays.asList(crossOrigin.getAllowedHeaders()));
180-
config.setExposedHeaders(Arrays.asList(crossOrigin.getExposedHeaders()));
181-
Boolean allowCredentials = crossOrigin.getAllowCredentials();
182-
config.setAllowCredentials(allowCredentials);
183-
List<String> allowedOrigins = Arrays.asList(crossOrigin.getOrigin());
184-
if (Boolean.TRUE.equals(allowCredentials)
185-
&& CollectionUtils.contains(allowedOrigins.iterator(), CorsConfiguration.ALL)) {
186-
config.setAllowedOriginPatterns(allowedOrigins);
187-
}
188-
else {
189-
config.setAllowedOrigins(allowedOrigins);
190-
}
175+
return buildCorsConfiguration(crossOrigin, mappingInfo);
176+
}
177+
return null;
178+
}
191179

192-
if (crossOrigin.getMaxAge() != -1) {
193-
config.setMaxAge(crossOrigin.getMaxAge());
194-
}
195-
if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
196-
for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
197-
config.addAllowedMethod(allowedMethod.name());
198-
}
180+
private static CorsConfiguration buildCorsConfiguration(CrossOrigin crossOrigin, RequestMappingInfo mappingInfo) {
181+
CorsConfiguration config = new CorsConfiguration();
182+
for (RequestMethod requestMethod : crossOrigin.getMethod()) {
183+
config.addAllowedMethod(requestMethod.name());
184+
}
185+
config.setAllowedHeaders(Arrays.asList(crossOrigin.getAllowedHeaders()));
186+
config.setExposedHeaders(Arrays.asList(crossOrigin.getExposedHeaders()));
187+
Boolean allowCredentials = crossOrigin.getAllowCredentials();
188+
config.setAllowCredentials(allowCredentials);
189+
List<String> allowedOrigins = Arrays.asList(crossOrigin.getOrigin());
190+
if (Boolean.TRUE.equals(allowCredentials)
191+
&& CollectionUtils.contains(allowedOrigins.iterator(), CorsConfiguration.ALL)) {
192+
config.setAllowedOriginPatterns(allowedOrigins);
193+
}
194+
else {
195+
config.setAllowedOrigins(allowedOrigins);
196+
}
197+
198+
if (crossOrigin.getMaxAge() != -1) {
199+
config.setMaxAge(crossOrigin.getMaxAge());
200+
}
201+
if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
202+
for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
203+
config.addAllowedMethod(allowedMethod.name());
199204
}
200-
if (CollectionUtils.isEmpty(config.getAllowedHeaders())) {
201-
for (NameValueExpression<String> headerExpression :
202-
mappingInfo.getHeadersCondition().getExpressions()) {
205+
}
206+
if (CollectionUtils.isEmpty(config.getAllowedHeaders())) {
207+
for (NameValueExpression<String> headerExpression :
208+
mappingInfo.getHeadersCondition().getExpressions()) {
203209

204-
if (!headerExpression.isNegated()) {
205-
config.addAllowedHeader(headerExpression.getName());
206-
}
210+
if (!headerExpression.isNegated()) {
211+
config.addAllowedHeader(headerExpression.getName());
207212
}
208213
}
209-
return config.applyPermitDefaultValues();
210214
}
211-
return null;
215+
return config.applyPermitDefaultValues();
212216
}
213217

214218
/**

spring-integration-webflux/src/main/java/org/springframework/integration/webflux/inbound/WebFluxIntegrationRequestMappingHandlerMapping.java

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -148,45 +148,50 @@ private RequestMappingInfo getMappingForEndpoint(WebFluxInboundEndpoint endpoint
148148
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) {
149149
CrossOrigin crossOrigin = ((BaseHttpInboundEndpoint) handler).getCrossOrigin();
150150
if (crossOrigin != null) {
151-
CorsConfiguration config = new CorsConfiguration();
152-
for (RequestMethod requestMethod : crossOrigin.getMethod()) {
153-
config.addAllowedMethod(requestMethod.name());
154-
}
155-
config.setAllowedHeaders(Arrays.asList(crossOrigin.getAllowedHeaders()));
156-
config.setExposedHeaders(Arrays.asList(crossOrigin.getExposedHeaders()));
157-
Boolean allowCredentials = crossOrigin.getAllowCredentials();
158-
config.setAllowCredentials(allowCredentials);
159-
List<String> allowedOrigins = Arrays.asList(crossOrigin.getOrigin());
160-
if (Boolean.TRUE.equals(allowCredentials)
161-
&& CollectionUtils.contains(allowedOrigins.iterator(), CorsConfiguration.ALL)) {
162-
config.setAllowedOriginPatterns(allowedOrigins);
163-
}
164-
else {
165-
config.setAllowedOrigins(allowedOrigins);
166-
}
151+
return buildCorsConfiguration(crossOrigin, mappingInfo);
152+
}
153+
return null;
154+
}
167155

168-
if (crossOrigin.getMaxAge() != -1) {
169-
config.setMaxAge(crossOrigin.getMaxAge());
170-
}
171-
if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
172-
for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
173-
config.addAllowedMethod(allowedMethod.name());
174-
}
156+
private static CorsConfiguration buildCorsConfiguration(CrossOrigin crossOrigin, RequestMappingInfo mappingInfo) {
157+
CorsConfiguration config = new CorsConfiguration();
158+
for (RequestMethod requestMethod : crossOrigin.getMethod()) {
159+
config.addAllowedMethod(requestMethod.name());
160+
}
161+
config.setAllowedHeaders(Arrays.asList(crossOrigin.getAllowedHeaders()));
162+
config.setExposedHeaders(Arrays.asList(crossOrigin.getExposedHeaders()));
163+
Boolean allowCredentials = crossOrigin.getAllowCredentials();
164+
config.setAllowCredentials(allowCredentials);
165+
List<String> allowedOrigins = Arrays.asList(crossOrigin.getOrigin());
166+
if (Boolean.TRUE.equals(allowCredentials)
167+
&& CollectionUtils.contains(allowedOrigins.iterator(), CorsConfiguration.ALL)) {
168+
config.setAllowedOriginPatterns(allowedOrigins);
169+
}
170+
else {
171+
config.setAllowedOrigins(allowedOrigins);
172+
}
173+
174+
if (crossOrigin.getMaxAge() != -1) {
175+
config.setMaxAge(crossOrigin.getMaxAge());
176+
}
177+
if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
178+
for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
179+
config.addAllowedMethod(allowedMethod.name());
175180
}
176-
if (CollectionUtils.isEmpty(config.getAllowedHeaders())) {
177-
for (NameValueExpression<String> headerExpression :
178-
mappingInfo.getHeadersCondition().getExpressions()) {
181+
}
182+
if (CollectionUtils.isEmpty(config.getAllowedHeaders())) {
183+
for (NameValueExpression<String> headerExpression :
184+
mappingInfo.getHeadersCondition().getExpressions()) {
179185

180-
if (!headerExpression.isNegated()) {
181-
config.addAllowedHeader(headerExpression.getName());
182-
}
186+
if (!headerExpression.isNegated()) {
187+
config.addAllowedHeader(headerExpression.getName());
183188
}
184189
}
185-
return config.applyPermitDefaultValues();
186190
}
187-
return null;
191+
return config.applyPermitDefaultValues();
188192
}
189193

194+
190195
/**
191196
* {@link org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport}s
192197
* may depend on auto-created {@code requestChannel}s, so MVC Handlers detection should be postponed

0 commit comments

Comments
 (0)