Fix Sonar vulnerabilities for varargs
* Fix smell for static `AmqpInboundGateway.attributesHolder` * Fix readOnlyHeaders in the `MessageBuilder`
This commit is contained in:
committed by
Gary Russell
parent
1d08d3bdc2
commit
315f0e711f
@@ -67,7 +67,7 @@ import com.rabbitmq.client.Channel;
|
||||
*/
|
||||
public class AmqpInboundGateway extends MessagingGatewaySupport {
|
||||
|
||||
private static final ThreadLocal<AttributeAccessor> attributesHolder = new ThreadLocal<>();
|
||||
private static final ThreadLocal<AttributeAccessor> ATTRIBUTES_HOLDER = new ThreadLocal<>();
|
||||
|
||||
private final AbstractMessageListenerContainer messageListenerContainer;
|
||||
|
||||
@@ -75,9 +75,9 @@ public class AmqpInboundGateway extends MessagingGatewaySupport {
|
||||
|
||||
private final boolean amqpTemplateExplicitlySet;
|
||||
|
||||
private volatile MessageConverter amqpMessageConverter = new SimpleMessageConverter();
|
||||
private MessageConverter amqpMessageConverter = new SimpleMessageConverter();
|
||||
|
||||
private volatile AmqpHeaderMapper headerMapper = DefaultAmqpHeaderMapper.inboundMapper();
|
||||
private AmqpHeaderMapper headerMapper = DefaultAmqpHeaderMapper.inboundMapper();
|
||||
|
||||
private Address defaultReplyTo;
|
||||
|
||||
@@ -244,12 +244,12 @@ public class AmqpInboundGateway extends MessagingGatewaySupport {
|
||||
boolean needHolder = getErrorChannel() != null && this.retryTemplate == null;
|
||||
boolean needAttributes = needHolder || this.retryTemplate != null;
|
||||
if (needHolder) {
|
||||
attributesHolder.set(ErrorMessageUtils.getAttributeAccessor(null, null));
|
||||
ATTRIBUTES_HOLDER.set(ErrorMessageUtils.getAttributeAccessor(null, null));
|
||||
}
|
||||
if (needAttributes) {
|
||||
AttributeAccessor attributes = this.retryTemplate != null
|
||||
? RetrySynchronizationManager.getContext()
|
||||
: attributesHolder.get();
|
||||
: ATTRIBUTES_HOLDER.get();
|
||||
if (attributes != null) {
|
||||
attributes.setAttribute(ErrorMessageUtils.INPUT_MESSAGE_CONTEXT_KEY, message);
|
||||
attributes.setAttribute(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE, amqpMessage);
|
||||
@@ -259,7 +259,7 @@ public class AmqpInboundGateway extends MessagingGatewaySupport {
|
||||
|
||||
@Override
|
||||
protected AttributeAccessor getErrorMessageAttributes(org.springframework.messaging.Message<?> message) {
|
||||
AttributeAccessor attributes = attributesHolder.get();
|
||||
AttributeAccessor attributes = ATTRIBUTES_HOLDER.get();
|
||||
if (attributes == null) {
|
||||
return super.getErrorMessageAttributes(message);
|
||||
}
|
||||
@@ -281,7 +281,7 @@ public class AmqpInboundGateway extends MessagingGatewaySupport {
|
||||
}
|
||||
}
|
||||
finally {
|
||||
attributesHolder.remove();
|
||||
ATTRIBUTES_HOLDER.remove();
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -300,8 +300,8 @@ public class AmqpInboundGateway extends MessagingGatewaySupport {
|
||||
private org.springframework.messaging.Message<Object> convert(Message message, Channel channel) {
|
||||
Map<String, Object> headers;
|
||||
Object payload;
|
||||
boolean isManualAck = AmqpInboundGateway.this.messageListenerContainer
|
||||
.getAcknowledgeMode() == AcknowledgeMode.MANUAL;
|
||||
boolean isManualAck =
|
||||
AmqpInboundGateway.this.messageListenerContainer.getAcknowledgeMode() == AcknowledgeMode.MANUAL;
|
||||
try {
|
||||
if (AmqpInboundGateway.this.batchingStrategy.canDebatch(message.getMessageProperties())) {
|
||||
List<Object> payloads = new ArrayList<>();
|
||||
@@ -325,8 +325,9 @@ public class AmqpInboundGateway extends MessagingGatewaySupport {
|
||||
MessageChannel errorChannel = getErrorChannel();
|
||||
if (errorChannel != null) {
|
||||
setAttributesIfNecessary(message, null);
|
||||
AmqpInboundGateway.this.messagingTemplate.send(errorChannel, buildErrorMessage(null,
|
||||
EndpointUtils.errorMessagePayload(message, channel, isManualAck, e)));
|
||||
AmqpInboundGateway.this.messagingTemplate.send(errorChannel,
|
||||
buildErrorMessage(null,
|
||||
EndpointUtils.errorMessagePayload(message, channel, isManualAck, e)));
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
@@ -383,8 +384,7 @@ public class AmqpInboundGateway extends MessagingGatewaySupport {
|
||||
"and the `defaultReplyTo` hasn't been configured.");
|
||||
}
|
||||
else {
|
||||
AmqpInboundGateway.this.amqpTemplate.convertAndSend(reply.getPayload(),
|
||||
messagePostProcessor);
|
||||
AmqpInboundGateway.this.amqpTemplate.convertAndSend(reply.getPayload(), messagePostProcessor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.integration.channel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.integration.core.MessageSelector;
|
||||
@@ -40,6 +41,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
public class ChannelPurger {
|
||||
|
||||
@@ -58,18 +60,18 @@ public class ChannelPurger {
|
||||
Assert.notNull(channels[0], "channel must not be null");
|
||||
}
|
||||
this.selector = selector;
|
||||
this.channels = channels;
|
||||
this.channels = Arrays.copyOf(channels, channels.length);
|
||||
}
|
||||
|
||||
|
||||
public final List<Message<?>> purge() {
|
||||
List<Message<?>> purgedMessages = new ArrayList<Message<?>>();
|
||||
List<Message<?>> purgedMessages = new ArrayList<>();
|
||||
for (QueueChannel channel : this.channels) {
|
||||
List<Message<?>> results = (this.selector == null) ?
|
||||
channel.clear() : channel.purge(this.selector);
|
||||
if (results != null) {
|
||||
purgedMessages.addAll(results);
|
||||
}
|
||||
List<Message<?>> results =
|
||||
this.selector == null
|
||||
? channel.clear()
|
||||
: channel.purge(this.selector);
|
||||
purgedMessages.addAll(results);
|
||||
}
|
||||
return purgedMessages;
|
||||
}
|
||||
|
||||
@@ -97,11 +97,11 @@ public class CacheRequestHandlerAdvice extends AbstractRequestHandlerAdvice
|
||||
* Create a {@link CacheRequestHandlerAdvice} instance based on the provided name of caches
|
||||
* and {@link CacheableOperation} as default one.
|
||||
* This can be overridden by the {@link #setCacheOperations}.
|
||||
* @param cacheNames the name of caches to use in the advice.
|
||||
* @param cacheNamesArg the name of caches to use in the advice.
|
||||
* @see #setCacheOperations
|
||||
*/
|
||||
public CacheRequestHandlerAdvice(String... cacheNames) {
|
||||
this.cacheNames = cacheNames;
|
||||
public CacheRequestHandlerAdvice(String... cacheNamesArg) {
|
||||
this.cacheNames = cacheNamesArg != null ? Arrays.copyOf(cacheNamesArg, cacheNamesArg.length) : null;
|
||||
CacheableOperation.Builder builder = new CacheableOperation.Builder();
|
||||
builder.setName(toString());
|
||||
this.cacheOperations.add(builder.build());
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.messaging.Message;
|
||||
/**
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
*/
|
||||
@@ -39,7 +40,7 @@ public class DefaultMessageBuilderFactory implements MessageBuilderFactory {
|
||||
* @since 4.3.2
|
||||
*/
|
||||
public void setReadOnlyHeaders(String... readOnlyHeaders) {
|
||||
this.readOnlyHeaders = Arrays.copyOf(readOnlyHeaders, readOnlyHeaders.length);
|
||||
this.readOnlyHeaders = readOnlyHeaders != null ? Arrays.copyOf(readOnlyHeaders, readOnlyHeaders.length) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.integration.support;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -309,7 +310,7 @@ public final class MessageBuilder<T> extends AbstractIntegrationMessageBuilder<T
|
||||
* @see IntegrationMessageHeaderAccessor#isReadOnly(String)
|
||||
*/
|
||||
public MessageBuilder<T> readOnlyHeaders(String... readOnlyHeaders) {
|
||||
this.readOnlyHeaders = readOnlyHeaders;
|
||||
this.readOnlyHeaders = readOnlyHeaders != null ? Arrays.copyOf(readOnlyHeaders, readOnlyHeaders.length) : null;
|
||||
this.headerAccessor.setReadOnlyHeaders(readOnlyHeaders);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
*/
|
||||
@@ -76,7 +77,8 @@ public class MapMessageConverter implements MessageConverter, BeanFactoryAware {
|
||||
* @param headerNames The header names.
|
||||
*/
|
||||
public void setHeaderNames(String... headerNames) {
|
||||
this.headerNames = headerNames;
|
||||
Assert.notEmpty(headerNames, "at least one header name is required");
|
||||
this.headerNames = Arrays.copyOf(headerNames, headerNames.length);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,9 +118,9 @@ public class MapMessageConverter implements MessageConverter, BeanFactoryAware {
|
||||
@Nullable
|
||||
@Override
|
||||
public Object fromMessage(Message<?> message, Class<?> clazz) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("payload", message.getPayload());
|
||||
Map<String, Object> headers = new HashMap<String, Object>();
|
||||
Map<String, Object> headers = new HashMap<>();
|
||||
for (String headerName : this.headerNames) {
|
||||
Object header = message.getHeaders().get(headerName);
|
||||
if (header != null) {
|
||||
|
||||
@@ -112,7 +112,8 @@ public final class JacksonJsonUtils {
|
||||
|
||||
WhitelistTypeResolverBuilder(String... trustedPackages) {
|
||||
super(ObjectMapper.DefaultTyping.NON_FINAL);
|
||||
this.trustedPackages = trustedPackages;
|
||||
this.trustedPackages =
|
||||
trustedPackages != null ? Arrays.copyOf(trustedPackages, trustedPackages.length) : null;
|
||||
|
||||
init(JsonTypeInfo.Id.CLASS, null)
|
||||
.inclusion(JsonTypeInfo.As.PROPERTY);
|
||||
|
||||
@@ -45,7 +45,7 @@ public class HeaderFilter extends IntegrationObjectSupport implements Transforme
|
||||
|
||||
public HeaderFilter(String... headersToRemove) {
|
||||
Assert.notEmpty(headersToRemove, "At least one header name to remove is required.");
|
||||
this.headersToRemove = headersToRemove;
|
||||
this.headersToRemove = Arrays.copyOf(headersToRemove, headersToRemove.length);
|
||||
}
|
||||
|
||||
public void setPatternMatch(boolean patternMatch) {
|
||||
@@ -75,7 +75,7 @@ public class HeaderFilter extends IntegrationObjectSupport implements Transforme
|
||||
|
||||
@Override
|
||||
public Message<?> transform(Message<?> message) {
|
||||
AbstractIntegrationMessageBuilder<?> builder = this.getMessageBuilderFactory().fromMessage(message);
|
||||
AbstractIntegrationMessageBuilder<?> builder = getMessageBuilderFactory().fromMessage(message);
|
||||
if (this.patternMatch) {
|
||||
builder.removeHeaders(this.headersToRemove);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
@@ -26,6 +27,7 @@ import org.springframework.integration.file.FileReadingMessageSource;
|
||||
import org.springframework.integration.file.filters.CompositeFileListFilter;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.file.locking.AbstractFileLockerFilter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -76,7 +78,8 @@ public class FileReadingMessageSourceFactoryBean extends AbstractFactoryBean<Fil
|
||||
}
|
||||
|
||||
public void setWatchEvents(FileReadingMessageSource.WatchEventType... watchEvents) {
|
||||
this.watchEvents = watchEvents;
|
||||
Assert.notEmpty(watchEvents, "at least one watch event type is required");
|
||||
this.watchEvents = Arrays.copyOf(watchEvents, watchEvents.length);
|
||||
}
|
||||
|
||||
public void setFilter(FileListFilter<File> filter) {
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.integration.http.inbound;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
/**
|
||||
@@ -24,26 +26,28 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
* {@link org.springframework.web.bind.annotation.CrossOrigin}.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 4.2
|
||||
*
|
||||
* @see org.springframework.web.bind.annotation.CrossOrigin
|
||||
* @see IntegrationRequestMappingHandlerMapping
|
||||
*/
|
||||
public class CrossOrigin {
|
||||
|
||||
private String[] origin = {"*"};
|
||||
private String[] origin = { "*" };
|
||||
|
||||
private String[] allowedHeaders = {"*"};
|
||||
private String[] allowedHeaders = { "*" };
|
||||
|
||||
private String[] exposedHeaders = {};
|
||||
private String[] exposedHeaders = { };
|
||||
|
||||
private RequestMethod[] method = {};
|
||||
private RequestMethod[] method = { };
|
||||
|
||||
private Boolean allowCredentials = true;
|
||||
|
||||
private long maxAge = 1800;
|
||||
|
||||
public void setOrigin(String... origin) {
|
||||
this.origin = origin;
|
||||
this.origin = Arrays.copyOf(origin, origin.length);
|
||||
}
|
||||
|
||||
public String[] getOrigin() {
|
||||
@@ -51,7 +55,7 @@ public class CrossOrigin {
|
||||
}
|
||||
|
||||
public void setAllowedHeaders(String... allowedHeaders) {
|
||||
this.allowedHeaders = allowedHeaders;
|
||||
this.allowedHeaders = Arrays.copyOf(allowedHeaders, allowedHeaders.length);
|
||||
}
|
||||
|
||||
public String[] getAllowedHeaders() {
|
||||
@@ -59,7 +63,7 @@ public class CrossOrigin {
|
||||
}
|
||||
|
||||
public void setExposedHeaders(String... exposedHeaders) {
|
||||
this.exposedHeaders = exposedHeaders;
|
||||
this.exposedHeaders = Arrays.copyOf(exposedHeaders, exposedHeaders.length);
|
||||
}
|
||||
|
||||
public String[] getExposedHeaders() {
|
||||
@@ -67,7 +71,7 @@ public class CrossOrigin {
|
||||
}
|
||||
|
||||
public void setMethod(RequestMethod... method) {
|
||||
this.method = method;
|
||||
this.method = Arrays.copyOf(method, method.length);
|
||||
}
|
||||
|
||||
public RequestMethod[] getMethod() {
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.integration.http.inbound;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@@ -26,6 +28,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
* {@link org.springframework.web.bind.annotation.RequestMapping}.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @see org.springframework.web.bind.annotation.RequestMapping
|
||||
@@ -37,15 +40,15 @@ public class RequestMapping {
|
||||
|
||||
private String[] pathPatterns;
|
||||
|
||||
private HttpMethod[] methods = new HttpMethod[]{HttpMethod.GET, HttpMethod.POST};
|
||||
private HttpMethod[] methods = { HttpMethod.GET, HttpMethod.POST };
|
||||
|
||||
private String[] params = new String[0];
|
||||
private String[] params = { };
|
||||
|
||||
private String[] headers = new String[0];
|
||||
private String[] headers = { };
|
||||
|
||||
private String[] consumes = new String[0];
|
||||
private String[] consumes = { };
|
||||
|
||||
private String[] produces = new String[0];
|
||||
private String[] produces = { };
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
@@ -57,7 +60,7 @@ public class RequestMapping {
|
||||
|
||||
public void setPathPatterns(String... pathPatterns) {
|
||||
Assert.notEmpty(pathPatterns, "at least one path pattern is required");
|
||||
this.pathPatterns = pathPatterns;
|
||||
this.pathPatterns = Arrays.copyOf(pathPatterns, pathPatterns.length);
|
||||
}
|
||||
|
||||
public String[] getPathPatterns() {
|
||||
@@ -66,7 +69,7 @@ public class RequestMapping {
|
||||
|
||||
public void setMethods(HttpMethod... supportedMethods) {
|
||||
Assert.notEmpty(supportedMethods, "at least one supported methods is required");
|
||||
this.methods = supportedMethods;
|
||||
this.methods = Arrays.copyOf(supportedMethods, supportedMethods.length);
|
||||
}
|
||||
|
||||
public HttpMethod[] getMethods() {
|
||||
@@ -75,7 +78,7 @@ public class RequestMapping {
|
||||
|
||||
public void setParams(String... params) {
|
||||
Assert.notEmpty(params, "at least one param is required");
|
||||
this.params = params;
|
||||
this.params = Arrays.copyOf(params, params.length);
|
||||
}
|
||||
|
||||
public String[] getParams() {
|
||||
@@ -84,7 +87,7 @@ public class RequestMapping {
|
||||
|
||||
public void setHeaders(String... headers) {
|
||||
Assert.notEmpty(headers, "at least one header is required");
|
||||
this.headers = headers;
|
||||
this.headers = Arrays.copyOf(headers, headers.length);
|
||||
}
|
||||
|
||||
public String[] getHeaders() {
|
||||
@@ -93,7 +96,7 @@ public class RequestMapping {
|
||||
|
||||
public void setConsumes(String... consumes) {
|
||||
Assert.notEmpty(consumes, "at least one consume value is required");
|
||||
this.consumes = consumes;
|
||||
this.consumes = Arrays.copyOf(consumes, consumes.length);
|
||||
}
|
||||
|
||||
public String[] getConsumes() {
|
||||
@@ -102,7 +105,7 @@ public class RequestMapping {
|
||||
|
||||
public void setProduces(String... produces) {
|
||||
Assert.notEmpty(produces, "at least one produce value is required");
|
||||
this.produces = produces;
|
||||
this.produces = Arrays.copyOf(produces, produces.length);
|
||||
}
|
||||
|
||||
public String[] getProduces() {
|
||||
|
||||
@@ -405,77 +405,79 @@ public class DefaultHttpHeaderMapper implements HeaderMapper<HttpHeaders>, BeanF
|
||||
|
||||
private static final String PRAGMA_LOWER = "pragma";
|
||||
|
||||
private static final String[] HTTP_REQUEST_HEADER_NAMES = new String[] {
|
||||
HttpHeaders.ACCEPT,
|
||||
HttpHeaders.ACCEPT_CHARSET,
|
||||
HttpHeaders.ACCEPT_ENCODING,
|
||||
HttpHeaders.ACCEPT_LANGUAGE,
|
||||
HttpHeaders.ACCEPT_RANGES,
|
||||
HttpHeaders.AUTHORIZATION,
|
||||
HttpHeaders.CACHE_CONTROL,
|
||||
HttpHeaders.CONNECTION,
|
||||
HttpHeaders.CONTENT_LENGTH,
|
||||
HttpHeaders.CONTENT_TYPE,
|
||||
HttpHeaders.COOKIE,
|
||||
HttpHeaders.DATE,
|
||||
HttpHeaders.EXPECT,
|
||||
HttpHeaders.FROM,
|
||||
HttpHeaders.HOST,
|
||||
HttpHeaders.IF_MATCH,
|
||||
HttpHeaders.IF_MODIFIED_SINCE,
|
||||
HttpHeaders.IF_NONE_MATCH,
|
||||
HttpHeaders.IF_RANGE,
|
||||
HttpHeaders.IF_UNMODIFIED_SINCE,
|
||||
HttpHeaders.MAX_FORWARDS,
|
||||
HttpHeaders.PRAGMA,
|
||||
HttpHeaders.PROXY_AUTHORIZATION,
|
||||
HttpHeaders.RANGE,
|
||||
HttpHeaders.REFERER,
|
||||
HttpHeaders.TE,
|
||||
HttpHeaders.UPGRADE,
|
||||
HttpHeaders.USER_AGENT,
|
||||
HttpHeaders.VIA,
|
||||
HttpHeaders.WARNING
|
||||
};
|
||||
private static final String[] HTTP_REQUEST_HEADER_NAMES =
|
||||
{
|
||||
HttpHeaders.ACCEPT,
|
||||
HttpHeaders.ACCEPT_CHARSET,
|
||||
HttpHeaders.ACCEPT_ENCODING,
|
||||
HttpHeaders.ACCEPT_LANGUAGE,
|
||||
HttpHeaders.ACCEPT_RANGES,
|
||||
HttpHeaders.AUTHORIZATION,
|
||||
HttpHeaders.CACHE_CONTROL,
|
||||
HttpHeaders.CONNECTION,
|
||||
HttpHeaders.CONTENT_LENGTH,
|
||||
HttpHeaders.CONTENT_TYPE,
|
||||
HttpHeaders.COOKIE,
|
||||
HttpHeaders.DATE,
|
||||
HttpHeaders.EXPECT,
|
||||
HttpHeaders.FROM,
|
||||
HttpHeaders.HOST,
|
||||
HttpHeaders.IF_MATCH,
|
||||
HttpHeaders.IF_MODIFIED_SINCE,
|
||||
HttpHeaders.IF_NONE_MATCH,
|
||||
HttpHeaders.IF_RANGE,
|
||||
HttpHeaders.IF_UNMODIFIED_SINCE,
|
||||
HttpHeaders.MAX_FORWARDS,
|
||||
HttpHeaders.PRAGMA,
|
||||
HttpHeaders.PROXY_AUTHORIZATION,
|
||||
HttpHeaders.RANGE,
|
||||
HttpHeaders.REFERER,
|
||||
HttpHeaders.TE,
|
||||
HttpHeaders.UPGRADE,
|
||||
HttpHeaders.USER_AGENT,
|
||||
HttpHeaders.VIA,
|
||||
HttpHeaders.WARNING
|
||||
};
|
||||
|
||||
private static final Set<String> HTTP_REQUEST_HEADER_NAMES_LOWER = new HashSet<>();
|
||||
|
||||
private static final String[] HTTP_RESPONSE_HEADER_NAMES = new String[] {
|
||||
HttpHeaders.ACCEPT_RANGES,
|
||||
HttpHeaders.AGE,
|
||||
HttpHeaders.ALLOW,
|
||||
HttpHeaders.CACHE_CONTROL,
|
||||
HttpHeaders.CONNECTION,
|
||||
HttpHeaders.CONTENT_ENCODING,
|
||||
HttpHeaders.CONTENT_LANGUAGE,
|
||||
HttpHeaders.CONTENT_LENGTH,
|
||||
HttpHeaders.CONTENT_LOCATION,
|
||||
CONTENT_MD5,
|
||||
HttpHeaders.CONTENT_RANGE,
|
||||
HttpHeaders.CONTENT_TYPE,
|
||||
HttpHeaders.CONTENT_DISPOSITION,
|
||||
HttpHeaders.TRANSFER_ENCODING,
|
||||
HttpHeaders.DATE,
|
||||
HttpHeaders.ETAG,
|
||||
HttpHeaders.EXPIRES,
|
||||
HttpHeaders.LAST_MODIFIED,
|
||||
HttpHeaders.LOCATION,
|
||||
HttpHeaders.PRAGMA,
|
||||
HttpHeaders.PROXY_AUTHENTICATE,
|
||||
REFRESH,
|
||||
HttpHeaders.RETRY_AFTER,
|
||||
HttpHeaders.SERVER,
|
||||
HttpHeaders.SET_COOKIE,
|
||||
HttpHeaders.TRAILER,
|
||||
HttpHeaders.VARY,
|
||||
HttpHeaders.VIA,
|
||||
HttpHeaders.WARNING,
|
||||
HttpHeaders.WWW_AUTHENTICATE
|
||||
};
|
||||
private static final String[] HTTP_RESPONSE_HEADER_NAMES =
|
||||
{
|
||||
HttpHeaders.ACCEPT_RANGES,
|
||||
HttpHeaders.AGE,
|
||||
HttpHeaders.ALLOW,
|
||||
HttpHeaders.CACHE_CONTROL,
|
||||
HttpHeaders.CONNECTION,
|
||||
HttpHeaders.CONTENT_ENCODING,
|
||||
HttpHeaders.CONTENT_LANGUAGE,
|
||||
HttpHeaders.CONTENT_LENGTH,
|
||||
HttpHeaders.CONTENT_LOCATION,
|
||||
CONTENT_MD5,
|
||||
HttpHeaders.CONTENT_RANGE,
|
||||
HttpHeaders.CONTENT_TYPE,
|
||||
HttpHeaders.CONTENT_DISPOSITION,
|
||||
HttpHeaders.TRANSFER_ENCODING,
|
||||
HttpHeaders.DATE,
|
||||
HttpHeaders.ETAG,
|
||||
HttpHeaders.EXPIRES,
|
||||
HttpHeaders.LAST_MODIFIED,
|
||||
HttpHeaders.LOCATION,
|
||||
HttpHeaders.PRAGMA,
|
||||
HttpHeaders.PROXY_AUTHENTICATE,
|
||||
REFRESH,
|
||||
HttpHeaders.RETRY_AFTER,
|
||||
HttpHeaders.SERVER,
|
||||
HttpHeaders.SET_COOKIE,
|
||||
HttpHeaders.TRAILER,
|
||||
HttpHeaders.VARY,
|
||||
HttpHeaders.VIA,
|
||||
HttpHeaders.WARNING,
|
||||
HttpHeaders.WWW_AUTHENTICATE
|
||||
};
|
||||
|
||||
private static final Set<String> HTTP_RESPONSE_HEADER_NAMES_LOWER = new HashSet<>();
|
||||
|
||||
private static final String[] HTTP_REQUEST_HEADER_NAMES_OUTBOUND_EXCLUSIONS = new String[0];
|
||||
private static final String[] HTTP_REQUEST_HEADER_NAMES_OUTBOUND_EXCLUSIONS = { };
|
||||
|
||||
private static final String[] HTTP_RESPONSE_HEADER_NAMES_INBOUND_EXCLUSIONS =
|
||||
{ HttpHeaders.CONTENT_LENGTH, HttpHeaders.TRANSFER_ENCODING };
|
||||
@@ -500,17 +502,17 @@ public class DefaultHttpHeaderMapper implements HeaderMapper<HttpHeaders>, BeanF
|
||||
}
|
||||
}
|
||||
|
||||
private volatile String[] outboundHeaderNames = new String[0];
|
||||
private volatile String[] outboundHeaderNames = {};
|
||||
|
||||
private volatile String[] outboundHeaderNamesLowerWithContentType = new String[0];
|
||||
private volatile String[] outboundHeaderNamesLowerWithContentType = {};
|
||||
|
||||
private volatile String[] inboundHeaderNames = new String[0];
|
||||
private volatile String[] inboundHeaderNames = {};
|
||||
|
||||
private volatile String[] inboundHeaderNamesLower = new String[0];
|
||||
private volatile String[] inboundHeaderNamesLower = {};
|
||||
|
||||
private volatile String[] excludedOutboundStandardRequestHeaderNames = new String[0];
|
||||
private volatile String[] excludedOutboundStandardRequestHeaderNames = {};
|
||||
|
||||
private volatile String[] excludedInboundStandardResponseHeaderNames = new String[0];
|
||||
private volatile String[] excludedInboundStandardResponseHeaderNames = {};
|
||||
|
||||
private volatile String userDefinedHeaderPrefix = "";
|
||||
|
||||
@@ -575,12 +577,12 @@ public class DefaultHttpHeaderMapper implements HeaderMapper<HttpHeaders>, BeanF
|
||||
* will match the header name prefixed with the value specified by
|
||||
* {@link DefaultHttpHeaderMapper#setUserDefinedHeaderPrefix(String)}. The default for
|
||||
* that is an empty String.
|
||||
* @param inboundHeaderNames The inbound header names.
|
||||
* @param inboundHeaderNamesArg The inbound header names.
|
||||
*/
|
||||
public void setInboundHeaderNames(String... inboundHeaderNames) {
|
||||
public void setInboundHeaderNames(String... inboundHeaderNamesArg) {
|
||||
this.inboundHeaderNames =
|
||||
inboundHeaderNames != null
|
||||
? Arrays.copyOf(inboundHeaderNames, inboundHeaderNames.length)
|
||||
inboundHeaderNamesArg != null
|
||||
? Arrays.copyOf(inboundHeaderNamesArg, inboundHeaderNamesArg.length)
|
||||
: new String[0];
|
||||
this.inboundHeaderNamesLower = new String[this.inboundHeaderNames.length];
|
||||
for (int i = 0; i < this.inboundHeaderNames.length; i++) {
|
||||
|
||||
@@ -33,16 +33,12 @@ import javax.management.NotificationListener;
|
||||
import javax.management.ObjectInstance;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.integration.endpoint.MessageProducerSupport;
|
||||
import org.springframework.integration.support.AbstractIntegrationMessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* A JMX {@link NotificationListener} implementation that will send Messages
|
||||
@@ -51,28 +47,26 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Mark Fisher
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class NotificationListeningMessageProducer extends MessageProducerSupport
|
||||
implements NotificationListener, ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private final AtomicBoolean listenerRegisteredOnStartup = new AtomicBoolean();
|
||||
|
||||
private volatile MBeanServerConnection server;
|
||||
private MBeanServerConnection server;
|
||||
|
||||
private volatile ObjectName[] mBeanObjectNames;
|
||||
private ObjectName[] mBeanObjectNames;
|
||||
|
||||
private volatile NotificationFilter filter;
|
||||
private NotificationFilter filter;
|
||||
|
||||
private volatile Object handback;
|
||||
private Object handback;
|
||||
|
||||
|
||||
/**
|
||||
* Provide a reference to the MBeanServer where the notification
|
||||
* publishing MBeans are registered.
|
||||
*
|
||||
* @param server the MBean server connection.
|
||||
*/
|
||||
public void setServer(MBeanServerConnection server) {
|
||||
@@ -83,18 +77,16 @@ public class NotificationListeningMessageProducer extends MessageProducerSupport
|
||||
* Specify the JMX ObjectNames (or patterns)
|
||||
* of the notification publisher
|
||||
* to which this notification listener should be subscribed.
|
||||
*
|
||||
* @param objectNames The object names.
|
||||
*/
|
||||
public void setObjectName(ObjectName... objectNames) {
|
||||
Assert.isTrue(!ObjectUtils.isEmpty(objectNames), "'objectNames' must contain at least one ObjectName");
|
||||
this.mBeanObjectNames = objectNames;
|
||||
Assert.notEmpty(objectNames, "'objectNames' must contain at least one ObjectName");
|
||||
this.mBeanObjectNames = Arrays.copyOf(objectNames, objectNames.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a {@link NotificationFilter} to be passed to the server
|
||||
* when registering this listener. The filter may be null.
|
||||
*
|
||||
* @param filter The filter.
|
||||
*/
|
||||
public void setFilter(NotificationFilter filter) {
|
||||
@@ -104,7 +96,6 @@ public class NotificationListeningMessageProducer extends MessageProducerSupport
|
||||
/**
|
||||
* Specify a handback object to provide context to the listener
|
||||
* upon notification. This object may be null.
|
||||
*
|
||||
* @param handback The object.
|
||||
*/
|
||||
public void setHandback(Object handback) {
|
||||
@@ -122,12 +113,12 @@ public class NotificationListeningMessageProducer extends MessageProducerSupport
|
||||
if (this.logger.isInfoEnabled()) {
|
||||
this.logger.info("received notification: " + notification + ", and handback: " + handback);
|
||||
}
|
||||
AbstractIntegrationMessageBuilder<?> builder = this.getMessageBuilderFactory().withPayload(notification);
|
||||
AbstractIntegrationMessageBuilder<?> builder = getMessageBuilderFactory().withPayload(notification);
|
||||
if (handback != null) {
|
||||
builder.setHeader(JmxHeaders.NOTIFICATION_HANDBACK, handback);
|
||||
}
|
||||
Message<?> message = builder.build();
|
||||
this.sendMessage(message);
|
||||
sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -156,13 +147,13 @@ public class NotificationListeningMessageProducer extends MessageProducerSupport
|
||||
return;
|
||||
}
|
||||
this.logger.debug("Registering to receive notifications");
|
||||
Assert.notNull(this.server, "MBeanServer is required.");
|
||||
Assert.notNull(this.mBeanObjectNames, "An ObjectName is required.");
|
||||
try {
|
||||
Assert.notNull(this.server, "MBeanServer is required.");
|
||||
Assert.notNull(this.mBeanObjectNames, "An ObjectName is required.");
|
||||
Collection<ObjectName> objectNames = this.retrieveMBeanNames();
|
||||
if (objectNames.size() < 1) {
|
||||
this.logger.error("No MBeans found matching ObjectName pattern(s): " +
|
||||
Arrays.asList(this.mBeanObjectNames));
|
||||
Arrays.toString(this.mBeanObjectNames));
|
||||
}
|
||||
for (ObjectName objectName : objectNames) {
|
||||
this.server.addNotificationListener(objectName, this, this.filter, this.handback);
|
||||
@@ -202,7 +193,7 @@ public class NotificationListeningMessageProducer extends MessageProducerSupport
|
||||
}
|
||||
|
||||
protected Collection<ObjectName> retrieveMBeanNames() {
|
||||
List<ObjectName> objectNames = new ArrayList<ObjectName>();
|
||||
List<ObjectName> objectNames = new ArrayList<>();
|
||||
for (ObjectName pattern : this.mBeanObjectNames) {
|
||||
Set<ObjectInstance> mBeanInfos;
|
||||
try {
|
||||
@@ -212,11 +203,11 @@ public class NotificationListeningMessageProducer extends MessageProducerSupport
|
||||
throw new IllegalStateException("IOException on MBeanServerConnection.", e);
|
||||
}
|
||||
if (mBeanInfos.size() == 0 && this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("No MBeans found matching pattern:" + pattern);
|
||||
this.logger.debug("No MBeans found matching pattern: " + pattern);
|
||||
}
|
||||
for (ObjectInstance instance : mBeanInfos) {
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("Found MBean:" + instance.getObjectName().toString());
|
||||
this.logger.debug("Found MBean: " + instance.getObjectName().toString());
|
||||
}
|
||||
objectNames.add(instance.getObjectName());
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.integration.redis.inbound;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -70,11 +71,13 @@ public class RedisInboundChannelAdapter extends MessageProducerSupport {
|
||||
}
|
||||
|
||||
public void setTopics(String... topics) {
|
||||
this.topics = topics;
|
||||
Assert.notEmpty(topics, "at least one topic is required");
|
||||
this.topics = Arrays.copyOf(topics, topics.length);
|
||||
}
|
||||
|
||||
public void setTopicPatterns(String... topicPatterns) {
|
||||
this.topicPatterns = topicPatterns;
|
||||
Assert.notEmpty(topicPatterns, "at least one topic pattern is required");
|
||||
this.topicPatterns = Arrays.copyOf(topicPatterns, topicPatterns.length);
|
||||
}
|
||||
|
||||
public void setMessageConverter(MessageConverter messageConverter) {
|
||||
@@ -114,12 +117,12 @@ public class RedisInboundChannelAdapter extends MessageProducerSupport {
|
||||
Assert.state(hasTopics || hasPatterns, "at least one topic or topic pattern is required for subscription.");
|
||||
|
||||
if (this.messageConverter instanceof BeanFactoryAware) {
|
||||
((BeanFactoryAware) this.messageConverter).setBeanFactory(this.getBeanFactory());
|
||||
((BeanFactoryAware) this.messageConverter).setBeanFactory(getBeanFactory());
|
||||
}
|
||||
MessageListenerDelegate delegate = new MessageListenerDelegate();
|
||||
MessageListenerAdapter adapter = new MessageListenerAdapter(delegate);
|
||||
adapter.setSerializer(this.serializer);
|
||||
List<Topic> topicList = new ArrayList<Topic>();
|
||||
List<Topic> topicList = new ArrayList<>();
|
||||
if (hasTopics) {
|
||||
for (String topic : this.topics) {
|
||||
topicList.add(new ChannelTopic(topic));
|
||||
|
||||
@@ -95,11 +95,11 @@ public class RSocketInboundGateway extends MessagingGatewaySupport implements In
|
||||
|
||||
/**
|
||||
* Instantiate based on the provided Ant-style path patterns to map this endpoint for incoming RSocket requests.
|
||||
* @param path the mapping patterns to use.
|
||||
* @param pathArg the mapping patterns to use.
|
||||
*/
|
||||
public RSocketInboundGateway(String... path) {
|
||||
Assert.notNull(path, "'path' must not be null");
|
||||
this.path = path;
|
||||
public RSocketInboundGateway(String... pathArg) {
|
||||
Assert.notNull(pathArg, "'pathArg' must not be null");
|
||||
this.path = Arrays.copyOf(pathArg, pathArg.length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.integration.stomp;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.messaging.simp.stomp.StompSession;
|
||||
import org.springframework.messaging.simp.stomp.StompSessionHandler;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -29,8 +31,9 @@ import org.springframework.web.socket.messaging.WebSocketStompClient;
|
||||
* @author Artem Bilan
|
||||
* @author Sean Mills
|
||||
*
|
||||
* @see WebSocketStompClient
|
||||
* @since 4.2
|
||||
*
|
||||
* @see WebSocketStompClient
|
||||
*/
|
||||
public class WebSocketStompSessionManager extends AbstractStompSessionManager {
|
||||
|
||||
@@ -44,7 +47,7 @@ public class WebSocketStompSessionManager extends AbstractStompSessionManager {
|
||||
super(webSocketStompClient);
|
||||
Assert.hasText(url, "'url' must not be empty.");
|
||||
this.url = url;
|
||||
this.uriVariables = uriVariables;
|
||||
this.uriVariables = uriVariables != null ? Arrays.copyOf(uriVariables, uriVariables.length) : null;
|
||||
}
|
||||
|
||||
public void setHandshakeHeaders(WebSocketHttpHeaders handshakeHeaders) {
|
||||
@@ -53,8 +56,8 @@ public class WebSocketStompSessionManager extends AbstractStompSessionManager {
|
||||
|
||||
@Override
|
||||
protected ListenableFuture<StompSession> doConnect(StompSessionHandler handler) {
|
||||
return ((WebSocketStompClient) this.stompClient).connect(this.url, this.handshakeHeaders, getConnectHeaders(),
|
||||
handler, this.uriVariables);
|
||||
return ((WebSocketStompClient) this.stompClient)
|
||||
.connect(this.url, this.handshakeHeaders, getConnectHeaders(), handler, this.uriVariables);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.integration.test.matcher;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -62,7 +63,7 @@ public final class PayloadAndHeaderMatcher<T> extends BaseMatcher<Message<?>> {
|
||||
}
|
||||
|
||||
private PayloadAndHeaderMatcher(Message<T> expected, String... ignoreKeys) {
|
||||
this.ignoreKeys = ignoreKeys;
|
||||
this.ignoreKeys = ignoreKeys != null ? Arrays.copyOf(ignoreKeys, ignoreKeys.length) : null;
|
||||
this.payload = expected.getPayload();
|
||||
this.headers = extractHeadersToAssert(expected);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,8 @@ public class ServerWebSocketContainer extends IntegrationWebSocketContainer
|
||||
private int phase = 0;
|
||||
|
||||
public ServerWebSocketContainer(String... paths) {
|
||||
this.paths = paths;
|
||||
Assert.notEmpty(paths, "'paths' must not be empty");
|
||||
this.paths = Arrays.copyOf(paths, paths.length);
|
||||
}
|
||||
|
||||
public ServerWebSocketContainer setHandshakeHandler(HandshakeHandler handshakeHandler) {
|
||||
@@ -110,7 +111,8 @@ public class ServerWebSocketContainer extends IntegrationWebSocketContainer
|
||||
* @see WebSocketHandlerRegistration#setAllowedOrigins(String...)
|
||||
*/
|
||||
public ServerWebSocketContainer setAllowedOrigins(String... origins) {
|
||||
this.origins = origins; //NOSONAR - fully delegated
|
||||
Assert.notEmpty(origins, "'origins' must not be empty");
|
||||
this.origins = Arrays.copyOf(origins, origins.length);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -291,7 +293,8 @@ public class ServerWebSocketContainer extends IntegrationWebSocketContainer
|
||||
}
|
||||
|
||||
public SockJsServiceOptions setTransportHandlers(TransportHandler... transportHandlers) {
|
||||
this.transportHandlers = transportHandlers;
|
||||
Assert.notEmpty(transportHandlers, "'transportHandlers' must not be empty");
|
||||
this.transportHandlers = Arrays.copyOf(transportHandlers, transportHandlers.length);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user