Search in sources :

Example 16 with Registry

use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.

the class HandshakeTimeout method main.

public static void main(String[] args) throws Exception {
    System.setProperty("sun.rmi.transport.tcp.handshakeTimeout", String.valueOf(TIMEOUT / 2));
    /*
         * Listen on port, but never process connections made to it.
         */
    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();
    /*
         * Wait for call attempt to finished, 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);
            }
        }
    }
}
Also used : MarshalException(java.rmi.MarshalException) ConnectIOException(java.rmi.ConnectIOException) ServerSocket(java.net.ServerSocket) LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry) ConnectException(java.rmi.ConnectException)

Example 17 with Registry

use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.

the class HttpSocketTest method main.

public static void main(String[] args) throws Exception {
    Registry registry = null;
    TestLibrary.suggestSecurityManager(null);
    // Set the socket factory.
    System.err.println("installing socket factory");
    RMISocketFactory.setSocketFactory(new RMIHttpToPortSocketFactory());
    int registryPort = -1;
    try {
        System.err.println("Starting registry");
        registry = TestLibrary.createRegistryOnUnusedPort();
        registryPort = TestLibrary.getRegistryPort(registry);
    } catch (Exception e) {
        TestLibrary.bomb(e);
    }
    try {
        registry.rebind(NAME, new HttpSocketTest());
        MyRemoteInterface httpTest = (MyRemoteInterface) Naming.lookup("//:" + registryPort + "/" + NAME);
        httpTest.setRemoteObject(new HttpSocketTest());
        Remote r = httpTest.getRemoteObject();
    } catch (Exception e) {
        TestLibrary.bomb(e);
    }
}
Also used : RMIHttpToPortSocketFactory(sun.rmi.transport.proxy.RMIHttpToPortSocketFactory) Remote(java.rmi.Remote) LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry) RemoteException(java.rmi.RemoteException)

Example 18 with Registry

use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.

the class ReuseDefaultPort method main.

public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 6269166\n");
    RMISocketFactory.setSocketFactory(new SF());
    Remote impl = new ReuseDefaultPort();
    Remote stub = UnicastRemoteObject.exportObject(impl, 0);
    System.err.println("- exported object: " + stub);
    try {
        Registry registry = LocateRegistry.createRegistry(PORT);
        System.err.println("- exported registry: " + registry);
        System.err.println("TEST PASSED");
    } finally {
        UnicastRemoteObject.unexportObject(impl, true);
    }
}
Also used : Remote(java.rmi.Remote) LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry)

Example 19 with Registry

use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.

the class PinClientSocketFactory method main.

public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 4486732\n");
    Factory factoryImpl = new FactoryImpl();
    Factory factoryStub = (Factory) UnicastRemoteObject.exportObject(factoryImpl, 0);
    for (int i = 0; i < SESSIONS; i++) {
        Session session = factoryStub.getSession();
        session.ping();
    }
    UnicastRemoteObject.unexportObject(factoryImpl, true);
    Registry registryImpl = TestLibrary.createRegistryOnEphemeralPort();
    int port = TestLibrary.getRegistryPort(registryImpl);
    System.out.println("Registry listening on port " + port);
    CSF csf = new CSF();
    Reference<CSF> registryRef = new WeakReference<CSF>(csf);
    Registry registryStub = LocateRegistry.getRegistry("", port, csf);
    csf = null;
    registryStub.list();
    registryStub = null;
    UnicastRemoteObject.unexportObject(registryImpl, true);
    System.gc();
    // allow connections to time out
    Thread.sleep(3 * Long.getLong("sun.rmi.transport.connectionTimeout", 15000));
    System.gc();
    if (CSF.deserializedInstances.size() != SESSIONS) {
        throw new Error("unexpected number of deserialized instances: " + CSF.deserializedInstances.size());
    }
    int nonNullCount = 0;
    for (Reference<CSF> ref : CSF.deserializedInstances) {
        csf = ref.get();
        if (csf != null) {
            System.err.println("non-null deserialized instance: " + csf);
            nonNullCount++;
        }
    }
    if (nonNullCount > 0) {
        throw new Error("TEST FAILED: " + nonNullCount + " non-null deserialized instances");
    }
    csf = registryRef.get();
    if (csf != null) {
        System.err.println("non-null registry instance: " + csf);
        throw new Error("TEST FAILED: non-null registry instance");
    }
    System.err.println("TEST PASSED");
}
Also used : WeakReference(java.lang.ref.WeakReference) RMIServerSocketFactory(java.rmi.server.RMIServerSocketFactory) RMIClientSocketFactory(java.rmi.server.RMIClientSocketFactory) Registry(java.rmi.registry.Registry) LocateRegistry(java.rmi.registry.LocateRegistry)

Example 20 with Registry

use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.

the class LegalRegistryNames method main.

public static void main(String[] args) throws RuntimeException {
    System.err.println("\nRegression test for bug/rfe 4254808\n");
    Registry registry = null;
    LegalRegistryNames legal = null;
    boolean oneFormFailed = false;
    String[] names = null;
    Vector legalForms = getLegalForms();
    Remote shouldFind = null;
    // create a registry and the test object
    try {
        legal = new LegalRegistryNames();
        System.err.println("Starting registry on default port");
        registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
    } catch (Exception e) {
        TestLibrary.bomb("registry already running on test port");
    }
    // enumerate through all legal URLs to verify that a remote
    // object can be bound and unbound
    String s = null;
    Enumeration en = legalForms.elements();
    while (en.hasMoreElements()) {
        s = (String) en.nextElement();
        System.err.println("\ntesting form: " + s);
        try {
            Naming.rebind(s, legal);
            names = registry.list();
            // ensure that the name in the registry is what is expected
            if ((names.length > 0) && (names[0].compareTo("MyName") != 0)) {
                oneFormFailed = true;
                System.err.println("\tRegistry entry for form: " + s + " is incorrect: " + names[0]);
            }
            // ensure that the object can be unbound under the URL string
            shouldFind = Naming.lookup(s);
            Naming.unbind(s);
            System.err.println("\tform " + s + " OK");
        } catch (Exception e) {
            e.printStackTrace();
            oneFormFailed = true;
            System.err.println("\tunexpected lookup or unbind " + "exception for form: " + s + e.getMessage());
        }
    }
    if (oneFormFailed) {
        TestLibrary.bomb("Test failed");
    }
    // get the test to exit quickly
    TestLibrary.unexport(legal);
}
Also used : Enumeration(java.util.Enumeration) Remote(java.rmi.Remote) LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry) Vector(java.util.Vector) UnknownHostException(java.net.UnknownHostException) RemoteException(java.rmi.RemoteException)

Aggregations

Registry (java.rmi.registry.Registry)77 LocateRegistry (java.rmi.registry.LocateRegistry)71 RemoteException (java.rmi.RemoteException)35 Remote (java.rmi.Remote)12 HashMap (java.util.HashMap)9 JMXServiceURL (javax.management.remote.JMXServiceURL)9 IOException (java.io.IOException)8 JMXConnector (javax.management.remote.JMXConnector)8 UnknownHostException (java.net.UnknownHostException)7 MBeanServer (javax.management.MBeanServer)7 MBeanServerConnection (javax.management.MBeanServerConnection)7 JMXConnectorServer (javax.management.remote.JMXConnectorServer)7 ObjectName (javax.management.ObjectName)6 JMXPluggableAuthenticator (com.sun.jmx.remote.security.JMXPluggableAuthenticator)5 InetAddress (java.net.InetAddress)5 MalformedURLException (java.net.MalformedURLException)5 AlreadyBoundException (java.rmi.AlreadyBoundException)5 Properties (java.util.Properties)5 Attribute (javax.management.Attribute)5 Notification (javax.management.Notification)5