From 6a43174e1beb66446601e5c87063d07de92d2418 Mon Sep 17 00:00:00 2001
From: Chris Ridd <chris.ridd@forgerock.com>
Date: Thu, 22 May 2014 09:46:17 +0000
Subject: [PATCH] Fix OPENDJ-1466: Improve initialization of InetSocketAddress in SDK to prevent cached DNS data.
---
opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionFactory.java | 46 ++++++++++++++++++++++++++++++++--------------
1 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionFactory.java b/opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionFactory.java
index abe101c..f67bd22 100644
--- a/opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionFactory.java
+++ b/opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionFactory.java
@@ -217,7 +217,7 @@
return timeoutEndTime - currentTime;
} else {
future.handleErrorResult(newErrorResult(ResultCode.CLIENT_SIDE_CONNECT_ERROR,
- LDAP_CONNECTION_CONNECT_TIMEOUT.get(socketAddress, getTimeout()).toString()));
+ LDAP_CONNECTION_CONNECT_TIMEOUT.get(getSocketAddress(), getTimeout()).toString()));
return 0;
}
}
@@ -231,7 +231,8 @@
private final LDAPClientFilter clientFilter;
private final FilterChain defaultFilterChain;
private final LDAPOptions options;
- private final InetSocketAddress socketAddress;
+ private final String host;
+ private final int port;
/**
* Prevents the transport and timeoutChecker being released when there are
@@ -254,13 +255,15 @@
* to create connections to the Directory Server at the provided host and
* port address using provided connection options.
*
- * @param address
- * The address of the Directory Server to connect to.
+ * @param host
+ * The hostname of the Directory Server to connect to.
+ * @param port
+ * The port number of the Directory Server to connect to.
* @param options
* The LDAP connection options to use when creating connections.
*/
- public GrizzlyLDAPConnectionFactory(final InetSocketAddress address, final LDAPOptions options) {
- this(address, options, null);
+ public GrizzlyLDAPConnectionFactory(final String host, final int port, final LDAPOptions options) {
+ this(host, port, options, null);
}
/**
@@ -269,18 +272,21 @@
* port address using provided connection options and provided TCP
* transport.
*
- * @param address
- * The address of the Directory Server to connect to.
+ * @param host
+ * The hostname of the Directory Server to connect to.
+ * @param port
+ * The port number of the Directory Server to connect to.
* @param options
* The LDAP connection options to use when creating connections.
* @param transport
* Grizzly TCP Transport NIO implementation to use for
* connections. If {@code null}, default transport will be used.
*/
- public GrizzlyLDAPConnectionFactory(final InetSocketAddress address, final LDAPOptions options,
- TCPNIOTransport transport) {
+ public GrizzlyLDAPConnectionFactory(final String host, final int port, final LDAPOptions options,
+ TCPNIOTransport transport) {
this.transport = DEFAULT_TRANSPORT.acquireIfNull(transport);
- this.socketAddress = address;
+ this.host = host;
+ this.port = port;
this.options = new LDAPOptions(options);
this.clientFilter = new LDAPClientFilter(this.options.getDecodeOptions(), 0);
this.defaultFilterChain =
@@ -312,20 +318,32 @@
.build();
final AsynchronousFutureResult<Connection, ResultHandler<? super Connection>> future =
new AsynchronousFutureResult<Connection, ResultHandler<? super Connection>>(handler);
- connectorHandler.connect(socketAddress, new CompletionHandlerAdapter(future));
+ connectorHandler.connect(getSocketAddress(), new CompletionHandlerAdapter(future));
return future;
}
@Override
public InetSocketAddress getSocketAddress() {
- return socketAddress;
+ return new InetSocketAddress(host, port);
+ }
+
+ @Override
+ public String getHostName() {
+ return host;
+ }
+
+ @Override
+ public int getPort() {
+ return port;
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("LDAPConnectionFactory(");
- builder.append(getSocketAddress().toString());
+ builder.append(host);
+ builder.append(':');
+ builder.append(port);
builder.append(')');
return builder.toString();
}
--
Gitblit v1.10.0