Java Code Examples for java.rmi.server.RemoteObject

The following examples show how to use java.rmi.server.RemoteObject. These examples are extracted from open source projects. 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
private static void test(RemoteObject obj) throws Exception {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bout);
    out.writeObject(obj);
    ByteArrayInputStream bin =
        new ByteArrayInputStream(bout.toByteArray());
    ObjectInputStream in = new ObjectInputStream(bin);
    try {
        Object obj2 = in.readObject();
        System.err.println(
            "Object unexpectedly deserialized successfully: " + obj2);
        throw new RuntimeException(
            "TEST FAILED: object successfully deserialized");
    } catch (ClassNotFoundException e) {
        System.err.println("ClassNotFoundException as expected:");
        e.printStackTrace();
    } // other exceptions cause test failure
}
 
Example 2
private static void test(RemoteObject obj) throws Exception {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bout);
    out.writeObject(obj);
    ByteArrayInputStream bin =
        new ByteArrayInputStream(bout.toByteArray());
    ObjectInputStream in = new ObjectInputStream(bin);
    try {
        Object obj2 = in.readObject();
        System.err.println(
            "Object unexpectedly deserialized successfully: " + obj2);
        throw new RuntimeException(
            "TEST FAILED: object successfully deserialized");
    } catch (ClassNotFoundException e) {
        System.err.println("ClassNotFoundException as expected:");
        e.printStackTrace();
    } // other exceptions cause test failure
}
 
Example 3
private static RMIConnection getConnection(RMIServer server,
        Object credentials,
        boolean checkStub)
        throws IOException {
    RMIConnection c = server.newClient(credentials);
    if (checkStub) checkStub(c, rmiConnectionImplStubClass);
    try {
        if (c.getClass() == rmiConnectionImplStubClass)
            return shadowJrmpStub((RemoteObject) c);
        if (c.getClass().getName().equals(iiopConnectionStubClassName))
            return shadowIiopStub(c);
        logger.trace("getConnection",
                "Did not wrap " + c.getClass() + " to foil " +
                "stack search for classes: class loading semantics " +
                "may be incorrect");
    } catch (Exception e) {
        logger.error("getConnection",
                "Could not wrap " + c.getClass() + " to foil " +
                "stack search for classes: class loading semantics " +
                "may be incorrect: " + e);
        logger.debug("getConnection",e);
        // so just return the original stub, which will work for all
        // but the most exotic class loading situations
    }
    return c;
}
 
Example 4
Source Project: TencentKona-8   Source File: RMIConnector.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static RMIConnection getConnection(RMIServer server,
        Object credentials,
        boolean checkStub)
        throws IOException {
    RMIConnection c = server.newClient(credentials);
    if (checkStub) checkStub(c, rmiConnectionImplStubClass);
    try {
        if (c.getClass() == rmiConnectionImplStubClass)
            return shadowJrmpStub((RemoteObject) c);
        if (c.getClass().getName().equals(iiopConnectionStubClassName))
            return shadowIiopStub(c);
        logger.trace("getConnection",
                "Did not wrap " + c.getClass() + " to foil " +
                "stack search for classes: class loading semantics " +
                "may be incorrect");
    } catch (Exception e) {
        logger.error("getConnection",
                "Could not wrap " + c.getClass() + " to foil " +
                "stack search for classes: class loading semantics " +
                "may be incorrect: " + e);
        logger.debug("getConnection",e);
        // so just return the original stub, which will work for all
        // but the most exotic class loading situations
    }
    return c;
}
 
Example 5
private static void test(RemoteObject obj) throws Exception {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bout);
    out.writeObject(obj);
    ByteArrayInputStream bin =
        new ByteArrayInputStream(bout.toByteArray());
    ObjectInputStream in = new ObjectInputStream(bin);
    try {
        Object obj2 = in.readObject();
        System.err.println(
            "Object unexpectedly deserialized successfully: " + obj2);
        throw new RuntimeException(
            "TEST FAILED: object successfully deserialized");
    } catch (ClassNotFoundException e) {
        System.err.println("ClassNotFoundException as expected:");
        e.printStackTrace();
    } // other exceptions cause test failure
}
 
Example 6
private static void test(RemoteObject obj) throws Exception {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bout);
    out.writeObject(obj);
    ByteArrayInputStream bin =
        new ByteArrayInputStream(bout.toByteArray());
    ObjectInputStream in = new ObjectInputStream(bin);
    try {
        Object obj2 = in.readObject();
        System.err.println(
            "Object unexpectedly deserialized successfully: " + obj2);
        throw new RuntimeException(
            "TEST FAILED: object successfully deserialized");
    } catch (ClassNotFoundException e) {
        System.err.println("ClassNotFoundException as expected:");
        e.printStackTrace();
    } // other exceptions cause test failure
}
 
