use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.
the class UnderscoreHost method main.
public static void main(String[] args) {
UnderscoreHost t = null;
try {
HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory();
RMISocketFactory.setSocketFactory(hvf);
Registry r = TestLibrary.createRegistryOnUnusedPort();
int port = TestLibrary.getRegistryPort(r);
t = new UnderscoreHost();
r.rebind(NAME, t);
Naming.lookup("rmi://" + HOSTNAME + ":" + port + "/" + NAME);
/*
* This test is coded to pass whether java.net.URI obeys
* RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.).
*
* If java.net.URI obeys RFC 3986, so host names may
* contain underscores, then the Naming.lookup invocation
* should succeed-- but the host actually connected to
* must equal HOSTNAME.
*/
if (!hvf.host.equals(HOSTNAME)) {
throw new RuntimeException("java.rmi.Naming Parsing error:" + hvf.host + ":" + HOSTNAME);
}
} catch (MalformedURLException e) {
/*
* If java.net.URI obeys RFC 2396, so host names must not
* contain underscores, then the Naming.lookup invocation
* should throw MalformedURLException-- so this is OK.
*/
} catch (IOException ioe) {
TestLibrary.bomb(ioe);
} catch (java.rmi.NotBoundException nbe) {
TestLibrary.bomb(nbe);
} finally {
TestLibrary.unexport(t);
}
}
use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.
the class DefaultRegistryPort method main.
public static void main(String[] args) {
Registry registry = null;
try {
System.err.println("Starting registry on default port REGISTRY_PORT=" + Registry.REGISTRY_PORT);
registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
System.err.println("Created registry=" + registry);
} catch (java.rmi.RemoteException e) {
try {
System.err.println("Failed to create a registry, try using existing one");
registry = LocateRegistry.getRegistry();
System.err.println("Found registry=" + registry);
} catch (Exception ge) {
TestLibrary.bomb("Test Failed: cound not find or create a registry");
}
}
try {
if (registry != null) {
registry.rebind("myself", registry);
Remote myself = Naming.lookup("rmi://localhost/myself");
System.err.println("Test PASSED");
} else {
TestLibrary.bomb("Test Failed: cound not find or create a registry");
}
} catch (java.rmi.NotBoundException e) {
TestLibrary.bomb("Test Failed: could not find myself");
} catch (Exception e) {
e.printStackTrace();
TestLibrary.bomb("Test failed: unexpected exception");
}
}
use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.
the class ApplicationServer method run.
/*
* On initialization, export remote objects and register
* them with server.
*/
public void run() {
try {
int i = 0;
/*
* Locate apple user object in registry. The lookup will
* occur until it is successful or fails LOOKUP_ATTEMPTS times.
* These repeated attempts allow the ApplicationServer
* to be started before the AppleUserImpl.
*/
Exception exc = null;
for (i = 0; i < LOOKUP_ATTEMPTS; i++) {
try {
Registry registry = LocateRegistry.getRegistry(registryHost, registryPort);
user = (AppleUser) registry.lookup("AppleUser");
user.startTest();
//successfully obtained AppleUser
break;
} catch (Exception e) {
exc = e;
//sleep 10 seconds and try again
Thread.sleep(10000);
}
}
if (user == null) {
logger.log(Level.SEVERE, "Failed to lookup AppleUser:", exc);
return;
}
/*
* Create and export apple implementations.
*/
try {
for (i = 0; i < numApples; i++) {
apples[i] = new AppleImpl("AppleImpl #" + (i + 1));
}
} catch (RemoteException e) {
logger.log(Level.SEVERE, "Failed to create AppleImpl #" + (i + 1) + ":", e);
user.reportException(e);
return;
}
/*
* Hand apple objects to apple user.
*/
try {
for (i = 0; i < numApples; i++) {
user.useApple(apples[i]);
}
} catch (RemoteException e) {
logger.log(Level.SEVERE, "Failed to register callbacks for " + apples[i] + ":", e);
user.reportException(e);
return;
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Unexpected exception:", e);
}
}
use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.
the class HandshakeFailure method main.
public static void main(String[] args) throws Exception {
/*
* Listen on port...
*/
ServerSocket serverSocket = new ServerSocket(PORT);
/*
* (Attempt RMI call to port in separate thread.)
*/
Registry registry = LocateRegistry.getRegistry(PORT);
Connector connector = new Connector(registry);
Thread t = new Thread(connector);
t.setDaemon(true);
t.start();
/*
* ...accept one connection from port and send non-JRMP data.
*/
Socket socket = serverSocket.accept();
socket.getOutputStream().write("Wrong way".getBytes());
socket.close();
/*
* Wait for call attempt to finish, and analyze result.
*/
t.join(TIMEOUT);
synchronized (connector) {
if (connector.success) {
throw new RuntimeException("TEST FAILED: remote call succeeded??");
}
if (connector.exception == null) {
throw new RuntimeException("TEST FAILED: remote call did not time out");
} else {
System.err.println("remote call failed with exception:");
connector.exception.printStackTrace();
System.err.println();
if (connector.exception instanceof MarshalException) {
System.err.println("TEST FAILED: MarshalException thrown, expecting " + "java.rmi.ConnectException or ConnectIOException");
} else if (connector.exception instanceof ConnectException || connector.exception instanceof ConnectIOException) {
System.err.println("TEST PASSED: java.rmi.ConnectException or " + "ConnectIOException thrown");
} else {
throw new RuntimeException("TEST FAILED: unexpected Exception thrown", connector.exception);
}
}
}
}
use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.
the class CloseServerSocket method main.
public static void main(String[] args) throws Exception {
System.err.println("\nRegression test for bug 4457683\n");
verifyPortFree(PORT);
Registry registry = LocateRegistry.createRegistry(PORT);
System.err.println("- exported registry: " + registry);
verifyPortInUse(PORT);
UnicastRemoteObject.unexportObject(registry, true);
System.err.println("- unexported registry");
// work around BindException (bug?)
Thread.sleep(1000);
verifyPortFree(PORT);
/*
* The follow portion of this test is disabled temporarily
* because 4457683 was partially backed out because of
* 6269166; for now, only server sockets originally opened for
* exports on non-anonymous ports will be closed when all of
* the corresponding remote objects have been exported. A
* separate bug will be filed to represent the remainder of
* 4457683 for anonymous-port exports.
*/
// SSF ssf = new SSF();
// Remote impl = new CloseServerSocket();
// Remote stub = UnicastRemoteObject.exportObject(impl, 0, null, ssf);
// System.err.println("- exported object: " + stub);
// UnicastRemoteObject.unexportObject(impl, true);
// System.err.println("- unexported object");
// synchronized (ssf) {
// if (!ssf.serverSocketClosed) {
// throw new RuntimeException("TEST FAILED: " +
// "server socket not closed");
// }
// }
System.err.println("TEST PASSED");
}
Aggregations