Fix deprecations from SF

* Remove `whitelist` words
* Resolve Sonar smells
* Add `await()` for FTP file removal test: looks like this operation may fail under the stress build
This commit is contained in:
Artem Bilan
2020-06-19 12:07:58 -04:00
parent 3a9ae217b8
commit 498f42d480
15 changed files with 58 additions and 232 deletions

View File

@@ -477,6 +477,7 @@ project('spring-integration-ftp') {
optionalApi "org.apache.ftpserver:ftpserver-core:$ftpServerVersion"
testImplementation project(':spring-integration-file').sourceSets.test.output
testImplementation "org.hamcrest:hamcrest-core:$hamcrestVersion"
}
}

View File

@@ -39,12 +39,6 @@ public class PayloadDeserializingTransformerParser extends AbstractTransformerPa
@Override
protected void parseTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "deserializer");
// TODO remove in 5.5
if (element.hasAttribute("white-list")) {
parserContext.getReaderContext().error(
"the 'white-list' attribute is deprecated in favor of 'allow-list'", element);
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "white-list", "allowedPatterns");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "allow-list", "allowedPatterns");
}

View File

@@ -1,94 +0,0 @@
/*
* Copyright 2002-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.support.converter;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.serializer.DefaultDeserializer;
import org.springframework.core.serializer.Deserializer;
/**
* A {@link Converter} that delegates to a
* {@link org.springframework.core.serializer.Deserializer} to convert data in a byte
* array to an object. By default, if using a {@link DefaultDeserializer} all
* classes/packages are deserialized. If you receive data from untrusted sources, consider
* adding trusted classes/packages using {@link #setWhiteListPatterns(String...)} or
* {@link #addWhiteListPatterns(String...)}.
*
* @author Gary Russell
* @author Mark Fisher
* @author Juergen Hoeller
*
* @since 4.2.13
*
* @deprecated since 5.4 in favor of AllowListDeserializingConverter
*/
@Deprecated
public class WhiteListDeserializingConverter extends AllowListDeserializingConverter {
/**
* Create a {@code WhiteListDeserializingConverter} with default
* {@link java.io.ObjectInputStream} configuration, using the "latest user-defined
* ClassLoader".
*/
public WhiteListDeserializingConverter() {
super();
}
/**
* Create a {@code WhiteListDeserializingConverter} for using an
* {@link java.io.ObjectInputStream} with the given {@code ClassLoader}.
* @param classLoader the class loader to use for deserialization.
*/
public WhiteListDeserializingConverter(ClassLoader classLoader) {
super(classLoader);
}
/**
* Create a {@code WhiteListDeserializingConverter} that delegates to the provided
* {@link Deserializer}.
* @param deserializer the deserializer to use.
*/
public WhiteListDeserializingConverter(Deserializer<Object> deserializer) {
super(deserializer);
}
/**
* Set simple patterns for allowable packages/classes for deserialization.
* The patterns will be applied in order until a match is found.
* A class can be fully qualified or a wildcard '*' is allowed at the
* beginning or end of the class name.
* Examples: {@code com.foo.*}, {@code *.MyClass}.
* @param whiteListPatterns the patterns.
*/
public void setWhiteListPatterns(String... whiteListPatterns) {
setAllowedPatterns(whiteListPatterns);
}
/**
* Add package/class patterns to the white list.
* @param patterns the patterns to add.
* @see #setWhiteListPatterns(String...)
*/
public void addWhiteListPatterns(String... patterns) {
addAllowedPatterns(patterns);
}
protected void checkWhiteList(Class<?> clazz) {
checkAllowList(clazz);
}
}

View File