Example 7
Source Project: openjdk-8   Source File: RMIConnector.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static RMIConnection getConnection(RMIServer server,
        Object credentials,
        boolean checkStub)
        throws IOException {
    RMIConnection c = server.newClient(credentials);
    if (checkStub) checkStub(c, rmiConnectionImplStubClass);
    try {
        if (c.getClass() == rmiConnectionImplStubClass)
            return shadowJrmpStub((RemoteObject) c);
        if (c.getClass().getName().equals(iiopConnectionStubClassName))
            return shadowIiopStub(c);
        logger.trace("getConnection",
                "Did not wrap " + c.getClass() + " to foil " +
                "stack search for classes: class loading semantics " +
                "may be incorrect");
    } catch (Exception e) {
        logger.error("getConnection",
                "Could not wrap " + c.getClass() + " to foil " +
                "stack search for classes: class loading semantics " +
                "may be incorrect: " + e);
        logger.debug("getConnection",e);
        // so just return the original stub, which will work for all
        // but the most exotic class loading situations
    }
    return c;
}
 
Example 8
Source Project: jdk8u_jdk   Source File: RMIConnector.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static RMIConnection getConnection(RMIServer server,
        Object credentials,
        boolean checkStub)
        throws IOException {
    RMIConnection c = server.newClient(credentials);
    if (checkStub) checkStub(c, rmiConnectionImplStubClass);
    try {
        if (c.getClass() == rmiConnectionImplStubClass)
            return shadowJrmpStub((RemoteObject) c);
        if (c.getClass().getName().equals(iiopConnectionStubClassName))
            return shadowIiopStub(c);
        logger.trace("getConnection",
                "Did not wrap " + c.getClass() + " to foil " +
                "stack search for classes: class loading semantics " +
                "may be incorrect");
    } catch (Exception e) {
        logger.error("getConnection",
                "Could not wrap " + c.getClass() + " to foil " +
                "stack search for classes: class loading semantics " +
                "may be incorrect: " + e);
        logger.debug("getConnection",e);
        // so just return the original stub, which will work for all
        // but the most exotic class loading situations
    }
    return c;
}
 
Example 9
Source Project: hottub   Source File: RMIConnector.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static RMIConnection getConnection(RMIServer server,
        Object credentials,
        boolean checkStub)
        throws IOException {
    RMIConnection c = server.newClient(credentials);
    if (checkStub) checkStub(c, rmiConnectionImplStubClass);
    try {
        if (c.getClass() == rmiConnectionImplStubClass)
            return shadowJrmpStub((RemoteObject) c);
        if (c.getClass().getName().equals(iiopConnectionStubClassName))
            return shadowIiopStub(c);
        logger.trace("getConnection",
                "Did not wrap " + c.getClass() + " to foil " +
                "stack search for classes: class loading semantics " +
                "may be incorrect");
    } catch (Exception e) {
        logger.error("getConnection",
                "Could not wrap " + c.getClass() + " to foil " +
                "stack search for classes: class loading semantics " +
                "may be incorrect: " + e);
        logger.debug("getConnection",e);
        // so just return the original stub, which will work for all
        // but the most exotic class loading situations
    }
    return c;
}
 
Example 10
private static void test(RemoteObject obj) throws Exception {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bout);
    out.writeObject(obj);
    ByteArrayInputStream bin =
        new ByteArrayInputStream(bout.toByteArray());
    ObjectInputStream in = new ObjectInputStream(bin);
    try {
        Object obj2 = in.readObject();
        System.err.println(
            "Object unexpectedly deserialized successfully: " + obj2);
        throw new RuntimeException(
            "TEST FAILED: object successfully deserialized");
    } catch (ClassNotFoundException e) {
        System.err.println("ClassNotFoundException as expected:");
        e.printStackTrace();
    } // other exceptions cause test failure
}
 
Example 11
Source Project: openjdk-jdk9   Source File: ActivatableRef.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * This call is used by the old 1.1 stub protocol and is
 * unsupported since activation requires 1.2 stubs.
 */
public synchronized RemoteCall newCall(RemoteObject obj,
                                       Operation[] ops,
                                       int opnum,
                                       long hash)
    throws RemoteException
{
    throw new UnsupportedOperationException(versionComplaint);
}
 
Example 12
Source Project: jdk1.8-source-analysis   Source File: ProxyRef.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated
 */
