Java Code Examples for java.rmi.server.RMISocketFactory#setSocketFactory()

The following examples show how to use java.rmi.server.RMISocketFactory#setSocketFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnderscoreHost.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }

}
 
Example 2
Source File: UnderscoreHost.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
    }

}
 
Example 3
Source File: UnderscoreHost.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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);
    }

}
 
Example 4
Source File: ReuseDefaultPort.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 5
Source File: ReuseDefaultPort.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 6
Source File: ReuseDefaultPort.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 7
Source File: ReuseDefaultPort.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 8
Source File: ReadTimeoutTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
    throws Exception
{
    // Make trouble for ourselves
    if (System.getSecurityManager() == null)
        System.setSecurityManager(new RMISecurityManager());

    // Flaky code alert - hope this is executed before TCPTransport.<clinit>
    System.setProperty("sun.rmi.transport.tcp.readTimeout", Integer.toString(DELAY));

    // Set the socket factory.
    System.err.println("(installing socket factory)");
    SomeFactory fac = new SomeFactory();
    RMISocketFactory.setSocketFactory(fac);

    // Create remote object
    TestImpl impl = new TestImpl();

    // Export and get which port.
    System.err.println("(exporting remote object)");
    TestIface stub = impl.export();
    Socket DoS = null;
    try {
        int port = fac.whichPort();

        // Sanity
        if (port == 0)
            throw new Error("TEST FAILED: export didn't reserve a port(?)");

        // Now, connect to that port
        //Thread.sleep(2000);
        System.err.println("(connecting to listening port on 127.0.0.1:" +
                           port + ")");
        DoS = new Socket("127.0.0.1", port);
        InputStream stream = DoS.getInputStream();

        // Read on the socket in the background
        boolean[] successful = new boolean[] { false };
        (new SomeReader(stream, successful)).start();

        // Wait for completion
        int nretries = 4;
        while (nretries-- > 0) {
            if (successful[0])
                break;
            Thread.sleep(DELAY);
        }

        if (successful[0]) {
            System.err.println("TEST PASSED.");
        } else {
            throw new Error("TEST FAILED.");
        }

    } finally {
        try {
            if (DoS != null)
                DoS.close();        // aborts the reader if still blocked
            impl.unexport();
        } catch (Throwable unmatter) {
        }
    }

    // Should exit here
}
 
Example 9
Source File: ReadTimeoutTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
    throws Exception
{
    // Make trouble for ourselves
    if (System.getSecurityManager() == null)
        System.setSecurityManager(new RMISecurityManager());

    // Flaky code alert - hope this is executed before TCPTransport.<clinit>
    System.setProperty("sun.rmi.transport.tcp.readTimeout", Integer.toString(DELAY));

    // Set the socket factory.
    System.err.println("(installing socket factory)");
    SomeFactory fac = new SomeFactory();
    RMISocketFactory.setSocketFactory(fac);

    // Create remote object
    TestImpl impl = new TestImpl();

    // Export and get which port.
    System.err.println("(exporting remote object)");
    TestIface stub = impl.export();
    Socket DoS = null;
    try {
        int port = fac.whichPort();

        // Sanity
        if (port == 0)
            throw new Error("TEST FAILED: export didn't reserve a port(?)");

        // Now, connect to that port
        //Thread.sleep(2000);
        System.err.println("(connecting to listening port on 127.0.0.1:" +
                           port + ")");
        DoS = new Socket("127.0.0.1", port);
        InputStream stream = DoS.getInputStream();

        // Read on the socket in the background
        boolean[] successful = new boolean[] { false };
        (new SomeReader(stream, successful)).start();

        // Wait for completion
        int nretries = 4;
        while (nretries-- > 0) {
            if (successful[0])
                break;
            Thread.sleep(DELAY);
        }

        if (successful[0]) {
            System.err.println("TEST PASSED.");
        } else {
            throw new Error("TEST FAILED.");
        }

    } finally {
        try {
            if (DoS != null)
                DoS.close();        // aborts the reader if still blocked
            impl.unexport();
        } catch (Throwable unmatter) {
        }
    }

    // Should exit here
}
 
