URI loopback = URIHelper.create(scheme, loopbackIP, port);
SocketRequestInfo acceptInfo = getSocketRequestInfo(loopback);
acceptInfo.setBindAll(false);
// create the acceptor
ManagedConnectionAcceptor acceptor
= createAcceptor(null, acceptInfo);
TestAcceptorEventListener listener = new TestAcceptorEventListener(
new TestInvocationHandler());
acceptor.accept(listener);
// connections to this should fail
String host = InetAddress.getLocalHost().getHostName();
URI localhost = URIHelper.create(scheme, host, port);
SocketRequestInfo failInfo = getSocketRequestInfo(localhost);
// verify that a connection can't be established
try {
createConnection(null, failInfo);
fail("Expected connection to " + localhost + " to fail");
} catch (ResourceException exception) {
// the expected behaviour
}
// verify that a connection can be established via the loopback URI
SocketRequestInfo info = getSocketRequestInfo(loopback);
ManagedConnection connection = null;
try {
connection = createConnection(null, info);
} catch (Exception exception) {
fail("Expected connections to " + loopback + " to succeed:" +
exception);
}
// clean up
connection.destroy();
// NB: the ServerSocket doesn't seem to close down under JDK 1.3.1
// and 1.4.1 if the accepted sockets aren't closed first.
// This only happens when the ServerSocket is bound to a single address
listener.destroy();
acceptor.close();
}