@Deprecated
public java.rmi.server.RemoteCall newCall(RemoteObject obj,
        java.rmi.server.Operation[] op, int opnum,
                          long hash) throws RemoteException {
    return ref.newCall(obj, op, opnum, hash);
}
 
Example 13
Source Project: jdk8u-jdk   Source File: RMIConnector.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static RMIConnection shadowJrmpStub(RemoteObject stub)
throws InstantiationException, IllegalAccessException,
        InvocationTargetException, ClassNotFoundException,
        NoSuchMethodException {
    RemoteRef ref = stub.getRef();
    RemoteRef proxyRef = (RemoteRef)
        proxyRefConstructor.newInstance(new Object[] {ref});
    final Constructor<?> rmiConnectionImplStubConstructor =
        rmiConnectionImplStubClass.getConstructor(RemoteRef.class);
    Object[] args = {proxyRef};
    RMIConnection proxyStub = (RMIConnection)
    rmiConnectionImplStubConstructor.newInstance(args);
    return proxyStub;
}
 
Example 14
Source Project: openjdk-8   Source File: RMIConnector.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static RMIConnection shadowJrmpStub(RemoteObject stub)
throws InstantiationException, IllegalAccessException,
        InvocationTargetException, ClassNotFoundException,
        NoSuchMethodException {
    RemoteRef ref = stub.getRef();
    RemoteRef proxyRef = (RemoteRef)
        proxyRefConstructor.newInstance(new Object[] {ref});
    final Constructor<?> rmiConnectionImplStubConstructor =
        rmiConnectionImplStubClass.getConstructor(RemoteRef.class);
    Object[] args = {proxyRef};
    RMIConnection proxyStub = (RMIConnection)
    rmiConnectionImplStubConstructor.newInstance(args);
    return proxyStub;
}
 
Example 15
/**
 * This call is used by the old 1.1 stub protocol and is
 * unsupported since activation requires 1.2 stubs.
 */
public synchronized RemoteCall newCall(RemoteObject obj,
                                       Operation[] ops,
                                       int opnum,
                                       long hash)
    throws RemoteException
{
    throw new UnsupportedOperationException(versionComplaint);
}
 
Example 16
Source Project: jdk8u-jdk   Source File: NotSerializable.java    License: GNU General Public License v2.0 5 votes vote down vote up
public RemoteCall newCall(RemoteObject obj,
                          Operation[] op,
                          int opnum,
                          long hash)
{
    throw new UnsupportedOperationException();
}
 
Example 17
Source Project: hottub   Source File: BenchServerImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Uses the given remote object factory to create a new remote object on
 * the server side.
 */
public Remote create(BenchServer.RemoteObjectFactory factory)
    throws RemoteException
{
    Remote impl = factory.create();
    implTable.put(RemoteObject.toStub(impl), new WeakReference(impl));
    return impl;
}
 
Example 18
Source Project: dragonwell8_jdk   Source File: RMIConnector.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static RMIConnection shadowJrmpStub(RemoteObject stub)
throws InstantiationException, IllegalAccessException,
        InvocationTargetException, ClassNotFoundException,
        NoSuchMethodException {
    RemoteRef ref = stub.getRef();
    RemoteRef proxyRef = (RemoteRef)
        proxyRefConstructor.newInstance(new Object[] {ref});
    final Constructor<?> rmiConnectionImplStubConstructor =
        rmiConnectionImplStubClass.getConstructor(RemoteRef.class);
    Object[] args = {proxyRef};
    RMIConnection proxyStub = (RMIConnection)
    rmiConnectionImplStubConstructor.newInstance(args);
    return proxyStub;
}
 
Example 19
Source Project: hottub   Source File: EmptyName.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Registry impl = TestLibrary.createRegistryOnUnusedPort();
    Registry stub = (Registry) RemoteObject.toStub(impl);
    stub.bind("", stub);
    stub.lookup("");
    stub.rebind("", stub);
    stub.lookup("");
    stub.unbind("");
}
 
