1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-22 12:37:58 +01:00

Deprecate setHostAddressByNameOrIp() and move logic into setHost()

in ConnectionConfiguration.Builder.
This commit is contained in:
Florian Schmaus 2019-08-22 10:30:46 +02:00
parent 44649ef3f5
commit 01e0ae230b
2 changed files with 27 additions and 25 deletions

View file

@ -646,7 +646,7 @@ public abstract class ConnectionConfiguration {
/**
* Set the Internet address of the host providing the XMPP service. If set, then this will overwrite anything
* set via {@link #setHost(String)}.
* set via {@link #setHost(CharSequence)}.
*
* @param address the Internet address of the host providing the XMPP service.
* @return a reference to this builder.
@ -658,16 +658,29 @@ public abstract class ConnectionConfiguration {
}
/**
* Set the name of the host providing the XMPP service. Note that this method does only allow DNS names and not
* IP addresses. Use {@link #setHostAddress(InetAddress)} if you want to explicitly set the Internet address of
* the host providing the XMPP service.
* Set the name of the host providing the XMPP service. This method takes DNS names and
* IP addresses.
*
* @param host the DNS name of the host providing the XMPP service.
* @return a reference to this builder.
*/
public B setHost(String host) {
DnsName hostDnsName = DnsName.from(host);
return setHost(hostDnsName);
public B setHost(CharSequence host) {
String fqdnOrIpString = host.toString();
if (InetAddressUtil.isIpAddress(fqdnOrIpString)) {
InetAddress hostInetAddress;
try {
hostInetAddress = InetAddress.getByName(fqdnOrIpString);
}
catch (UnknownHostException e) {
// Should never happen.
throw new AssertionError(e);
}
setHostAddress(hostInetAddress);
} else {
DnsName dnsName = DnsName.from(fqdnOrIpString);
setHost(dnsName);
}
return getThis();
}
/**
@ -691,23 +704,12 @@ public abstract class ConnectionConfiguration {
* @see #setHost(DnsName)
* @see #setHostAddress(InetAddress)
* @since 4.3.2
* @deprecated use {@link #setHost(CharSequence)} instead.
*/
@Deprecated
// TODO: Remove in Smack 4.5.
public B setHostAddressByNameOrIp(CharSequence fqdnOrIp) {
String fqdnOrIpString = fqdnOrIp.toString();
if (InetAddressUtil.isIpAddress(fqdnOrIp)) {
InetAddress hostInetAddress;
try {
hostInetAddress = InetAddress.getByName(fqdnOrIpString);
}
catch (UnknownHostException e) {
// Should never happen.
throw new AssertionError(e);
}
setHostAddress(hostInetAddress);
} else {
setHost(fqdnOrIpString);
}
return getThis();
return setHost(fqdnOrIp);
}
public B setPort(int port) {

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2018 Florian Schmaus.
* Copyright 2018-2019 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -28,7 +28,7 @@ public class ConnectionConfigurationTest {
DummyConnectionConfiguration.Builder builder = newUnitTestBuilder();
final String ip = "192.168.0.1";
builder.setHostAddressByNameOrIp(ip);
builder.setHost(ip);
DummyConnectionConfiguration connectionConfiguration = builder.build();
assertEquals('/' + ip, connectionConfiguration.getHostAddress().toString());
@ -39,7 +39,7 @@ public class ConnectionConfigurationTest {
DummyConnectionConfiguration.Builder builder = newUnitTestBuilder();
final String fqdn = "foo.example.org";
builder.setHostAddressByNameOrIp(fqdn);
builder.setHost(fqdn);
DummyConnectionConfiguration connectionConfiguration = builder.build();
assertEquals(fqdn, connectionConfiguration.getHost().toString());