Example 10
Source File: ReadTimeoutTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
    throws Exception
{
    // Make trouble for ourselves
    if (System.getSecurityManager() == null)
        System.setSecurityManager(new RMISecurityManager());

    // Flaky code alert - hope this is executed before TCPTransport.<clinit>
    System.setProperty("sun.rmi.transport.tcp.readTimeout", Integer.toString(DELAY));

    // Set the socket factory.
    System.err.println("(installing socket factory)");
    SomeFactory fac = new SomeFactory();
    RMISocketFactory.setSocketFactory(fac);

    // Create remote object
    TestImpl impl = new TestImpl();

    // Export and get which port.
    System.err.println("(exporting remote object)");
    TestIface stub = impl.export();
    Socket DoS = null;
    try {
        int port = fac.whichPort();

        // Sanity
        if (port == 0)
            throw new Error("TEST FAILED: export didn't reserve a port(?)");

        // Now, connect to that port
        //Thread.sleep(2000);
        System.err.println("(connecting to listening port on 127.0.0.1:" +
                           port + ")");
        DoS = new Socket("127.0.0.1", port);
        InputStream stream = DoS.getInputStream();

        // Read on the socket in the background
        boolean[] successful = new boolean[] { false };
        (new SomeReader(stream, successful)).start();

        // Wait for completion
        int nretries = 4;
        while (nretries-- > 0) {
            if (successful[0])
                break;
            Thread.sleep(DELAY);
        }

        if (successful[0]) {
            System.err.println("TEST PASSED.");
        } else {
            throw new Error("TEST FAILED.");
        }

    } finally {
        try {
            if (DoS != null)
                DoS.close();        // aborts the reader if still blocked
            impl.unexport();
        } catch (Throwable unmatter) {
        }
    }

    // Should exit here
}
 
Example 11
Source File: ReadTimeoutTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
    throws Exception
{
    // Make trouble for ourselves
    if (System.getSecurityManager() == null)
        System.setSecurityManager(new RMISecurityManager());

    // Flaky code alert - hope this is executed before TCPTransport.<clinit>
    System.setProperty("sun.rmi.transport.tcp.readTimeout", Integer.toString(DELAY));

    // Set the socket factory.
    System.err.println("(installing socket factory)");
    SomeFactory fac = new SomeFactory();
    RMISocketFactory.setSocketFactory(fac);

    // Create remote object
    TestImpl impl = new TestImpl();

    // Export and get which port.
    System.err.println("(exporting remote object)");
    TestIface stub = impl.export();
    Socket DoS = null;
    try {
        int port = fac.whichPort();

        // Sanity
        if (port == 0)
            throw new Error("TEST FAILED: export didn't reserve a port(?)");

        // Now, connect to that port
        //Thread.sleep(2000);
        System.err.println("(connecting to listening port on 127.0.0.1:" +
                           port + ")");
        DoS = new Socket("127.0.0.1", port);
        InputStream stream = DoS.getInputStream();

        // Read on the socket in the background
        boolean[] successful = new boolean[] { false };
        (new SomeReader(stream, successful)).start();

        // Wait for completion
        int nretries = 4;
        while (nretries-- > 0) {
            if (successful[0])
                break;
            Thread.sleep(DELAY);
        }

        if (successful[0]) {
            System.err.println("TEST PASSED.");
        } else {
            throw new Error("TEST FAILED.");
        }

    } finally {
        try {
            if (DoS != null)
                DoS.close();        // aborts the reader if still blocked
            impl.unexport();
        } catch (Throwable unmatter) {
        }
    }

    // Should exit here
}
 