Example 20
Source Project: jdk8u-dev-jdk   Source File: RMIConnector.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void checkStub(Remote stub,
        Class<?> stubClass) {

    // Check remote stub is from the expected class.
    //
    if (stub.getClass() != stubClass) {
        if (!Proxy.isProxyClass(stub.getClass())) {
            throw new SecurityException(
                    "Expecting a " + stubClass.getName() + " stub!");
        } else {
            InvocationHandler handler = Proxy.getInvocationHandler(stub);
            if (handler.getClass() != RemoteObjectInvocationHandler.class)
                throw new SecurityException(
                        "Expecting a dynamic proxy instance with a " +
                        RemoteObjectInvocationHandler.class.getName() +
                        " invocation handler!");
            else
                stub = (Remote) handler;
        }
    }

    // Check RemoteRef in stub is from the expected class
    // "sun.rmi.server.UnicastRef2".
    //
    RemoteRef ref = ((RemoteObject)stub).getRef();
    if (ref.getClass() != UnicastRef2.class)
        throw new SecurityException(
                "Expecting a " + UnicastRef2.class.getName() +
                " remote reference in stub!");

    // Check RMIClientSocketFactory in stub is from the expected class
    // "javax.rmi.ssl.SslRMIClientSocketFactory".
    //
    LiveRef liveRef = ((UnicastRef2)ref).getLiveRef();
    RMIClientSocketFactory csf = liveRef.getClientSocketFactory();
    if (csf == null || csf.getClass() != SslRMIClientSocketFactory.class)
        throw new SecurityException(
                "Expecting a " + SslRMIClientSocketFactory.class.getName() +
                " RMI client socket factory in stub!");
}
 
Example 21
/**
 * Uses the given remote object factory to create a new remote object on
 * the server side.
 */
public Remote create(BenchServer.RemoteObjectFactory factory)
    throws RemoteException
{
    Remote impl = factory.create();
    implTable.put(RemoteObject.toStub(impl), new WeakReference(impl));
    return impl;
}
 
Example 22
public static void main(String[] args) throws Exception {

        InetAddress localAddress = InetAddress.getLocalHost();
        String[] hostlist = new String[] {
            localAddress.getHostAddress(), localAddress.getHostName() };

        for (int i = 0; i < hostlist.length; i++) {

            System.setProperty("java.rmi.server.hostname", hostlist[i]);
            Remote impl = new ChangeHostName();
            System.err.println("\ncreated impl extending URO: " + impl);

            Receiver stub = (Receiver) RemoteObject.toStub(impl);
            System.err.println("stub for impl: " + stub);

            System.err.println("invoking method on stub");
            stub.receive(stub);

            UnicastRemoteObject.unexportObject(impl, true);
            System.err.println("unexported impl");

            if (stub.toString().indexOf(hostlist[i]) >= 0) {
                System.err.println("stub's ref contains hostname: " +
                                   hostlist[i]);
            } else {
                throw new RuntimeException(
                    "TEST FAILED: stub's ref doesn't contain hostname: " +
                    hostlist[i]);
            }
        }
        System.err.println("TEST PASSED");
    }
 
Example 23
public static void main(String[] args) throws Exception {
    Remote impl2 = null;
    try {
        Remote impl = new MarshalAfterUnexport();
        System.err.println("created impl extending URO: " + impl);

        Receiver stub = (Receiver) RemoteObject.toStub(impl);
        System.err.println("stub for impl: " + stub);

        UnicastRemoteObject.unexportObject(impl, true);
        System.err.println("unexported impl");

        impl2 = new MarshalAfterUnexport();
        Receiver stub2 = (Receiver) RemoteObject.toStub(impl2);

        System.err.println("marshalling unexported object:");
        MarshalledObject mobj = new MarshalledObject(impl);

        System.err.println("passing unexported object via RMI-JRMP:");
        stub2.receive(stub);

        System.err.println("TEST PASSED");
    } finally {
        if (impl2 != null) {
            try {
                UnicastRemoteObject.unexportObject(impl2, true);
            } catch (Throwable t) {
            }
        }
    }
}
 
Example 24
Source Project: jdk8u-jdk   Source File: Test.java    License: GNU General Public License v2.0 5 votes vote down vote up
public RemoteCall newCall(RemoteObject obj,
                          Operation[] op,
                          int opnum,
                          long hash)
{
    throw new AssertionError();
}
 
Example 25
public static void main(String[] args) throws Exception {
    Remote impl2 = null;
    try {
        Remote impl = new MarshalAfterUnexport();
        System.err.println("created impl extending URO: " + impl);

        Receiver stub = (Receiver) RemoteObject.toStub(impl);
        System.err.println("stub for impl: " + stub);

        UnicastRemoteObject.unexportObject(impl, true);
        System.err.println("unexported impl");

        impl2 = new MarshalAfterUnexport();
        Receiver stub2 = (Receiver) RemoteObject.toStub(impl2);

        System.err.println("marshalling unexported object:");
        MarshalledObject mobj = new MarshalledObject(impl);

        System.err.println("passing unexported object via RMI-JRMP:");
        stub2.receive(stub);

        System.err.println("TEST PASSED");
    } finally {
        if (impl2 != null) {
            try {
                UnicastRemoteObject.unexportObject(impl2, true);
            } catch (Throwable t) {
            }
        }
    }
}
 
