throw new RuntimeException("TEST FAILED: " +
"local host name not looked up in name service");
}
System.err.println("Local host name is \"" + localName + "\"");
final ServerEndpoint se = getServerEndpoint();
final ListenContext lc = new ListenContext() {
public ListenCookie addListenEndpoint(ListenEndpoint le)
throws IOException
{
return le.listen(new RequestDispatcher() {
public void dispatch(InboundRequest r) { }
}).getCookie();
}
};
/*
* Verify that invoking enumerateListenEndpoints with
* permission to resolve the local host name throws an
* UnknownHostException that does contain the local host name
* in its detail message.
*/
System.err.println("Trying with permission:");
try {
se.enumerateListenEndpoints(lc);
throw new RuntimeException("TEST FAILED");
} catch (UnknownHostException e) {
e.printStackTrace();
String message = e.getMessage();
if (message == null || message.indexOf(localName) == -1) {
throw new RuntimeException("TEST FAILED: " +
"exception message does not contain local host name");
}
}
/*
* Verify that invoking enumerateListenEndpoints without
* permission to resolve the local host name throws an
* UnknownHostException that does not contain the local host
* name in its detail message.
*/
System.err.println("Trying without permission:");
AccessControlContext acc = new AccessControlContext(
new ProtectionDomain[] { new ProtectionDomain(null, null) });
try {
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws IOException {
se.enumerateListenEndpoints(lc);
throw new RuntimeException("TEST FAILED");
}
}, acc);
} catch (PrivilegedActionException pae) {
IOException e = (IOException) pae.getCause();