Use lookupHost = false by default for TCP & UDP (#3825)
* Use `lookupHost = false` by default for TCP & UDP The applications these days more and more are deployed and managed in the containers where DNS is not configured by default. Having `lookupHost = true` by default leads to a bad experience when some delays happen for reverse host lookups. * Use `lookupHost = false` by default for both TCP & UDP to have a reliable behavior independently of the environment. The `hostName` is used for `connectionId` and as a header in the message - semantically it doesn't matter for the application logic what value is present over there. * * Fix language in docs Co-authored-by: Gary Russell <grussell@vmware.com> Co-authored-by: Gary Russell <grussell@vmware.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -21,7 +21,6 @@ import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.SocketException;
|
||||
import java.time.Duration;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
@@ -249,10 +248,12 @@ public class ParserUnitTests {
|
||||
@Autowired
|
||||
MessageChannel udpAutoChannel;
|
||||
|
||||
@Autowired @Qualifier("tcpAutoChannel.adapter")
|
||||
@Autowired
|
||||
@Qualifier("tcpAutoChannel.adapter")
|
||||
TcpReceivingChannelAdapter tcpAutoAdapter;
|
||||
|
||||
@Autowired @Qualifier("udpAutoChannel.adapter")
|
||||
@Autowired
|
||||
@Qualifier("udpAutoChannel.adapter")
|
||||
UnicastReceivingChannelAdapter udpAutoAdapter;
|
||||
|
||||
@Autowired
|
||||
@@ -316,7 +317,7 @@ public class ParserUnitTests {
|
||||
assertThat(dfa.getPropertyValue("errorChannel")).isNull();
|
||||
DatagramPacketMessageMapper mapper = (DatagramPacketMessageMapper) dfa.getPropertyValue("mapper");
|
||||
DirectFieldAccessor mapperAccessor = new DirectFieldAccessor(mapper);
|
||||
assertThat((Boolean) mapperAccessor.getPropertyValue("lookupHost")).isTrue();
|
||||
assertThat((Boolean) mapperAccessor.getPropertyValue("lookupHost")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -611,10 +612,10 @@ public class ParserUnitTests {
|
||||
TestUtils.getPropertyValue(this.tcpChannel, "dispatcher"),
|
||||
"handlers");
|
||||
Iterator<MessageHandler> iterator = handlers.iterator();
|
||||
assertThat(iterator.next()).isSameAs(this.tcpNewOut2); //15
|
||||
assertThat(iterator.next()).isSameAs(this.tcpOutboundGateway); //24
|
||||
assertThat(iterator.next()).isSameAs(this.tcpNewOut1); //25
|
||||
assertThat(iterator.next()).isSameAs(this.tcpOut); //35
|
||||
assertThat(iterator.next()).isSameAs(this.tcpNewOut2); //15
|
||||
assertThat(iterator.next()).isSameAs(this.tcpOutboundGateway); //24
|
||||
assertThat(iterator.next()).isSameAs(this.tcpNewOut1); //25
|
||||
assertThat(iterator.next()).isSameAs(this.tcpOut); //35
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -682,6 +683,7 @@ public class ParserUnitTests {
|
||||
public EventSubclass1(TcpConnectionSupport connection, String connectionFactoryName) {
|
||||
super(connection, connectionFactoryName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@@ -690,6 +692,7 @@ public class ParserUnitTests {
|
||||
public EventSubclass2(TcpConnectionSupport connection, String connectionFactoryName) {
|
||||
super(connection, connectionFactoryName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -708,7 +711,7 @@ public class ParserUnitTests {
|
||||
public static class SocketCust implements SocketCustomizer {
|
||||
|
||||
@Override
|
||||
public void configure(DatagramSocket socket) throws SocketException {
|
||||
public void configure(DatagramSocket socket) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -133,8 +133,9 @@ public class TcpNioConnectionTests {
|
||||
}
|
||||
});
|
||||
assertThat(latch.await(10000, TimeUnit.MILLISECONDS)).isTrue();
|
||||
TcpNioClientConnectionFactory factory = new TcpNioClientConnectionFactory("localhost",
|
||||
serverSocket.get().getLocalPort());
|
||||
TcpNioClientConnectionFactory factory =
|
||||
new TcpNioClientConnectionFactory("localhost", serverSocket.get().getLocalPort());
|
||||
factory.setLookupHost(true);
|
||||
AtomicReference<String> connectionId = new AtomicReference<>();
|
||||
factory.setApplicationEventPublisher(event -> {
|
||||
if (event instanceof TcpConnectionOpenEvent) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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,7 +23,7 @@ import java.net.DatagramPacket;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.integration.ip.IpHeaders;
|
||||
import org.springframework.integration.mapping.MessageMappingException;
|
||||
@@ -33,31 +33,33 @@ import org.springframework.messaging.Message;
|
||||
/**
|
||||
* @author Gary Russell
|
||||
* @author Dave Syer
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class DatagramPacketMessageMapperTests {
|
||||
|
||||
@Test
|
||||
public void testFromToMessageNoAckNoLengthCheck() throws Exception {
|
||||
public void testFromToMessageNoAckNoLengthCheck() {
|
||||
test(false, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromToMessageAckNoLengthCheck() throws Exception {
|
||||
public void testFromToMessageAckNoLengthCheck() {
|
||||
test(true, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromToMessageNoAckLengthCheck() throws Exception {
|
||||
public void testFromToMessageNoAckLengthCheck() {
|
||||
test(false, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromToMessageAckLengthCheck() throws Exception {
|
||||
public void testFromToMessageAckLengthCheck() {
|
||||
test(true, true);
|
||||
}
|
||||
|
||||
private void test(boolean ack, boolean lengthCheck) throws Exception {
|
||||
private void test(boolean ack, boolean lengthCheck) {
|
||||
Message<byte[]> message = MessageBuilder.withPayload("ABCD".getBytes()).build();
|
||||
DatagramPacketMessageMapper mapper = new DatagramPacketMessageMapper();
|
||||
mapper.setAckAddress("localhost:11111");
|
||||
@@ -71,19 +73,19 @@ public class DatagramPacketMessageMapperTests {
|
||||
assertThat(message.getHeaders().getId().toString())
|
||||
.isEqualTo(messageOut.getHeaders().get(IpHeaders.ACK_ID).toString());
|
||||
}
|
||||
assertThat(((String) messageOut.getHeaders().get(IpHeaders.HOSTNAME)).contains("localhost")).isTrue();
|
||||
mapper.setLookupHost(false);
|
||||
assertThat(((String) messageOut.getHeaders().get(IpHeaders.HOSTNAME))).doesNotContain("localhost");
|
||||
mapper.setLookupHost(true);
|
||||
messageOut = mapper.toMessage(packet);
|
||||
assertThat(new String(messageOut.getPayload())).isEqualTo(new String(message.getPayload()));
|
||||
if (ack) {
|
||||
assertThat(message.getHeaders().getId().toString())
|
||||
.isEqualTo(messageOut.getHeaders().get(IpHeaders.ACK_ID).toString());
|
||||
}
|
||||
assertThat(((String) messageOut.getHeaders().get(IpHeaders.HOSTNAME)).contains("localhost")).isFalse();
|
||||
assertThat(((String) messageOut.getHeaders().get(IpHeaders.HOSTNAME))).contains("localhost");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTruncation() throws Exception {
|
||||
public void testTruncation() {
|
||||
String test = "ABCD";
|
||||
Message<byte[]> message = MessageBuilder.withPayload(test.getBytes()).build();
|
||||
DatagramPacketMessageMapper mapper = new DatagramPacketMessageMapper();
|
||||
@@ -101,8 +103,7 @@ public class DatagramPacketMessageMapperTests {
|
||||
fail("Truncated message exception expected");
|
||||
}
|
||||
catch (MessageMappingException e) {
|
||||
assertThat(e.getMessage().contains("expected " + (bigLen + 4) + ", received " + (test.length() + 4)))
|
||||
.isTrue();
|
||||
assertThat(e.getMessage()).contains("expected " + (bigLen + 4) + ", received " + (test.length() + 4));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user