Example 26
/**
 * Uses the given remote object factory to create a new remote object on
 * the server side.
 */
public Remote create(BenchServer.RemoteObjectFactory factory)
    throws RemoteException
{
    Remote impl = factory.create();
    implTable.put(RemoteObject.toStub(impl), new WeakReference(impl));
    return impl;
}
 
Example 27
Source Project: hottub   Source File: MarshalAfterUnexport2.java    License: 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 4513223\n");

        Remote impl2 = null;
        try {
            Remote impl = new MarshalAfterUnexport2();
            System.err.println(
                "created impl extending URO (with a UnicastServerRef2): " +
                impl);

            Receiver stub = (Receiver) RemoteObject.toStub(impl);
            System.err.println("stub for impl: " + stub);

            UnicastRemoteObject.unexportObject(impl, true);
            System.err.println("unexported impl");

            impl2 = new MarshalAfterUnexport2();
            Receiver stub2 = (Receiver) RemoteObject.toStub(impl2);

            System.err.println("marshalling unexported object:");
            MarshalledObject mobj = new MarshalledObject(impl);

            System.err.println("passing unexported object via RMI-JRMP:");
            stub2.receive(stub);

            System.err.println("TEST PASSED");
        } finally {
            if (impl2 != null) {
                try {
                    UnicastRemoteObject.unexportObject(impl2, true);
                } catch (Throwable t) {
                }
            }
        }
    }
 
Example 28
Source Project: jdk8u-jdk   Source File: BenchServerImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Uses the given remote object factory to create a new remote object on
 * the server side.
 */
public Remote create(BenchServer.RemoteObjectFactory factory)
    throws RemoteException
{
    Remote impl = factory.create();
    implTable.put(RemoteObject.toStub(impl), new WeakReference(impl));
    return impl;
}
 
Example 29
Source Project: marshalsec   Source File: RMIRefServer.java    License: MIT License 5 votes vote down vote up
/**
 * @param ois
 * @param out
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws NamingException
 */
private boolean handleRMI ( ObjectInputStream ois, DataOutputStream out ) throws Exception {
    int method = ois.readInt(); // method
    ois.readLong(); // hash

    if ( method != 2 ) { // lookup
        return false;
    }

    String object = (String) ois.readObject();
    System.err.println("Is RMI.lookup call for " + object + " " + method);

    out.writeByte(TransportConstants.Return);// transport op
    try ( ObjectOutputStream oos = new MarshalOutputStream(out, this.classpathUrl) ) {

        oos.writeByte(TransportConstants.NormalReturn);
        new UID().write(oos);

        System.err.println(
            String.format(
                "Sending remote classloading stub targeting %s",
                new URL(this.classpathUrl, this.classpathUrl.getRef().replace('.', '/').concat(".class"))));

        ReferenceWrapper rw = Reflections.createWithoutConstructor(ReferenceWrapper.class);
        Reflections.setFieldValue(rw, "wrappee", new Reference("Foo", this.classpathUrl.getRef(), this.classpathUrl.toString()));
        Field refF = RemoteObject.class.getDeclaredField("ref");
        refF.setAccessible(true);
        refF.set(rw, new UnicastServerRef(12345));

        oos.writeObject(rw);

        oos.flush();
        out.flush();
    }
    return true;
}
 
Example 30
Source Project: openjdk-jdk9   Source File: ChangeHostName.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        InetAddress localAddress = InetAddress.getLocalHost();
        String[] hostlist = new String[] {
            localAddress.getHostAddress(), localAddress.getHostName() };

        for (int i = 0; i < hostlist.length; i++) {

            System.setProperty("java.rmi.server.hostname", hostlist[i]);
            Remote impl = new ChangeHostName();
            System.err.println("\ncreated impl extending URO: " + impl);

            Receiver stub = (Receiver) RemoteObject.toStub(impl);
            System.err.println("stub for impl: " + stub);

            System.err.println("invoking method on stub");
            stub.receive(stub);

            UnicastRemoteObject.unexportObject(impl, true);
            System.err.println("unexported impl");

            if (stub.toString().indexOf(hostlist[i]) >= 0) {
                System.err.println("stub's ref contains hostname: " +
                                   hostlist[i]);
            } else {
                throw new RuntimeException(
                    "TEST FAILED: stub's ref doesn't contain hostname: " +
                    hostlist[i]);
            }
        }
        System.err.println("TEST PASSED");
    }