Fix some Sonar smells
This commit is contained in:
@@ -998,8 +998,8 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
||||
}
|
||||
}
|
||||
|
||||
private void processFile(Session<F> session, String directory, String subDirectory, List<F> lsFiles,
|
||||
boolean recursion, F file) throws IOException {
|
||||
private void processFile(Session<F> session, String directory, String subDirectory, // NOSONAR - complexity
|
||||
List<F> lsFiles, boolean recursion, F file) throws IOException {
|
||||
|
||||
F fileToAdd = file;
|
||||
if (recursion && StringUtils.hasText(subDirectory)) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -57,35 +57,16 @@ public class JmsChannelParser extends AbstractChannelParser {
|
||||
builder.addPropertyReference(JmsParserUtils.CONNECTION_FACTORY_PROPERTY,
|
||||
JmsParserUtils.determineConnectionFactoryBeanName(element, parserContext));
|
||||
if ("channel".equals(element.getLocalName())) {
|
||||
this.parseDestination(element, parserContext, builder, "queue");
|
||||
parseDestination(element, parserContext, builder, "queue");
|
||||
}
|
||||
else if ("publish-subscribe-channel".equals(element.getLocalName())) {
|
||||
this.parseDestination(element, parserContext, builder, "topic");
|
||||
parseDestination(element, parserContext, builder, "topic");
|
||||
}
|
||||
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "max-subscribers");
|
||||
|
||||
String containerType = element.getAttribute(CONTAINER_TYPE_ATTRIBUTE);
|
||||
String containerClass = element.getAttribute(CONTAINER_CLASS_ATTRIBUTE);
|
||||
if (!StringUtils.hasText(containerClass) && StringUtils.hasText(containerType)) {
|
||||
if ("default".equals(containerType)) {
|
||||
containerClass = "org.springframework.jms.listener.DefaultMessageListenerContainer";
|
||||
}
|
||||
else if ("simple".equals(containerType)) {
|
||||
containerClass = "org.springframework.jms.listener.SimpleMessageListenerContainer";
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Schema docs tell the user to ensure that, if they supply a container-class, it
|
||||
* is their responsibility to set the container-type appropriately, based on the superclass
|
||||
* of their implementation (default="default"). If it is set incorrectly, some attributes
|
||||
* may not be applied.
|
||||
*
|
||||
* We cannot reliably infer it here.
|
||||
*/
|
||||
if (StringUtils.hasText(containerClass)) {
|
||||
builder.addPropertyValue("containerType", containerClass);
|
||||
}
|
||||
setContainerClass(element, builder, containerType);
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "receive-timeout");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "task-executor");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "transaction-manager");
|
||||
@@ -98,38 +79,12 @@ public class JmsChannelParser extends AbstractChannelParser {
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "time-to-live");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "priority");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "explicit-qos-enabled");
|
||||
String cache = element.getAttribute("cache");
|
||||
if (StringUtils.hasText(cache)) {
|
||||
if (containerType.startsWith("simple")) {
|
||||
if (!("auto".equals(cache) || "consumer".equals(cache))) {
|
||||
parserContext.getReaderContext().warning(
|
||||
"'cache' attribute not actively supported for listener container of type \"simple\". " +
|
||||
"Effective runtime behavior will be equivalent to \"consumer\" / \"auto\".", element);
|
||||
}
|
||||
}
|
||||
else {
|
||||
builder.addPropertyValue("cacheLevelName", "CACHE_" + cache.toUpperCase());
|
||||
}
|
||||
}
|
||||
Integer acknowledgeMode = this.parseAcknowledgeMode(element, parserContext);
|
||||
if (acknowledgeMode != null) {
|
||||
if (acknowledgeMode == Session.SESSION_TRANSACTED) {
|
||||
builder.addPropertyValue("sessionTransacted", Boolean.TRUE);
|
||||
}
|
||||
else {
|
||||
builder.addPropertyValue("sessionAcknowledgeMode", acknowledgeMode);
|
||||
}
|
||||
}
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "concurrency");
|
||||
|
||||
String prefetch = element.getAttribute("prefetch");
|
||||
if (StringUtils.hasText(prefetch) && containerType.startsWith("default")) {
|
||||
builder.addPropertyValue("maxMessagesPerTask", Integer.valueOf(prefetch));
|
||||
}
|
||||
setCache(element, parserContext, builder, containerType);
|
||||
setAcknowledgeMode(element, parserContext, builder, containerType);
|
||||
return builder;
|
||||
}
|
||||
|
||||
private void parseDestination(Element element, ParserContext parserContext, BeanDefinitionBuilder builder,
|
||||
private static void parseDestination(Element element, ParserContext parserContext, BeanDefinitionBuilder builder,
|
||||
String type) {
|
||||
|
||||
boolean isPubSub = "topic".equals(type);
|
||||
@@ -161,7 +116,68 @@ public class JmsChannelParser extends AbstractChannelParser {
|
||||
}
|
||||
}
|
||||
|
||||
private Integer parseAcknowledgeMode(Element ele, ParserContext parserContext) {
|
||||
private static void setContainerClass(Element element, BeanDefinitionBuilder builder, String containerType) {
|
||||
String containerClass = element.getAttribute(CONTAINER_CLASS_ATTRIBUTE);
|
||||
if (!StringUtils.hasText(containerClass) && StringUtils.hasText(containerType)) {
|
||||
if ("default".equals(containerType)) {
|
||||
containerClass = "org.springframework.jms.listener.DefaultMessageListenerContainer";
|
||||
}
|
||||
else if ("simple".equals(containerType)) {
|
||||
containerClass = "org.springframework.jms.listener.SimpleMessageListenerContainer";
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Schema docs tell the user to ensure that, if they supply a container-class, it
|
||||
* is their responsibility to set the container-type appropriately, based on the superclass
|
||||
* of their implementation (default="default"). If it is set incorrectly, some attributes
|
||||
* may not be applied.
|
||||
* We cannot reliably infer it here.
|
||||
*/
|
||||
if (StringUtils.hasText(containerClass)) {
|
||||
builder.addPropertyValue("containerType", containerClass);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setCache(Element element, ParserContext parserContext, BeanDefinitionBuilder builder,
|
||||
String containerType) {
|
||||
|
||||
String cache = element.getAttribute("cache");
|
||||
if (StringUtils.hasText(cache)) {
|
||||
if (containerType.startsWith("simple")) {
|
||||
if (!("auto".equals(cache) || "consumer".equals(cache))) {
|
||||
parserContext.getReaderContext().warning(
|
||||
"'cache' attribute not actively supported for listener container of type \"simple\". " +
|
||||
"Effective runtime behavior will be equivalent to \"consumer\" / \"auto\".",
|
||||
element);
|
||||
}
|
||||
}
|
||||
else {
|
||||
builder.addPropertyValue("cacheLevelName", "CACHE_" + cache.toUpperCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void setAcknowledgeMode(Element element, ParserContext parserContext, BeanDefinitionBuilder builder,
|
||||
String containerType) {
|
||||
|
||||
Integer acknowledgeMode = parseAcknowledgeMode(element, parserContext);
|
||||
if (acknowledgeMode != null) {
|
||||
if (acknowledgeMode == Session.SESSION_TRANSACTED) {
|
||||
builder.addPropertyValue("sessionTransacted", Boolean.TRUE);
|
||||
}
|
||||
else {
|
||||
builder.addPropertyValue("sessionAcknowledgeMode", acknowledgeMode);
|
||||
}
|
||||
}
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "concurrency");
|
||||
|
||||
String prefetch = element.getAttribute("prefetch");
|
||||
if (StringUtils.hasText(prefetch) && containerType.startsWith("default")) {
|
||||
builder.addPropertyValue("maxMessagesPerTask", Integer.valueOf(prefetch));
|
||||
}
|
||||
}
|
||||
|
||||
private static Integer parseAcknowledgeMode(Element ele, ParserContext parserContext) {
|
||||
String acknowledge = ele.getAttribute(ACKNOWLEDGE_ATTRIBUTE);
|
||||
if (StringUtils.hasText(acknowledge)) {
|
||||
int acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2020 the original author or authors.
|
||||
* Copyright 2015-2021 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.
|
||||
@@ -128,68 +128,92 @@ public class StompHeaderMapper implements HeaderMapper<StompHeaders> {
|
||||
}
|
||||
|
||||
private void setStompHeader(StompHeaders target, String name, Object value) {
|
||||
if (StompHeaders.CONTENT_LENGTH.equals(name)) {
|
||||
if (value instanceof Number) {
|
||||
target.setContentLength(((Number) value).longValue());
|
||||
}
|
||||
else if (value instanceof String) {
|
||||
target.setContentLength(Long.parseLong((String) value));
|
||||
}
|
||||
else {
|
||||
Class<?> clazz = (value != null) ? value.getClass() : null;
|
||||
throw new IllegalArgumentException(
|
||||
"Expected Number or String value for 'content-length' header value, but received: " + clazz);
|
||||
}
|
||||
}
|
||||
else if (StompHeaders.CONTENT_TYPE.equals(name) || MessageHeaders.CONTENT_TYPE.equals(name)) {
|
||||
MimeType contentType = target.getContentType();
|
||||
if (contentType == null || StompHeaders.CONTENT_TYPE.equals(name)) {
|
||||
if (value instanceof MediaType) {
|
||||
target.setContentType((MediaType) value);
|
||||
}
|
||||
else if (value instanceof String) {
|
||||
target.setContentType(MediaType.parseMediaType((String) value));
|
||||
switch (name) {
|
||||
case StompHeaders.CONTENT_LENGTH:
|
||||
setContentLength(target, value);
|
||||
break;
|
||||
|
||||
case StompHeaders.CONTENT_TYPE:
|
||||
case MessageHeaders.CONTENT_TYPE:
|
||||
setContentType(target, name, value);
|
||||
break;
|
||||
|
||||
case StompHeaders.DESTINATION:
|
||||
case IntegrationStompHeaders.DESTINATION:
|
||||
setDestination(target, value);
|
||||
break;
|
||||
|
||||
case StompHeaders.RECEIPT:
|
||||
case IntegrationStompHeaders.RECEIPT:
|
||||
setReceipt(target, value);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (value instanceof String) {
|
||||
target.set(name, (String) value);
|
||||
}
|
||||
else {
|
||||
Class<?> clazz = (value != null) ? value.getClass() : null;
|
||||
throw new IllegalArgumentException(
|
||||
"Expected MediaType or String value for 'content-type' header value, but received: "
|
||||
+ clazz);
|
||||
"Expected String value for any generic STOMP header value, but received: " + clazz);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (StompHeaders.DESTINATION.equals(name) || IntegrationStompHeaders.DESTINATION.equals(name)) {
|
||||
if (value instanceof String) {
|
||||
target.setDestination((String) value);
|
||||
}
|
||||
else {
|
||||
Class<?> clazz = (value != null) ? value.getClass() : null;
|
||||
throw new IllegalArgumentException(
|
||||
"Expected String value for 'destination' header value, but received: " + clazz);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setContentLength(StompHeaders target, Object value) {
|
||||
if (value instanceof Number) {
|
||||
target.setContentLength(((Number) value).longValue());
|
||||
}
|
||||
else if (StompHeaders.RECEIPT.equals(name) || IntegrationStompHeaders.RECEIPT.equals(name)) {
|
||||
if (value instanceof String) {
|
||||
target.setReceipt((String) value);
|
||||
}
|
||||
else {
|
||||
Class<?> clazz = (value != null) ? value.getClass() : null;
|
||||
throw new IllegalArgumentException(
|
||||
"Expected String value for 'receipt' header value, but received: " + clazz);
|
||||
}
|
||||
else if (value instanceof String) {
|
||||
target.setContentLength(Long.parseLong((String) value));
|
||||
}
|
||||
else {
|
||||
if (value instanceof String) {
|
||||
target.set(name, (String) value);
|
||||
Class<?> clazz = (value != null) ? value.getClass() : null;
|
||||
throw new IllegalArgumentException(
|
||||
"Expected Number or String value for 'content-length' header value, but received: " + clazz);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setContentType(StompHeaders target, String name, Object value) {
|
||||
MimeType contentType = target.getContentType();
|
||||
if (contentType == null || StompHeaders.CONTENT_TYPE.equals(name)) {
|
||||
if (value instanceof MediaType) {
|
||||
target.setContentType((MediaType) value);
|
||||
}
|
||||
else if (value instanceof String) {
|
||||
target.setContentType(MediaType.parseMediaType((String) value));
|
||||
}
|
||||
else {
|
||||
Class<?> clazz = (value != null) ? value.getClass() : null;
|
||||
throw new IllegalArgumentException(
|
||||
"Expected String value for any generic STOMP header value, but received: " + clazz);
|
||||
"Expected MediaType or String value for 'content-type' header value, but received: "
|
||||
+ clazz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void setReceipt(StompHeaders target, Object value) {
|
||||
if (value instanceof String) {
|
||||
target.setReceipt((String) value);
|
||||
}
|
||||
else {
|
||||
Class<?> clazz = (value != null) ? value.getClass() : null;
|
||||
throw new IllegalArgumentException(
|
||||
"Expected String value for 'receipt' header value, but received: " + clazz);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setDestination(StompHeaders target, Object value) {
|
||||
if (value instanceof String) {
|
||||
target.setDestination((String) value);
|
||||
}
|
||||
else {
|
||||
Class<?> clazz = (value != null) ? value.getClass() : null;
|
||||
throw new IllegalArgumentException(
|
||||
"Expected String value for 'destination' header value, but received: " + clazz);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toHeaders(StompHeaders source) {
|
||||
Map<String, Object> target = new HashMap<>();
|
||||
@@ -211,7 +235,7 @@ public class StompHeaderMapper implements HeaderMapper<StompHeaders> {
|
||||
}
|
||||
|
||||
|
||||
private boolean shouldMapHeader(String headerName, String[] patterns) {
|
||||
private static boolean shouldMapHeader(String headerName, String[] patterns) {
|
||||
if (patterns != null && patterns.length > 0) {
|
||||
for (String pattern : patterns) {
|
||||
if (PatternMatchUtils.simpleMatch(pattern, headerName)) {
|
||||
|
||||
Reference in New Issue
Block a user