Example 12
Source File: BlockAcceptTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
    throws Exception
{
    // Make trouble for ourselves
    if (System.getSecurityManager() == null)
        System.setSecurityManager(new RMISecurityManager());

    // HTTP direct to the server port
    System.setProperty("http.proxyHost", "127.0.0.1");

    // Set the socket factory.
    System.err.println("(installing HTTP-out socket factory)");
    HttpOutFactory fac = new HttpOutFactory();
    RMISocketFactory.setSocketFactory(fac);

    // Create remote object
    TestImpl impl = new TestImpl();

    // Export and get which port.
    System.err.println("(exporting remote object)");
    TestIface stub = impl.export();
    try {
        int port = fac.whichPort();

        // Sanity
        if (port == 0)
            throw new Error("TEST FAILED: export didn't reserve a port(?)");

        // Set the HTTP port, at last.
        System.setProperty("http.proxyPort", port+"");

        // Now, connect to that port
        //Thread.sleep(2000);
        System.err.println("(connecting to listening port on 127.0.0.1:" +
                           port + ")");
        Socket DoS = new Socket("127.0.0.1", port);
        // we hold the connection open until done with the test.

        // The test itself: make a remote call and see if it's blocked or
        // if it works
        //Thread.sleep(2000);
        System.err.println("(making RMI-through-HTTP call)");
        System.err.println("(typical test failure deadlocks here)");
        String result = stub.testCall("dummy load");

        System.err.println(" => " + result);
        if (!("OK".equals(result)))
            throw new Error("TEST FAILED: result not OK");
        System.err.println("Test passed.");

        // Clean up, including writing a byte to that connection just in
        // case an optimizer thought of optimizing it out of existence
        try {
            DoS.getOutputStream().write(0);
            DoS.getOutputStream().close();
        } catch (Throwable apathy) {
        }

    } finally {
        try {
            impl.unexport();
        } catch (Throwable unmatter) {
        }
    }

    // Should exit here
}
 
Example 13
Source File: BlockAcceptTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
    throws Exception
{
    // Make trouble for ourselves
    if (System.getSecurityManager() == null)
        System.setSecurityManager(new RMISecurityManager());

    // HTTP direct to the server port
    System.setProperty("http.proxyHost", "127.0.0.1");

    // Set the socket factory.
    System.err.println("(installing HTTP-out socket factory)");
    HttpOutFactory fac = new HttpOutFactory();
    RMISocketFactory.setSocketFactory(fac);

    // Create remote object
    TestImpl impl = new TestImpl();

    // Export and get which port.
    System.err.println("(exporting remote object)");
    TestIface stub = impl.export();
    try {
        int port = fac.whichPort();

        // Sanity
        if (port == 0)
            throw new Error("TEST FAILED: export didn't reserve a port(?)");

        // Set the HTTP port, at last.
        System.setProperty("http.proxyPort", port+"");

        // Now, connect to that port
        //Thread.sleep(2000);
        System.err.println("(connecting to listening port on 127.0.0.1:" +
                           port + ")");
        Socket DoS = new Socket("127.0.0.1", port);
        // we hold the connection open until done with the test.

        // The test itself: make a remote call and see if it's blocked or
        // if it works
        //Thread.sleep(2000);
        System.err.println("(making RMI-through-HTTP call)");
        System.err.println("(typical test failure deadlocks here)");
        String result = stub.testCall("dummy load");

        System.err.println(" => " + result);
        if (!("OK".equals(result)))
            throw new Error("TEST FAILED: result not OK");
        System.err.println("Test passed.");

        // Clean up, including writing a byte to that connection just in
        // case an optimizer thought of optimizing it out of existence
        try {
            DoS.getOutputStream().write(0);
            DoS.getOutputStream().close();
        } catch (Throwable apathy) {
        }

    } finally {
        try {
            impl.unexport();
        } catch (Throwable unmatter) {
        }
    }

    // Should exit here
}
 
