java.rmi.server.RemoteObject Java Examples

The following examples show how to use java.rmi.server.RemoteObject. 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: UnrecognizedRefType.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: UnrecognizedRefType.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: UnrecognizedRefType.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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 #4
Source File: UnrecognizedRefType.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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 #5
Source File: UnrecognizedRefType.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: RMIConnector.java    From hottub with 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 #7
Source File: RMIConnector.java    From openjdk-8-source with 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 File: RMIConnector.java    From jdk8u_jdk with 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 File: RMIConnector.java    From TencentKona-8 with 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
Source File: RMIConnector.java    From openjdk-8 with 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 #11
Source File: ChangeHostName.java    From openjdk-jdk8u with 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");
    }
 
Example #12
Source File: EmptyName.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Registry impl = TestLibrary.createRegistryOnEphemeralPort();
    Registry stub = (Registry) RemoteObject.toStub(impl);
    stub.bind("", stub);
    stub.lookup("");
    stub.rebind("", stub);
    stub.lookup("");
    stub.unbind("");
}
 
Example #13
Source File: ActivatableRef.java    From jdk8u_jdk with 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 #14
Source File: JRMPListener.java    From ysoserial with MIT License 5 votes vote down vote up
public UnicastRemoteObject getObject ( final String command ) throws Exception {
    int jrmpPort = Integer.parseInt(command);
    UnicastRemoteObject uro = Reflections.createWithConstructor(ActivationGroupImpl.class, RemoteObject.class, new Class[] {
        RemoteRef.class
    }, new Object[] {
        new UnicastServerRef(jrmpPort)
    });

    Reflections.getField(UnicastRemoteObject.class, "port").set(uro, jrmpPort);
    return uro;
}
 
Example #15
Source File: MarshalAfterUnexport.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 #16
Source File: RMIConnector.java    From jdk8u-jdk with 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 #17
Source File: Test.java    From openjdk-jdk8u with 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 #18
Source File: NotSerializable.java    From openjdk-8-source with 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 #19
Source File: ChangeHostName.java    From openjdk-8-source with 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");
    }
 
Example #20
Source File: UnrecognizedRefType.java    From jdk8u60 with 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 #21
Source File: ActivatableRef.java    From openjdk-jdk9 with 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 #22
Source File: RMIConnector.java    From openjdk-jdk8u-backup with 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 #23
Source File: MarshalAfterUnexport.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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 File: ChangeHostName.java    From jdk8u60 with 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");
    }
 
Example #25
Source File: Test.java    From hottub with 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 #26
Source File: RMIConnector.java    From jdk8u-dev-jdk with 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 #27
Source File: RMIConnector.java    From jdk8u60 with 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 #28
Source File: ActivatableRef.java    From openjdk-8 with 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 #29
Source File: ActivatableRef.java    From jdk8u60 with 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 #30
Source File: ChangeHostName.java    From hottub with 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");
    }