@@ -140,7 +140,7 @@ public final class JacksonJsonUtils {
/**
* A {@link TypeIdResolver} that delegates to an existing implementation
* and throws an IllegalStateException if the class being looked up is not whitelisted,
* and throws an IllegalStateException if the class being looked up is not trusted,
* does not provide an explicit mixin mappings.
*
* @author Rob Winch
@@ -167,13 +167,13 @@ public final class JacksonJsonUtils {
AllowlistTypeIdResolver(TypeIdResolver delegate, String... trustedPackages) {
this.delegate = delegate;
if (trustedPackages != null) {
for (String whiteListPackage : trustedPackages) {
if ("*".equals(whiteListPackage)) {
for (String trustedPackage : trustedPackages) {
if ("*".equals(trustedPackage)) {
this.trustedPackages.clear();
break;
}
else {
this.trustedPackages.add(whiteListPackage);
this.trustedPackages.add(trustedPackage);
}
}
}

View File

@@ -49,21 +49,6 @@ public class PayloadDeserializingTransformer extends PayloadTypeConvertingTransf
setConverter(new AllowListDeserializingConverter(deserializer));
}
/**
* When using a {@link AllowListDeserializingConverter} (the default) add patterns
* for packages/classes that are allowed to be deserialized.
* A class can be fully qualified or a wildcard '*' is allowed at the
* beginning or end of the class name.
* Examples: {@code com.foo.*}, {@code *.MyClass}.
* @param patterns the patterns.
* @since 4.2.13
* @deprecated since 5.4 in favor of {@link #setAllowedPatterns(String...)}
*/
@Deprecated
public void setWhiteListPatterns(String... patterns) {
setAllowedPatterns(patterns);
}
/**
* When using a {@link AllowListDeserializingConverter} (the default) add patterns
* for packages/classes that are allowed to be deserialized.

View File

@@ -2787,16 +2787,6 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="white-list">
<xsd:annotation>
<xsd:documentation>
[DEPRECATED]
When using the default Deserializer, a list of package/class patterns indicating
classes that are allowed to be deserialized. Consider providing this if you receive
data from untrusted sources. Example: "com.mycom.*, com.yourcom.*".
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="allow-list">
<xsd:annotation>
<xsd:documentation>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-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.
@@ -24,7 +24,7 @@ import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.logging.Log;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.DirectFieldAccessor;
@@ -50,7 +50,6 @@ import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.transaction.support.TransactionSynchronizationUtils;
import org.springframework.transaction.support.TransactionTemplate;
@@ -87,7 +86,7 @@ public class PseudoTransactionalMessageSourceTests {
@Override
public Message<String> receive() {
GenericMessage<String> message = new GenericMessage<String>("foo");
GenericMessage<String> message = new GenericMessage<>("foo");
IntegrationResourceHolder holder =
(IntegrationResourceHolder) TransactionSynchronizationManager.getResource(this);
holder.addAttribute("baz", "qux");
@@ -141,7 +140,7 @@ public class PseudoTransactionalMessageSourceTests {
@Override
public Message<String> receive() {
GenericMessage<String> message = new GenericMessage<String>("foo");
GenericMessage<String> message = new GenericMessage<>("foo");
IntegrationResourceHolder holder =
(IntegrationResourceHolder) TransactionSynchronizationManager.getResource(this);
holder.addAttribute("baz", "qux");
@@ -192,7 +191,7 @@ public class PseudoTransactionalMessageSourceTests {
@Override
public Message<String> receive() {
GenericMessage<String> message = new GenericMessage<String>("foo");
GenericMessage<String> message = new GenericMessage<>("foo");
((IntegrationResourceHolder) TransactionSynchronizationManager.getResource(this))
.addAttribute("baz", testMessage);
return message;
@@ -235,7 +234,7 @@ public class PseudoTransactionalMessageSourceTests {
@Override
public Message<String> receive() {
GenericMessage<String> message = new GenericMessage<String>("foo");
GenericMessage<String> message = new GenericMessage<>("foo");
IntegrationResourceHolder holder =
(IntegrationResourceHolder) TransactionSynchronizationManager.getResource(this);
holder.addAttribute("baz", "qux");
@@ -280,7 +279,7 @@ public class PseudoTransactionalMessageSourceTests {
@Override
public Message<String> receive() {
GenericMessage<String> message = new GenericMessage<String>("foo");
GenericMessage<String> message = new GenericMessage<>("foo");
((IntegrationResourceHolder) TransactionSynchronizationManager.getResource(this))
.addAttribute("baz", "qux");
return message;
@@ -323,7 +322,7 @@ public class PseudoTransactionalMessageSourceTests {
@Override
public Message<String> receive() {
GenericMessage<String> message = new GenericMessage<String>("foo");
GenericMessage<String> message = new GenericMessage<>("foo");
((IntegrationResourceHolder) TransactionSynchronizationManager.getResource(this))
.addAttribute("baz", "qux");
return message;
@@ -361,17 +360,13 @@ public class PseudoTransactionalMessageSourceTests {
final AtomicInteger txSyncCounter = new AtomicInteger();
TransactionSynchronizationFactory syncFactory = new TransactionSynchronizationFactory() {
TransactionSynchronizationFactory syncFactory = key -> new TransactionSynchronization() {
@Override
public TransactionSynchronization create(Object key) {
return new TransactionSynchronizationAdapter() {
@Override
public void afterCompletion(int status) {
txSyncCounter.incrementAndGet();
}
};
public void afterCompletion(int status) {
txSyncCounter.incrementAndGet();
}
};
adapter.setTransactionSynchronizationFactory(syncFactory);
@@ -412,6 +407,7 @@ public class PseudoTransactionalMessageSourceTests {
}
}
@Configuration
@EnableIntegration
public static class TestTxSyncConfiguration {

View File

@@ -18,12 +18,14 @@ package org.springframework.integration.ftp.session;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.awaitility.Awaitility.await;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.time.Duration;
import java.util.UUID;
import org.apache.commons.net.ftp.FTPClient;
@@ -92,8 +94,7 @@ public class FtpRemoteFileTemplateTests extends FtpTestSupport {
template.execute((SessionCallbackWithoutResult<FTPFile>) session -> {
assertThat(session.remove("foo/foobar.txt")).isTrue();
assertThat(session.rmdir("foo/bar/")).isTrue();
FTPFile[] files = session.list("foo/");
assertThat(files.length).isEqualTo(0);
await().atMost(Duration.ofSeconds(10)).until(() -> session.list("foo/"), files -> files.length == 0);
assertThat(session.rmdir("foo/")).isTrue();
});
assertThat(template.exists("foo")).isFalse();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-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.
@@ -63,6 +63,7 @@ import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.MessagingException;
import org.springframework.messaging.converter.MessageConversionException;
import org.springframework.messaging.support.ErrorMessage;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
@@ -270,6 +271,7 @@ public abstract class HttpRequestHandlingEndpointSupport extends BaseHttpInbound
Map<String, Object> headers = getHeaderMapper().toHeaders(httpEntity.getHeaders());
Object payload = null;
Message<?> message = null;
boolean expectReply = isExpectReply();
try {
if (getPayloadExpression() != null) {
// create payload based on SpEL
@@ -300,9 +302,14 @@ public abstract class HttpRequestHandlingEndpointSupport extends BaseHttpInbound
new MessageConversionException("Cannot create request message", ex);
MessageChannel errorChannel = getErrorChannel();
if (errorChannel != null) {
this.messagingTemplate.send(errorChannel,
buildErrorMessage(null,
conversionException));
ErrorMessage errorMessage = buildErrorMessage(null, conversionException);
if (expectReply) {
return this.messagingTemplate.sendAndReceive(errorChannel, errorMessage);
}
else {
this.messagingTemplate.send(errorChannel, errorMessage);
return null;
}
}
else {
throw conversionException;
@@ -310,7 +317,8 @@ public abstract class HttpRequestHandlingEndpointSupport extends BaseHttpInbound
}
Message<?> reply = null;
if (isExpectReply()) {
if (expectReply) {
try {
reply = sendAndReceiveMessage(message);
}
@@ -501,7 +509,7 @@ public abstract class HttpRequestHandlingEndpointSupport extends BaseHttpInbound
return new RequestEntity<>(requestBody, request.getHeaders(), request.getMethod(), request.getURI());
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
protected Object extractRequestBody(ServletServerHttpRequest request) throws IOException {
MediaType contentType = request.getHeaders().getContentType();
if (contentType == null) {

View File

@@ -193,19 +193,6 @@ public class JdbcChannelMessageStore implements PriorityCapableChannelMessageSto
this.deserializer = new AllowListDeserializingConverter((Deserializer) deserializer);
}
/**
* Add patterns for packages/classes that are allowed to be deserialized. A class can
* be fully qualified or a wildcard '*' is allowed at the beginning or end of the
* class name. Examples: {@code com.foo.*}, {@code *.MyClass}.
* @param patterns the patterns.
* @since 4.2.13
* @deprecated since 5.4 in favor of {@link #addAllowedPatterns(String...)}
*/
@Deprecated
public void addWhiteListPatterns(String... patterns) {
addAllowedPatterns(patterns);
}
/**
* Add patterns for packages/classes that are allowed to be deserialized. A class can
* be fully qualified or a wildcard '*' is allowed at the beginning or end of the

View File

@@ -250,19 +250,6 @@ public class JdbcMessageStore extends AbstractMessageGroupStore implements Messa
this.deserializer = new AllowListDeserializingConverter((Deserializer) deserializer);
}
/**
* Add patterns for packages/classes that are allowed to be deserialized. A class can
* be fully qualified or a wildcard '*' is allowed at the beginning or end of the
* class name. Examples: {@code com.foo.*}, {@code *.MyClass}.
* @param patterns the patterns.
* @since 4.2.13
* @deprecated since 5.4 in favor of {@link #addAllowedPatterns(String...)}
*/
@Deprecated
public void addWhiteListPatterns(String... patterns) {
addAllowedPatterns(patterns);
}
/**
* Add patterns for packages/classes that are allowed to be deserialized. A class can
* be fully qualified or a wildcard '*' is allowed at the beginning or end of the

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.
@@ -23,9 +23,8 @@ import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.IntegrationMessageHeaderAccessor;
@@ -37,10 +36,8 @@ import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
import org.springframework.transaction.support.TransactionSynchronizationManager;
/**
@@ -48,8 +45,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
*
* @since 4.1
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class AggregatorIntegrationTests {
@@ -62,14 +58,14 @@ public class AggregatorIntegrationTests {
@Autowired
private AggregatingMessageHandler aggregatingMessageHandler;
@After
@AfterEach
public void tearDown() {
this.aggregatingMessageHandler.stop();
}
@Test
public void testTransactionalAggregatorGroupTimeout() throws InterruptedException {
this.transactionalAggregatorInput.send(new GenericMessage<Integer>(1, stubHeaders(1, 2, 1)));
this.transactionalAggregatorInput.send(new GenericMessage<>(1, stubHeaders(1, 2, 1)));
assertThat(RollbackTxSync.latch.await(20, TimeUnit.SECONDS)).isTrue();
@@ -78,7 +74,7 @@ public class AggregatorIntegrationTests {
}
private Map<String, Object> stubHeaders(int sequenceNumber, int sequenceSize, int correlationId) {
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, sequenceNumber);
headers.put(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE, sequenceSize);
headers.put(IntegrationMessageHeaderAccessor.CORRELATION_ID, correlationId);
@@ -96,7 +92,7 @@ public class AggregatorIntegrationTests {
}
private static class RollbackTxSync extends TransactionSynchronizationAdapter {
private static class RollbackTxSync implements TransactionSynchronization {
public static CountDownLatch latch = new CountDownLatch(1);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-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.
@@ -22,10 +22,9 @@ import static org.assertj.core.api.Assertions.fail;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -35,7 +34,7 @@ import org.springframework.integration.store.MessageGroup;
import org.springframework.integration.store.MessageGroupStore;
import org.springframework.integration.store.SimpleMessageGroup;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.support.LongRunningIntegrationTest;
import org.springframework.integration.test.condition.LongRunningTest;
import org.springframework.integration.util.UUIDConverter;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
@@ -47,23 +46,20 @@ import org.springframework.messaging.MessagingException;
import org.springframework.messaging.PollableChannel;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
import org.springframework.transaction.support.TransactionSynchronizationManager;
/**
* @author Artem Bilan
* @author Gary Russell
*/
@LongRunningTest
public class DelayerHandlerRescheduleIntegrationTests {
public static final String DELAYER_ID = "delayerWithJdbcMS";
public static EmbeddedDatabase dataSource;
@Rule
public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest();
@BeforeClass
@BeforeAll
public static void init() {
dataSource = new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
@@ -72,12 +68,12 @@ public class DelayerHandlerRescheduleIntegrationTests {
.build();
}
@AfterClass
@AfterAll
public static void destroy() {
dataSource.shutdown();
}
@Test //INT-1132
@Test
public void testDelayerHandlerRescheduleWithJdbcMessageStore() throws Exception {
AbstractApplicationContext context =
new ClassPathXmlApplicationContext("DelayerHandlerRescheduleIntegrationTests-context.xml", getClass());
@@ -142,7 +138,7 @@ public class DelayerHandlerRescheduleIntegrationTests {
context.close();
}
@Test //INT-2649
@Test
public void testRollbackOnDelayerHandlerReleaseTask() throws Exception {
AbstractApplicationContext context =
new ClassPathXmlApplicationContext("DelayerHandlerRescheduleIntegrationTests-context.xml", getClass());
@@ -172,6 +168,9 @@ public class DelayerHandlerRescheduleIntegrationTests {
@SuppressWarnings("unused")
private static class ExceptionMessageHandler implements MessageHandler {
ExceptionMessageHandler() {
}
@Override
public void handleMessage(Message<?> message) throws MessagingException {
TransactionSynchronizationManager.registerSynchronization(new RollbackTxSync());
@@ -180,7 +179,7 @@ public class DelayerHandlerRescheduleIntegrationTests {
}
private static class RollbackTxSync extends TransactionSynchronizationAdapter {
private static class RollbackTxSync implements TransactionSynchronization {
public static CountDownLatch latch = new CountDownLatch(2);

View File

@@ -172,18 +172,6 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore
this.applicationContext = applicationContext;
}
/**
* Add patterns for packages/classes that are allowed to be deserialized. A class can
* be fully qualified or a wildcard '*' is allowed at the beginning or end of the
* class name. Examples: {@code com.foo.*}, {@code *.MyClass}.
* @param patterns the patterns.
* @deprecated since 5.4 in favor of {@link #addAllowedPatterns(String...)}
*/
@Deprecated
public void addWhiteListPatterns(String... patterns) {
addAllowedPatterns(patterns);
}
/**
* Add patterns for packages/classes that are allowed to be deserialized. A class can
* be fully qualified or a wildcard '*' is allowed at the beginning or end of the

View File

@@ -38,18 +38,6 @@ public class BinaryToMessageConverter implements Converter<Binary, Message<?>> {
return (Message<?>) this.deserializingConverter.convert(source.getData());
}
/**
* Add patterns for packages/classes that are allowed to be deserialized. A class can
* be fully qualified or a wildcard '*' is allowed at the beginning or end of the
* class name. Examples: {@code com.foo.*}, {@code *.MyClass}.
* @param patterns the patterns.
* @deprecated since 5.4 in favor of {@link #addAllowedPatterns(String...)}
*/
@Deprecated
public void addWhiteListPatterns(String... patterns) {
this.deserializingConverter.addAllowedPatterns(patterns);
}
/**
* Add patterns for packages/classes that are allowed to be deserialized. A class can
* be fully qualified or a wildcard '*' is allowed at the beginning or end of the