Example 14
Source File: DisableRMIOverHTTPTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
    throws Exception
{
    // HTTP direct to the server port
    System.setProperty("http.proxyHost", "127.0.0.1");
    boolean incomingHttpDisabled =
            Boolean.valueOf(
                System.getProperty(
                        "sun.rmi.server.disableIncomingHttp", "true")
                    .equalsIgnoreCase("true"));

    // Set the socket factory.
    System.err.println("(installing HTTP-out socket factory)");
    HttpOutFactory fac = new HttpOutFactory();
    RMISocketFactory.setSocketFactory(fac);

    // Create remote object
    TestImpl impl = new TestImpl();

    // Export and get which port.
    System.err.println("(exporting remote object)");
    TestIface stub = impl.export();
    try {
        int port = fac.whichPort();

        // Sanity
        if (port == 0)
            throw new Error("TEST FAILED: export didn't reserve a port(?)");

        // The test itself: make a remote call and see if it's blocked or
        // if it works
        //Thread.sleep(2000);
        System.err.println("(making RMI-through-HTTP call)");
        String result = stub.testCall("dummy load");
        System.err.println(" => " + result);

        if ("OK".equals(result)) {
            if (incomingHttpDisabled) {
                throw new Error(
                    "TEST FAILED: should not receive result if incoming http is disabled");
            }
        } else {
            if (!incomingHttpDisabled) {
                throw new Error("TEST FAILED: result not OK");
            }
        }
        System.err.println("Test passed.");
    } catch (UnmarshalException e) {
        if (!incomingHttpDisabled) {
            throw e;
        } else {
            System.err.println("Test passed.");
        }
    } finally {
        try {
            impl.unexport();
        } catch (Throwable unmatter) {
        }
    }

    // Should exit here
}
 
Example 15
Source File: ReadTimeoutTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
    throws Exception
{
    // Make trouble for ourselves
    if (System.getSecurityManager() == null)
        System.setSecurityManager(new RMISecurityManager());

    // Flaky code alert - hope this is executed before TCPTransport.<clinit>
    System.setProperty("sun.rmi.transport.tcp.readTimeout", Integer.toString(DELAY));

    // Set the socket factory.
    System.err.println("(installing socket factory)");
    SomeFactory fac = new SomeFactory();
    RMISocketFactory.setSocketFactory(fac);

    // Create remote object
    TestImpl impl = new TestImpl();

    // Export and get which port.
    System.err.println("(exporting remote object)");
    TestIface stub = impl.export();
    Socket DoS = null;
    try {
        int port = fac.whichPort();

        // Sanity
        if (port == 0)
            throw new Error("TEST FAILED: export didn't reserve a port(?)");

        // Now, connect to that port
        //Thread.sleep(2000);
        System.err.println("(connecting to listening port on 127.0.0.1:" +
                           port + ")");
        DoS = new Socket("127.0.0.1", port);
        InputStream stream = DoS.getInputStream();

        // Read on the socket in the background
        boolean[] successful = new boolean[] { false };
        (new SomeReader(stream, successful)).start();

        // Wait for completion
        int nretries = 4;
        while (nretries-- > 0) {
            if (successful[0])
                break;
            Thread.sleep(DELAY);
        }

        if (successful[0]) {
            System.err.println("TEST PASSED.");
        } else {
            throw new Error("TEST FAILED.");
        }

    } finally {
        try {
            if (DoS != null)
                DoS.close();        // aborts the reader if still blocked
            impl.unexport();
        } catch (Throwable unmatter) {
        }
    }

    // Should exit here
}
 
Example 16
Source File: BlockAcceptTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
    throws Exception
{
    // Make trouble for ourselves
    if (System.getSecurityManager() == null)
        System.setSecurityManager(new RMISecurityManager());

    // HTTP direct to the server port
    System.setProperty("http.proxyHost", "127.0.0.1");

    // Set the socket factory.
    System.err.println("(installing HTTP-out socket factory)");
    HttpOutFactory fac = new HttpOutFactory();
    RMISocketFactory.setSocketFactory(fac);

    // Create remote object
    TestImpl impl = new TestImpl();

    // Export and get which port.
    System.err.println("(exporting remote object)");
    TestIface stub = impl.export();
    try {
        int port = fac.whichPort();

        // Sanity
        if (port == 0)
            throw new Error("TEST FAILED: export didn't reserve a port(?)");

        // Set the HTTP port, at last.
        System.setProperty("http.proxyPort", port+"");

        // Now, connect to that port
        //Thread.sleep(2000);
        System.err.println("(connecting to listening port on 127.0.0.1:" +
                           port + ")");
        Socket DoS = new Socket("127.0.0.1", port);
        // we hold the connection open until done with the test.

        // The test itself: make a remote call and see if it's blocked or
        // if it works
        //Thread.sleep(2000);
        System.err.println("(making RMI-through-HTTP call)");
        System.err.println("(typical test failure deadlocks here)");
        String result = stub.testCall("dummy load");

        System.err.println(" => " + result);
        if (!("OK".equals(result)))
            throw new Error("TEST FAILED: result not OK");
        System.err.println("Test passed.");

        // Clean up, including writing a byte to that connection just in
        // case an optimizer thought of optimizing it out of existence
        try {
            DoS.getOutputStream().write(0);
            DoS.getOutputStream().close();
        } catch (Throwable apathy) {
        }

    } finally {
        try {
            impl.unexport();
        } catch (Throwable unmatter) {
        }
    }

    // Should exit here
}
 
