@ThreadSafety(level=NOT_THREADSAFE) public final class LDAPListener extends java.lang.Thread
// Create a canned response request handler that will always return a // "SUCCESS" result in response to any request. CannedResponseRequestHandler requestHandler = new CannedResponseRequestHandler(ResultCode.SUCCESS, null, null, null); // A listen port of zero indicates that the listener should // automatically pick a free port on the system. int listenPort = 0; // Create and start an LDAP listener to accept requests and blindly // return success results. LDAPListenerConfig listenerConfig = new LDAPListenerConfig(listenPort, requestHandler); LDAPListener listener = new LDAPListener(listenerConfig); listener.startListening(); // Establish a connection to the listener and verify that a search // request will get a success result. LDAPConnection connection = new LDAPConnection("localhost", listener.getListenPort()); SearchResult searchResult = connection.search("dc=example,dc=com", SearchScope.BASE, Filter.createPresenceFilter("objectClass")); LDAPTestUtils.assertResultCodeEquals(searchResult, ResultCode.SUCCESS); // Close the connection and stop the listener. connection.close(); listener.shutDown(true);
Constructor and Description |
---|
LDAPListener(LDAPListenerConfig config)
Creates a new
LDAPListener object with the provided configuration. |
Modifier and Type | Method and Description |
---|---|
void |
closeAllConnections(boolean sendNoticeOfDisconnection)
Closes all connections that are currently established to this listener.
|
java.net.InetAddress |
getListenAddress()
Retrieves the address on which this listener is accepting client
connections.
|
int |
getListenPort()
Retrieves the port on which this listener is accepting client connections.
|
void |
run()
Operates in a loop, waiting for client connections to arrive and ensuring
that they are handled properly.
|
void |
shutDown(boolean closeExisting)
Indicates that this listener should stop accepting connections.
|
void |
startListening()
Creates the server socket for this listener and starts listening for client
connections.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public LDAPListener(@NotNull LDAPListenerConfig config)
LDAPListener
object with the provided configuration.
The startListening()
method must be called after creating the object
to actually start listening for requests.config
- The configuration to use for this listener.public void startListening() throws java.io.IOException
java.io.IOException
- If a problem occurs while creating the server socket.@InternalUseOnly public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void closeAllConnections(boolean sendNoticeOfDisconnection)
sendNoticeOfDisconnection
- Indicates whether to send the client a
notice of disconnection unsolicited
notification before closing the
connection.public void shutDown(boolean closeExisting)
closeExisting
- Indicates whether to close existing connections that
may already be established.@Nullable public java.net.InetAddress getListenAddress()
InetAddress.isAnyLocalAddress
method returns true
, then
clients should generally use localhost
to attempt to establish
connections.null
if it is not currently listening for
client connections.public int getListenPort()