Fix OPENDJ-1466: Improve initialization of InetSocketAddress in SDK to prevent cached DNS data.
| | |
| | | Note: waiting on https://jira.codehaus.org/browse/MCLIRR-62 to be resolved to avoid the need to use \s* in the '<to>' tags. |
| | | --> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/LDAPConnectionFactory</className> |
| | | <differenceType>7002</differenceType> |
| | | <method>LDAPConnectionFactory(java.net.SocketAddress)</method> |
| | | <justification>Moving from inetSocketAddress to host+port constructors</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/LDAPConnectionFactory</className> |
| | | <differenceType>7002</differenceType> |
| | | <method>LDAPConnectionFactory(java.net.SocketAddress, org.forgerock.opendj.ldap.LDAPOptions)</method> |
| | | <justification>Moving from inetSocketAddress to host+port constructors</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/LDAPConnectionFactory</className> |
| | | <differenceType>7002</differenceType> |
| | | <method>java.net.InetAddress getAddress()</method> |
| | | <justification>Moving from inetSocketAddress to host+port constructors</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/LDAPConnectionFactory</className> |
| | | <differenceType>7002</differenceType> |
| | | <method>java.net.SocketAddress getSocketAddress()</method> |
| | | <justification>Moving from inetSocketAddress to host+port constructors</justification> |
| | | </difference> |
| | | |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/CoreMessages</className> |
| | | <differenceType>8001</differenceType> |
| | | <justification>Incorrectly reported because it is automatically generated</justification> |
| | |
| | | |
| | | import static com.forgerock.opendj.util.StaticUtils.getProvider; |
| | | |
| | | import java.net.InetAddress; |
| | | import java.net.InetSocketAddress; |
| | | |
| | | import org.forgerock.opendj.ldap.spi.LDAPConnectionFactoryImpl; |
| | | import org.forgerock.opendj.ldap.spi.TransportProvider; |
| | | import org.forgerock.util.Reject; |
| | |
| | | |
| | | /** |
| | | * Creates a new LDAP connection factory which can be used to create LDAP |
| | | * connections to the Directory Server at the provided address. |
| | | * |
| | | * @param address |
| | | * The address of the Directory Server. |
| | | * @throws NullPointerException |
| | | * If {@code address} was {@code null}. |
| | | * @throws ProviderNotFoundException if no provider is available or if the |
| | | * provider requested using options is not found. |
| | | */ |
| | | public LDAPConnectionFactory(final InetSocketAddress address) { |
| | | this(address, new LDAPOptions()); |
| | | } |
| | | |
| | | /** |
| | | * Creates a new LDAP connection factory which can be used to create LDAP |
| | | * connections to the Directory Server at the provided address. |
| | | * |
| | | * @param address |
| | | * The address of the Directory Server. |
| | | * @param options |
| | | * The LDAP options to use when creating connections. |
| | | * @throws NullPointerException |
| | | * If {@code address} or {@code options} was {@code null}. |
| | | * @throws ProviderNotFoundException if no provider is available or if the |
| | | * provider requested using options is not found. |
| | | */ |
| | | public LDAPConnectionFactory(final InetSocketAddress address, final LDAPOptions options) { |
| | | Reject.ifNull(address, options); |
| | | this.provider = getProvider(TransportProvider.class, options.getTransportProvider(), |
| | | options.getProviderClassLoader()); |
| | | this.impl = provider.getLDAPConnectionFactory(address, options); |
| | | } |
| | | |
| | | /** |
| | | * Creates a new LDAP connection factory which can be used to create LDAP |
| | | * connections to the Directory Server at the provided host and port |
| | | * address. |
| | | * number. |
| | | * |
| | | * @param host |
| | | * The host name. |
| | |
| | | /** |
| | | * Creates a new LDAP connection factory which can be used to create LDAP |
| | | * connections to the Directory Server at the provided host and port |
| | | * address. |
| | | * number. |
| | | * |
| | | * @param host |
| | | * The host name. |
| | |
| | | */ |
| | | public LDAPConnectionFactory(final String host, final int port, final LDAPOptions options) { |
| | | Reject.ifNull(host, options); |
| | | final InetSocketAddress address = new InetSocketAddress(host, port); |
| | | this.provider = getProvider(TransportProvider.class, options.getTransportProvider(), |
| | | options.getProviderClassLoader()); |
| | | this.impl = provider.getLDAPConnectionFactory(address, options); |
| | | } |
| | | |
| | | /** |
| | | * Returns the {@code InetAddress} of the Directory Server. |
| | | * |
| | | * @return The {@code InetAddress} of the Directory Server. |
| | | */ |
| | | public InetAddress getAddress() { |
| | | return getSocketAddress().getAddress(); |
| | | this.impl = provider.getLDAPConnectionFactory(host, port, options); |
| | | } |
| | | |
| | | @Override |
| | |
| | | * @return The host name of the Directory Server. |
| | | */ |
| | | public String getHostName() { |
| | | return Connections.getHostString(getSocketAddress()); |
| | | return impl.getHostName(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return The port of the Directory Server. |
| | | */ |
| | | public int getPort() { |
| | | return getSocketAddress().getPort(); |
| | | } |
| | | |
| | | /** |
| | | * Returns the address of the Directory Server. |
| | | * |
| | | * @return The address of the Directory Server. |
| | | */ |
| | | public InetSocketAddress getSocketAddress() { |
| | | return impl.getSocketAddress(); |
| | | return impl.getPort(); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public InetSocketAddress getSocketAddress(); |
| | | |
| | | /** |
| | | * Returns the hostname used by the connections created by this factory. |
| | | * |
| | | * @return The hostname used by the connections. |
| | | */ |
| | | public String getHostName(); |
| | | |
| | | /** |
| | | * Returns the remote port number used by the connections created by this |
| | | * factory. |
| | | * |
| | | * @return The remote port number used by the connections. |
| | | */ |
| | | public int getPort(); |
| | | |
| | | } |
| | |
| | | public interface TransportProvider extends Provider { |
| | | |
| | | /** |
| | | * Returns an implementation of {@code LDAPConnectionFactory}. |
| | | * Returns an implementation of {@code LDAPConnectionFactory}. The address |
| | | * will be resolved each time a new connection is returned. |
| | | * |
| | | * @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 options to use when creating connections. |
| | | * @return an implementation of {@code LDAPConnectionFactory} |
| | | */ |
| | | LDAPConnectionFactoryImpl getLDAPConnectionFactory(InetSocketAddress address, |
| | | LDAPConnectionFactoryImpl getLDAPConnectionFactory(String host, int port, |
| | | LDAPOptions options); |
| | | |
| | | /** |
| | | /** |
| | | * Returns an implementation of {@code LDAPListener}. |
| | | * |
| | | * @param address |
| | |
| | | public final class BasicLDAPConnectionFactory implements LDAPConnectionFactoryImpl { |
| | | |
| | | private final LDAPOptions options; |
| | | private final InetSocketAddress socketAddress; |
| | | private final String host; |
| | | private final int port; |
| | | |
| | | /** |
| | | * Creates a new LDAP connection factory which does nothing. |
| | | * |
| | | * @param address |
| | | * @param host |
| | | * The address of the Directory Server to connect to. |
| | | * @param port |
| | | * The port of the Directory Server to connect to. |
| | | * @param options |
| | | * The LDAP connection options to use when creating connections. |
| | | */ |
| | | public BasicLDAPConnectionFactory(final InetSocketAddress address, final LDAPOptions options) { |
| | | this.socketAddress = address; |
| | | public BasicLDAPConnectionFactory(final String host, final int port, final LDAPOptions options) { |
| | | this.host = host; |
| | | this.port = port; |
| | | this.options = new LDAPOptions(options); |
| | | } |
| | | |
| | |
| | | * @return The address of the Directory Server. |
| | | */ |
| | | 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(); |
| | | } |
| | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public LDAPConnectionFactoryImpl getLDAPConnectionFactory(InetSocketAddress address, LDAPOptions options) { |
| | | return new BasicLDAPConnectionFactory(address, options); |
| | | public LDAPConnectionFactoryImpl getLDAPConnectionFactory(String host, int port, LDAPOptions options) { |
| | | return new BasicLDAPConnectionFactory(host, port, options); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | |
| | | public class GrizzlyTransportProvider implements TransportProvider { |
| | | |
| | | @Override |
| | | public LDAPConnectionFactoryImpl getLDAPConnectionFactory(InetSocketAddress address, |
| | | LDAPOptions options) { |
| | | return new GrizzlyLDAPConnectionFactory(address, options); |
| | | public LDAPConnectionFactoryImpl getLDAPConnectionFactory(String host, int port, |
| | | LDAPOptions options) { |
| | | return new GrizzlyLDAPConnectionFactory(host, port, options); |
| | | } |
| | | |
| | | @Override |
| | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | 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 |
| | |
| | | * 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); |
| | | } |
| | | |
| | | /** |
| | |
| | | * 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 = |
| | |
| | | .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(); |
| | | } |
| | |
| | | import static org.mockito.Mockito.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.net.InetSocketAddress; |
| | | import java.util.Arrays; |
| | | import java.util.concurrent.Callable; |
| | | import java.util.concurrent.CountDownLatch; |
| | |
| | | Requests.newSearchRequest("uid=user.0,ou=people,o=test", SearchScope.BASE_OBJECT, |
| | | "objectclass=*", "cn"); |
| | | |
| | | InetSocketAddress serverAddress = getServerSocketAddress(); |
| | | factories[0][0] = |
| | | Connections.newHeartBeatConnectionFactory(new LDAPConnectionFactory( |
| | | getServerSocketAddress()), |
| | | serverAddress.getHostName(), serverAddress.getPort()), |
| | | 1000, 500, TimeUnit.MILLISECONDS, request); |
| | | |
| | | // InternalConnectionFactory |
| | |
| | | |
| | | // AuthenticatedConnectionFactory |
| | | factories[2][0] = |
| | | Connections.newAuthenticatedConnectionFactory(new LDAPConnectionFactory(getServerSocketAddress()), |
| | | Connections.newAuthenticatedConnectionFactory(new LDAPConnectionFactory( |
| | | serverAddress.getHostName(), serverAddress.getPort()), |
| | | Requests.newSimpleBindRequest("", new char[0])); |
| | | |
| | | // AuthenticatedConnectionFactory with multi-stage SASL |
| | | factories[3][0] = |
| | | Connections.newAuthenticatedConnectionFactory(new LDAPConnectionFactory(getServerSocketAddress()), |
| | | Connections.newAuthenticatedConnectionFactory(new LDAPConnectionFactory( |
| | | serverAddress.getHostName(), serverAddress.getPort()), |
| | | Requests.newCRAMMD5SASLBindRequest("id:user", "password".toCharArray())); |
| | | |
| | | // LDAPConnectionFactory with default options |
| | | factories[4][0] = new LDAPConnectionFactory(getServerSocketAddress()); |
| | | factories[4][0] = new LDAPConnectionFactory(serverAddress.getHostName(), serverAddress.getPort()); |
| | | |
| | | // LDAPConnectionFactory with startTLS |
| | | SSLContext sslContext = |
| | |
| | | "SSL_DH_anon_WITH_DES_CBC_SHA", "SSL_DH_anon_WITH_RC4_128_MD5", |
| | | "TLS_DH_anon_WITH_AES_128_CBC_SHA", |
| | | "TLS_DH_anon_WITH_AES_256_CBC_SHA" }); |
| | | factories[5][0] = new LDAPConnectionFactory(getServerSocketAddress(), options); |
| | | factories[5][0] = new LDAPConnectionFactory(serverAddress.getHostName(), serverAddress.getPort(), options); |
| | | |
| | | // startTLS + SASL confidentiality |
| | | // Use IP address here so that DIGEST-MD5 host verification works if |
| | |
| | | // FIXME: enable QOP once OPENDJ-514 is fixed. |
| | | factories[6][0] = |
| | | Connections.newAuthenticatedConnectionFactory(new LDAPConnectionFactory( |
| | | getServerSocketAddress(), options), Requests.newDigestMD5SASLBindRequest( |
| | | serverAddress.getHostName(), serverAddress.getPort(), options), |
| | | Requests.newDigestMD5SASLBindRequest( |
| | | "id:user", "password".toCharArray()).setCipher( |
| | | DigestMD5SASLBindRequest.CIPHER_LOW)); |
| | | |
| | | // Connection pool and load balancing tests. |
| | | InetSocketAddress offlineSocketAddress1 = findFreeSocketAddress(); |
| | | ConnectionFactory offlineServer1 = |
| | | Connections.newNamedConnectionFactory( |
| | | new LDAPConnectionFactory(findFreeSocketAddress()), "offline1"); |
| | | new LDAPConnectionFactory(offlineSocketAddress1.getHostName(), |
| | | offlineSocketAddress1.getPort()), "offline1"); |
| | | InetSocketAddress offlineSocketAddress2 = findFreeSocketAddress(); |
| | | ConnectionFactory offlineServer2 = |
| | | Connections.newNamedConnectionFactory( |
| | | new LDAPConnectionFactory(findFreeSocketAddress()), "offline2"); |
| | | new LDAPConnectionFactory(offlineSocketAddress2.getHostName(), |
| | | offlineSocketAddress2.getPort()), "offline2"); |
| | | ConnectionFactory onlineServer = |
| | | Connections.newNamedConnectionFactory( |
| | | new LDAPConnectionFactory(getServerSocketAddress()), "online"); |
| | | new LDAPConnectionFactory(serverAddress.getHostName(), |
| | | serverAddress.getPort()), "online"); |
| | | |
| | | // Connection pools. |
| | | factories[7][0] = Connections.newFixedConnectionPool(onlineServer, 10); |
| | |
| | | public void testSchemaUsage() throws Exception { |
| | | // Create a connection factory: this should always use the default |
| | | // schema, even if it is updated. |
| | | final ConnectionFactory factory = new LDAPConnectionFactory(getServerSocketAddress()); |
| | | InetSocketAddress socketAddress = getServerSocketAddress(); |
| | | final ConnectionFactory factory = new LDAPConnectionFactory(socketAddress.getHostName(), |
| | | socketAddress.getPort()); |
| | | final Schema defaultSchema = Schema.getDefaultSchema(); |
| | | |
| | | final Connection connection = factory.getConnection(); |
| | |
| | | LDAPListener listener = new LDAPListener(findFreeSocketAddress(), mockServer); |
| | | try { |
| | | LDAPConnectionFactory clientFactory = |
| | | new LDAPConnectionFactory(listener.getSocketAddress()); |
| | | new LDAPConnectionFactory(listener.getHostName(), listener.getPort()); |
| | | final Connection client = clientFactory.getConnection(); |
| | | connectLatch.await(TEST_TIMEOUT, TimeUnit.SECONDS); |
| | | MockConnectionEventListener mockListener = null; |
| | |
| | | LDAPListener listener = new LDAPListener(findFreeSocketAddress(), mockServer); |
| | | try { |
| | | LDAPConnectionFactory clientFactory = |
| | | new LDAPConnectionFactory(listener.getSocketAddress()); |
| | | new LDAPConnectionFactory(listener.getHostName(), |
| | | listener.getPort()); |
| | | final Connection client = clientFactory.getConnection(); |
| | | connectLatch.await(TEST_TIMEOUT, TimeUnit.SECONDS); |
| | | try { |
| | |
| | | @Test(description = "Test for OPENDJ-1121: Closing a connection after " |
| | | + "closing the connection factory causes NPE") |
| | | public void testFactoryCloseBeforeConnectionClose() throws Exception { |
| | | InetSocketAddress socketAddress = getServerSocketAddress(); |
| | | final ConnectionFactory factory = |
| | | newLoadBalancer(new FailoverLoadBalancingAlgorithm(Arrays.asList(newFixedConnectionPool( |
| | | newHeartBeatConnectionFactory(new LDAPConnectionFactory(getServerSocketAddress())), 2)))); |
| | | newHeartBeatConnectionFactory(new LDAPConnectionFactory( |
| | | socketAddress.getHostName(), socketAddress.getPort())), 2)))); |
| | | Connection conn = null; |
| | | try { |
| | | conn = factory.getConnection(); |
| | |
| | | import static org.mockito.Mockito.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.net.InetSocketAddress; |
| | | import java.util.concurrent.Semaphore; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.TimeoutException; |
| | |
| | | private final AtomicReference<LDAPClientContext> context = |
| | | new AtomicReference<LDAPClientContext>(); |
| | | private final LDAPListener server = createServer(); |
| | | private final ConnectionFactory factory = new LDAPConnectionFactory(server.getSocketAddress(), |
| | | new LDAPOptions().setTimeout(1, TimeUnit.MILLISECONDS)); |
| | | private final InetSocketAddress socketAddress = server.getSocketAddress(); |
| | | private final ConnectionFactory factory = new LDAPConnectionFactory(socketAddress.getHostName(), |
| | | socketAddress.getPort(), new LDAPOptions().setTimeout(1, TimeUnit.MILLISECONDS)); |
| | | private final ConnectionFactory pool = Connections.newFixedConnectionPool(factory, 10); |
| | | private volatile ServerConnection<Integer> serverConnection; |
| | | |
| | |
| | | @Test |
| | | public void testCreateLDAPConnectionFactory() throws Exception { |
| | | // test no exception is thrown, which means transport provider is correctly loaded |
| | | LDAPConnectionFactory factory = new LDAPConnectionFactory(findFreeSocketAddress()); |
| | | InetSocketAddress socketAddress = findFreeSocketAddress(); |
| | | LDAPConnectionFactory factory = new LDAPConnectionFactory(socketAddress.getHostName(), |
| | | socketAddress.getPort()); |
| | | factory.close(); |
| | | } |
| | | |
| | |
| | | expectedExceptionsMessageRegExp = "^The requested provider 'unknown' .*") |
| | | public void testCreateLDAPConnectionFactoryFailureProviderNotFound() throws Exception { |
| | | LDAPOptions options = new LDAPOptions().setTransportProvider("unknown"); |
| | | LDAPConnectionFactory factory = new LDAPConnectionFactory(findFreeSocketAddress(), options); |
| | | InetSocketAddress socketAddress = findFreeSocketAddress(); |
| | | LDAPConnectionFactory factory = new LDAPConnectionFactory(socketAddress.getHostName(), |
| | | socketAddress.getPort(), options); |
| | | factory.close(); |
| | | } |
| | | |
| | |
| | | LDAPOptions options = |
| | | new LDAPOptions().setProviderClassLoader(Thread.currentThread() |
| | | .getContextClassLoader()); |
| | | LDAPConnectionFactory factory = new LDAPConnectionFactory(findFreeSocketAddress(), options); |
| | | InetSocketAddress socketAddress = findFreeSocketAddress(); |
| | | LDAPConnectionFactory factory = new LDAPConnectionFactory(socketAddress.getHostName(), |
| | | socketAddress.getPort(), options); |
| | | factory.close(); |
| | | } |
| | | |
| | |
| | | * Use a very long time out in order to prevent the timeout thread from |
| | | * triggering the timeout. |
| | | */ |
| | | LDAPConnectionFactory factory = new LDAPConnectionFactory(address, |
| | | new LDAPOptions().setTimeout(100, TimeUnit.SECONDS)); |
| | | LDAPConnectionFactory factory = new LDAPConnectionFactory(address.getHostName(), |
| | | address.getPort(), new LDAPOptions().setTimeout(100, TimeUnit.SECONDS)); |
| | | GrizzlyLDAPConnection connection = (GrizzlyLDAPConnection) factory.getConnection(); |
| | | try { |
| | | SearchRequest request = |
| | |
| | | try { |
| | | // Connect and close. |
| | | final Connection connection = |
| | | new LDAPConnectionFactory(listener.getSocketAddress()).getConnection(); |
| | | new LDAPConnectionFactory(listener.getHostName(), |
| | | listener.getPort()).getConnection(); |
| | | assertThat(serverConnection.context.get(10, TimeUnit.SECONDS)).isNotNull(); |
| | | assertThat(serverConnection.isClosed.getCount()).isEqualTo(1); |
| | | connection.close(); |
| | |
| | | |
| | | try { |
| | | // Connection pool and load balancing tests. |
| | | InetSocketAddress offlineAddress1 = findFreeSocketAddress(); |
| | | final ConnectionFactory offlineServer1 = |
| | | Connections.newNamedConnectionFactory(new LDAPConnectionFactory( |
| | | findFreeSocketAddress()), "offline1"); |
| | | offlineAddress1.getHostName(), |
| | | offlineAddress1.getPort()), "offline1"); |
| | | InetSocketAddress offlineAddress2 = findFreeSocketAddress(); |
| | | final ConnectionFactory offlineServer2 = |
| | | Connections.newNamedConnectionFactory(new LDAPConnectionFactory( |
| | | findFreeSocketAddress()), "offline2"); |
| | | offlineAddress2.getHostName(), |
| | | offlineAddress2.getPort()), "offline2"); |
| | | final ConnectionFactory onlineServer = |
| | | Connections.newNamedConnectionFactory(new LDAPConnectionFactory( |
| | | onlineServerListener.getSocketAddress()), |
| | | "online"); |
| | | onlineServerListener.getHostName(), |
| | | onlineServerListener.getPort()), "online"); |
| | | |
| | | // Round robin. |
| | | final ConnectionFactory loadBalancer = |
| | |
| | | try { |
| | | // Connect and close. |
| | | final Connection connection = |
| | | new LDAPConnectionFactory(proxyListener.getSocketAddress()).getConnection(); |
| | | new LDAPConnectionFactory(proxyListener.getHostName(), |
| | | proxyListener.getPort()).getConnection(); |
| | | |
| | | assertThat(proxyServerConnection.context.get(10, TimeUnit.SECONDS)).isNotNull(); |
| | | assertThat(onlineServerConnection.context.get(10, TimeUnit.SECONDS)).isNotNull(); |
| | |
| | | |
| | | try { |
| | | // Connection pool and load balancing tests. |
| | | InetSocketAddress offlineAddress1 = findFreeSocketAddress(); |
| | | final ConnectionFactory offlineServer1 = |
| | | Connections.newNamedConnectionFactory( |
| | | new LDAPConnectionFactory(findFreeSocketAddress()), "offline1"); |
| | | new LDAPConnectionFactory(offlineAddress1.getHostName(), |
| | | offlineAddress1.getPort()), "offline1"); |
| | | InetSocketAddress offlineAddress2 = findFreeSocketAddress(); |
| | | final ConnectionFactory offlineServer2 = |
| | | Connections.newNamedConnectionFactory( |
| | | new LDAPConnectionFactory(findFreeSocketAddress()), "offline2"); |
| | | new LDAPConnectionFactory(offlineAddress2.getHostName(), |
| | | offlineAddress2.getPort()), "offline2"); |
| | | final ConnectionFactory onlineServer = |
| | | Connections.newNamedConnectionFactory( |
| | | new LDAPConnectionFactory(onlineServerListener.getSocketAddress()), "online"); |
| | | new LDAPConnectionFactory(onlineServerListener.getHostName(), |
| | | onlineServerListener.getPort()), "online"); |
| | | |
| | | // Round robin. |
| | | final ConnectionFactory loadBalancer = |
| | |
| | | try { |
| | | // Connect, bind, and close. |
| | | final Connection connection = |
| | | new LDAPConnectionFactory(proxyListener.getSocketAddress()).getConnection(); |
| | | new LDAPConnectionFactory(proxyListener.getHostName(), |
| | | proxyListener.getPort()).getConnection(); |
| | | try { |
| | | connection.bind("cn=test", "password".toCharArray()); |
| | | |
| | |
| | | public ServerConnection<Integer> handleAccept( |
| | | final LDAPClientContext clientContext) throws ErrorResultException { |
| | | // First attempt offline server. |
| | | InetSocketAddress offlineAddress = findFreeSocketAddress(); |
| | | LDAPConnectionFactory lcf = |
| | | new LDAPConnectionFactory(findFreeSocketAddress()); |
| | | new LDAPConnectionFactory(offlineAddress.getHostName(), |
| | | offlineAddress.getPort()); |
| | | try { |
| | | // This is expected to fail. |
| | | lcf.getConnection().close(); |
| | |
| | | // This is expected - so go to online server. |
| | | try { |
| | | lcf = |
| | | new LDAPConnectionFactory(onlineServerListener |
| | | .getSocketAddress()); |
| | | new LDAPConnectionFactory( |
| | | onlineServerListener.getHostName(), |
| | | onlineServerListener.getPort()); |
| | | lcf.getConnection().close(); |
| | | } catch (final Exception e) { |
| | | // Unexpected. |
| | |
| | | try { |
| | | // Connect and close. |
| | | final Connection connection = |
| | | new LDAPConnectionFactory(proxyListener.getSocketAddress()).getConnection(); |
| | | new LDAPConnectionFactory(proxyListener.getHostName(), |
| | | proxyListener.getPort()).getConnection(); |
| | | |
| | | assertThat(proxyServerConnection.context.get(10, TimeUnit.SECONDS)).isNotNull(); |
| | | assertThat(onlineServerConnection.context.get(10, TimeUnit.SECONDS)).isNotNull(); |
| | |
| | | final ResultHandler<BindResult> resultHandler) |
| | | throws UnsupportedOperationException { |
| | | // First attempt offline server. |
| | | LDAPConnectionFactory lcf = new LDAPConnectionFactory(findFreeSocketAddress()); |
| | | InetSocketAddress offlineAddress = findFreeSocketAddress(); |
| | | LDAPConnectionFactory lcf = new LDAPConnectionFactory(offlineAddress.getHostName(), |
| | | offlineAddress.getPort()); |
| | | try { |
| | | // This is expected to fail. |
| | | lcf.getConnection().close(); |
| | |
| | | } catch (final ConnectionException ce) { |
| | | // This is expected - so go to online server. |
| | | try { |
| | | lcf = new LDAPConnectionFactory(onlineServerListener.getSocketAddress()); |
| | | lcf = new LDAPConnectionFactory(onlineServerListener.getHostName(), |
| | | onlineServerListener.getPort()); |
| | | lcf.getConnection().close(); |
| | | resultHandler.handleResult(Responses.newBindResult(ResultCode.SUCCESS)); |
| | | } catch (final Exception e) { |
| | |
| | | try { |
| | | // Connect, bind, and close. |
| | | final Connection connection = |
| | | new LDAPConnectionFactory(proxyListener.getSocketAddress()).getConnection(); |
| | | new LDAPConnectionFactory(proxyListener.getHostName(), |
| | | proxyListener.getPort()).getConnection(); |
| | | try { |
| | | connection.bind("cn=test", "password".toCharArray()); |
| | | |
| | |
| | | |
| | | Connection connection = null; |
| | | try { |
| | | connection = new LDAPConnectionFactory(listener.getSocketAddress()). |
| | | connection = new LDAPConnectionFactory(listener.getHostName(), listener.getPort()). |
| | | getConnection(); |
| | | |
| | | // Small request |
| | |
| | | final Connection connection; |
| | | try { |
| | | // Connect and bind. |
| | | connection = new LDAPConnectionFactory(listener.getSocketAddress()).getConnection(); |
| | | connection = new LDAPConnectionFactory(listener.getHostName(), listener.getPort()).getConnection(); |
| | | try { |
| | | connection.bind("cn=test", "password".toCharArray()); |
| | | } catch (final ErrorResultException e) { |
| | |
| | | try { |
| | | // Connect and bind. |
| | | final Connection failedConnection = |
| | | new LDAPConnectionFactory(listener.getSocketAddress()).getConnection(); |
| | | new LDAPConnectionFactory(listener.getHostName(), |
| | | listener.getPort()).getConnection(); |
| | | failedConnection.close(); |
| | | connection.close(); |
| | | fail("Connection attempt to closed listener succeeded unexpectedly"); |