Example 17
Source File: BlockAcceptTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
    throws Exception
{
    // Make trouble for ourselves
    if (System.getSecurityManager() == null)
        System.setSecurityManager(new RMISecurityManager());

    // HTTP direct to the server port
    System.setProperty("http.proxyHost", "127.0.0.1");

    // Set the socket factory.
    System.err.println("(installing HTTP-out socket factory)");
    HttpOutFactory fac = new HttpOutFactory();
    RMISocketFactory.setSocketFactory(fac);

    // Create remote object
    TestImpl impl = new TestImpl();

    // Export and get which port.
    System.err.println("(exporting remote object)");
    TestIface stub = impl.export();
    try {
        int port = fac.whichPort();

        // Sanity
        if (port == 0)
            throw new Error("TEST FAILED: export didn't reserve a port(?)");

        // Set the HTTP port, at last.
        System.setProperty("http.proxyPort", port+"");

        // Now, connect to that port
        //Thread.sleep(2000);
        System.err.println("(connecting to listening port on 127.0.0.1:" +
                           port + ")");
        Socket DoS = new Socket("127.0.0.1", port);
        // we hold the connection open until done with the test.

        // The test itself: make a remote call and see if it's blocked or
        // if it works
        //Thread.sleep(2000);
        System.err.println("(making RMI-through-HTTP call)");
        System.err.println("(typical test failure deadlocks here)");
        String result = stub.testCall("dummy load");

        System.err.println(" => " + result);
        if (!("OK".equals(result)))
            throw new Error("TEST FAILED: result not OK");
        System.err.println("Test passed.");

        // Clean up, including writing a byte to that connection just in
        // case an optimizer thought of optimizing it out of existence
        try {
            DoS.getOutputStream().write(0);
            DoS.getOutputStream().close();
        } catch (Throwable apathy) {
        }

    } finally {
        try {
            impl.unexport();
        } catch (Throwable unmatter) {
        }
    }

    // Should exit here
}
 
Example 18
Source File: BlockAcceptTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
    throws Exception
{
    // Make trouble for ourselves
    if (System.getSecurityManager() == null)
        System.setSecurityManager(new RMISecurityManager());

    // HTTP direct to the server port
    System.setProperty("http.proxyHost", "127.0.0.1");

    // Set the socket factory.
    System.err.println("(installing HTTP-out socket factory)");
    HttpOutFactory fac = new HttpOutFactory();
    RMISocketFactory.setSocketFactory(fac);

    // Create remote object
    TestImpl impl = new TestImpl();

    // Export and get which port.
    System.err.println("(exporting remote object)");
    TestIface stub = impl.export();
    try {
        int port = fac.whichPort();

        // Sanity
        if (port == 0)
            throw new Error("TEST FAILED: export didn't reserve a port(?)");

        // Set the HTTP port, at last.
        System.setProperty("http.proxyPort", port+"");

        // Now, connect to that port
        //Thread.sleep(2000);
        System.err.println("(connecting to listening port on 127.0.0.1:" +
                           port + ")");
        Socket DoS = new Socket("127.0.0.1", port);
        // we hold the connection open until done with the test.

        // The test itself: make a remote call and see if it's blocked or
        // if it works
        //Thread.sleep(2000);
        System.err.println("(making RMI-through-HTTP call)");
        System.err.println("(typical test failure deadlocks here)");
        String result = stub.testCall("dummy load");

        System.err.println(" => " + result);
        if (!("OK".equals(result)))
            throw new Error("TEST FAILED: result not OK");
        System.err.println("Test passed.");

        // Clean up, including writing a byte to that connection just in
        // case an optimizer thought of optimizing it out of existence
        try {
            DoS.getOutputStream().write(0);
            DoS.getOutputStream().close();
        } catch (Throwable apathy) {
        }

    } finally {
        try {
            impl.unexport();
        } catch (Throwable unmatter) {
        }
    }

    // Should exit here
}
 
