diff --git a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLConnectionFactory.java b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLConnectionFactory.java index cf7baaadf..d46a2eb6e 100644 --- a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLConnectionFactory.java +++ b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLConnectionFactory.java @@ -17,10 +17,7 @@ import io.vertx.core.impl.ContextInternal; import io.vertx.core.impl.EventLoopContext; import io.vertx.core.impl.VertxInternal; -import io.vertx.core.net.NetClient; -import io.vertx.core.net.NetClientOptions; -import io.vertx.core.net.NetSocket; -import io.vertx.core.net.SocketAddress; +import io.vertx.core.net.*; import io.vertx.core.net.impl.NetSocketInternal; import io.vertx.core.spi.metrics.ClientMetrics; import io.vertx.core.spi.metrics.VertxMetrics; @@ -62,13 +59,18 @@ private Future connectOrRedirect(MSSQLConnectOptions options, EventL ) .compose(connBase -> { MSSQLSocketConnection conn = (MSSQLSocketConnection) connBase; - SocketAddress alternateServer = conn.getAlternateServer(); + HostAndPort alternateServer = conn.getAlternateServer(); if (alternateServer == null) { return context.succeededFuture(conn); } Promise closePromise = context.promise(); conn.close(null, closePromise); - return closePromise.future().transform(v -> connectOrRedirect(options, context, redirections + 1)); + return closePromise.future().transform(v -> { + MSSQLConnectOptions connectOptions = new MSSQLConnectOptions(options) + .setHost(alternateServer.host()) + .setPort(alternateServer.port()); + return connectOrRedirect(connectOptions, context, redirections + 1); + }); }); } diff --git a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLSocketConnection.java b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLSocketConnection.java index 966e1f739..f097d86ce 100644 --- a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLSocketConnection.java +++ b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLSocketConnection.java @@ -19,7 +19,7 @@ import io.vertx.core.Handler; import io.vertx.core.impl.EventLoopContext; import io.vertx.core.impl.future.PromiseInternal; -import io.vertx.core.net.SocketAddress; +import io.vertx.core.net.HostAndPort; import io.vertx.core.net.impl.NetSocketInternal; import io.vertx.core.net.impl.SSLHelper; import io.vertx.core.net.impl.SslHandshakeCompletionHandler; @@ -49,7 +49,7 @@ public class MSSQLSocketConnection extends SocketConnectionBase { private final int packetSize; private MSSQLDatabaseMetadata databaseMetadata; - private SocketAddress alternateServer; + private HostAndPort alternateServer; MSSQLSocketConnection(NetSocketInternal socket, ClientMetrics clientMetrics, @@ -173,11 +173,11 @@ private void setDatabaseMetadata(MSSQLDatabaseMetadata metadata) { this.databaseMetadata = metadata; } - public SocketAddress getAlternateServer() { + public HostAndPort getAlternateServer() { return alternateServer; } - public void setAlternateServer(SocketAddress alternateServer) { + public void setAlternateServer(HostAndPort alternateServer) { this.alternateServer = alternateServer; } } diff --git a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/InitCommandCodec.java b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/InitCommandCodec.java index 8ba62716d..44d919302 100644 --- a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/InitCommandCodec.java +++ b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/InitCommandCodec.java @@ -12,7 +12,7 @@ package io.vertx.mssqlclient.impl.codec; import io.netty.buffer.ByteBuf; -import io.vertx.core.net.SocketAddress; +import io.vertx.core.net.HostAndPort; import io.vertx.mssqlclient.MSSQLConnectOptions; import io.vertx.mssqlclient.impl.MSSQLSocketConnection; import io.vertx.mssqlclient.impl.protocol.client.login.LoginPacket; @@ -220,6 +220,6 @@ protected void handleRouting(ByteBuf payload) { throw new IllegalStateException("ProtocolProperty value of zero is not allowed when Protocol is TCP-IP"); } String host = readUnsignedShortLengthString(payload); - conn.setAlternateServer(SocketAddress.inetSocketAddress(port, host.toLowerCase(ENGLISH))); + conn.setAlternateServer(HostAndPort.create(host.toLowerCase(ENGLISH), port)); } }