Skip to content

Commit

Permalink
Fix deprecations from SF
Browse files Browse the repository at this point in the history
* Remove `whitelist` words
* Resolve Sonar smells
* Add `await()` for FTP file removal test: looks like this operation may fail under the stress build
  • Loading branch information
artembilan committed Jun 19, 2020
1 parent 3a9ae21 commit 498f42d
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 232 deletions.
1 change: 1 addition & 0 deletions build.gradle
Expand Up @@ -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"
}
}

Expand Down
Expand Up @@ -39,12 +39,6 @@ protected String getTransformerClassName() {
@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");
}

Expand Down

This file was deleted.

Expand Up @@ -140,7 +140,7 @@ protected TypeIdResolver idResolver(MapperConfig<?> config,

/**
* 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
Expand All @@ -167,13 +167,13 @@ private static final class AllowlistTypeIdResolver implements TypeIdResolver {
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);
}
}
}
Expand Down
Expand Up @@ -49,21 +49,6 @@ public void setDeserializer(Deserializer<Object> deserializer) {
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.
Expand Down
Expand Up @@ -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>
Expand Down
@@ -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.
Expand All @@ -24,7 +24,7 @@
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;
Expand All @@ -50,7 +50,6 @@
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;
Expand Down Expand Up @@ -87,7 +86,7 @@ public void testCommit() {

@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");
Expand Down Expand Up @@ -141,7 +140,7 @@ public void testTransactionSynchronizationFactoryBean() {

@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");
Expand Down Expand Up @@ -192,7 +191,7 @@ public void testRollback() {

@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;
Expand Down Expand Up @@ -235,7 +234,7 @@ public void testCommitWithManager() {

@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");
Expand Down Expand Up @@ -280,7 +279,7 @@ public void testRollbackWithManager() {

@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;
Expand Down Expand Up @@ -323,7 +322,7 @@ public void testRollbackWithManagerUsingStatus() {

@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;
Expand Down Expand Up @@ -361,17 +360,13 @@ public void testInt2777CustomTransactionSynchronizationFactoryWithoutDealWithInt

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);
Expand Down Expand Up @@ -412,6 +407,7 @@ public String getValue() {
}

}

@Configuration
@EnableIntegration
public static class TestTxSyncConfiguration {
Expand Down
Expand Up @@ -18,12 +18,14 @@

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;
Expand Down Expand Up @@ -92,8 +94,7 @@ public void testINT3412AppendStatRmdir() {
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();
Expand Down
@@ -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.
Expand Down Expand Up @@ -63,6 +63,7 @@
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;
Expand Down Expand Up @@ -270,6 +271,7 @@ private Message<?> actualDoHandleRequest(HttpServletRequest servletRequest, Requ
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
Expand Down Expand Up @@ -300,17 +302,23 @@ private Message<?> actualDoHandleRequest(HttpServletRequest servletRequest, Requ
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;
}
}

Message<?> reply = null;
if (isExpectReply()) {

if (expectReply) {
try {
reply = sendAndReceiveMessage(message);
}
Expand Down Expand Up @@ -501,7 +509,7 @@ protected RequestEntity<Object> prepareRequestEntity(ServletServerHttpRequest re
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) {
Expand Down
Expand Up @@ -193,19 +193,6 @@ public void setDeserializer(Deserializer<? extends Message<?>> deserializer) {
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
Expand Down

0 comments on commit 498f42d

Please sign in to comment.