Example 19
Source File: ReadTimeoutTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
    throws Exception
{
    // Make trouble for ourselves
    if (System.getSecurityManager() == null)
        System.setSecurityManager(new RMISecurityManager());

    // Flaky code alert - hope this is executed before TCPTransport.<clinit>
    System.setProperty("sun.rmi.transport.tcp.readTimeout", Integer.toString(DELAY));

    // Set the socket factory.
    System.err.println("(installing socket factory)");
    SomeFactory fac = new SomeFactory();
    RMISocketFactory.setSocketFactory(fac);

    // Create remote object
    TestImpl impl = new TestImpl();

    // Export and get which port.
    System.err.println("(exporting remote object)");
    TestIface stub = impl.export();
    Socket DoS = null;
    try {
        int port = fac.whichPort();

        // Sanity
        if (port == 0)
            throw new Error("TEST FAILED: export didn't reserve a port(?)");

        // Now, connect to that port
        //Thread.sleep(2000);
        System.err.println("(connecting to listening port on 127.0.0.1:" +
                           port + ")");
        DoS = new Socket("127.0.0.1", port);
        InputStream stream = DoS.getInputStream();

        // Read on the socket in the background
        boolean[] successful = new boolean[] { false };
        (new SomeReader(stream, successful)).start();

        // Wait for completion
        int nretries = 4;
        while (nretries-- > 0) {
            if (successful[0])
                break;
            Thread.sleep(DELAY);
        }

        if (successful[0]) {
            System.err.println("TEST PASSED.");
        } else {
            throw new Error("TEST FAILED.");
        }

    } finally {
        try {
            if (DoS != null)
                DoS.close();        // aborts the reader if still blocked
            impl.unexport();
        } catch (Throwable unmatter) {
        }
    }

    // Should exit here
}
 
Example 20
Source File: BlockAcceptTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
    throws Exception
{
    // Make trouble for ourselves
    if (System.getSecurityManager() == null)
        System.setSecurityManager(new RMISecurityManager());

    // HTTP direct to the server port
    System.setProperty("http.proxyHost", "127.0.0.1");

    // Set the socket factory.
    System.err.println("(installing HTTP-out socket factory)");
    HttpOutFactory fac = new HttpOutFactory();
    RMISocketFactory.setSocketFactory(fac);

    // Create remote object
    TestImpl impl = new TestImpl();

    // Export and get which port.
    System.err.println("(exporting remote object)");
    TestIface stub = impl.export();
    try {
        int port = fac.whichPort();

        // Sanity
        if (port == 0)
            throw new Error("TEST FAILED: export didn't reserve a port(?)");

        // Set the HTTP port, at last.
        System.setProperty("http.proxyPort", port+"");

        // Now, connect to that port
        //Thread.sleep(2000);
        System.err.println("(connecting to listening port on 127.0.0.1:" +
                           port + ")");
        Socket DoS = new Socket("127.0.0.1", port);
        // we hold the connection open until done with the test.

        // The test itself: make a remote call and see if it's blocked or
        // if it works
        //Thread.sleep(2000);
        System.err.println("(making RMI-through-HTTP call)");
        System.err.println("(typical test failure deadlocks here)");
        String result = stub.testCall("dummy load");

        System.err.println(" => " + result);
        if (!("OK".equals(result)))
            throw new Error("TEST FAILED: result not OK");
        System.err.println("Test passed.");

        // Clean up, including writing a byte to that connection just in
        // case an optimizer thought of optimizing it out of existence
        try {
            DoS.getOutputStream().write(0);
            DoS.getOutputStream().close();
        } catch (Throwable apathy) {
        }

    } finally {
        try {
            impl.unexport();
        } catch (Throwable unmatter) {
        }
    }

    // Should exit here
}