Search in sources :

Example 1 with RemoteObject

use of java.rmi.server.RemoteObject in project jdk8u_jdk by JetBrains.

the class UnrecognizedRefType method test.

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
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RemoteObject(java.rmi.server.RemoteObject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with RemoteObject

use of java.rmi.server.RemoteObject in project jmeter by apache.

the class ClientJMeterEngine method getEngine.

private static RemoteJMeterEngine getEngine(String h) throws MalformedURLException, RemoteException, NotBoundException {
    // $NON-NLS-1$ $NON-NLS-2$
    final String name = "//" + h + "/" + RemoteJMeterEngineImpl.JMETER_ENGINE_RMI_NAME;
    Remote remobj = Naming.lookup(name);
    if (remobj instanceof RemoteJMeterEngine) {
        final RemoteJMeterEngine rje = (RemoteJMeterEngine) remobj;
        if (remobj instanceof RemoteObject) {
            RemoteObject robj = (RemoteObject) remobj;
            System.out.println("Using remote object: " + robj.getRef().remoteToString());
        }
        return rje;
    }
    throw new RemoteException("Could not find " + name);
}
Also used : RemoteObject(java.rmi.server.RemoteObject) Remote(java.rmi.Remote) RemoteException(java.rmi.RemoteException)

Example 3 with RemoteObject

use of java.rmi.server.RemoteObject in project jdk8u_jdk by JetBrains.

the class RMIConnector method checkStub.

//--------------------------------------------------------------------
// Private stuff - Check if stub can be trusted.
//--------------------------------------------------------------------
private static void checkStub(Remote stub, Class<?> stubClass) {
    //
    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!");
}
Also used : SslRMIClientSocketFactory(javax.rmi.ssl.SslRMIClientSocketFactory) RemoteObject(java.rmi.server.RemoteObject) LiveRef(sun.rmi.transport.LiveRef) RemoteRef(java.rmi.server.RemoteRef) Remote(java.rmi.Remote) UnicastRef2(sun.rmi.server.UnicastRef2) RemoteObjectInvocationHandler(java.rmi.server.RemoteObjectInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler) SslRMIClientSocketFactory(javax.rmi.ssl.SslRMIClientSocketFactory) RMIClientSocketFactory(java.rmi.server.RMIClientSocketFactory)

Example 4 with RemoteObject

use of java.rmi.server.RemoteObject in project jdk8u_jdk by JetBrains.

the class ActivationID method writeObject.

/**
     * <code>writeObject</code> for custom serialization.
     *
     * <p>This method writes this object's serialized form for
     * this class as follows:
     *
     * <p>The <code>writeObject</code> method is invoked on
     * <code>out</code> passing this object's unique identifier
     * (a {@link java.rmi.server.UID UID} instance) as the argument.
     *
     * <p>Next, the {@link
     * java.rmi.server.RemoteRef#getRefClass(java.io.ObjectOutput)
     * getRefClass} method is invoked on the activator's
     * <code>RemoteRef</code> instance to obtain its external ref
     * type name.  Next, the <code>writeUTF</code> method is
     * invoked on <code>out</code> with the value returned by
     * <code>getRefClass</code>, and then the
     * <code>writeExternal</code> method is invoked on the
     * <code>RemoteRef</code> instance passing <code>out</code>
     * as the argument.
     *
     * @serialData The serialized data for this class comprises a
     * <code>java.rmi.server.UID</code> (written with
     * <code>ObjectOutput.writeObject</code>) followed by the
     * external ref type name of the activator's
     * <code>RemoteRef</code> instance (a string written with
     * <code>ObjectOutput.writeUTF</code>), followed by the
     * external form of the <code>RemoteRef</code> instance as
     * written by its <code>writeExternal</code> method.
     *
     * <p>The external ref type name of the
     * <code>RemoteRef</Code> instance is
     * determined using the definitions of external ref type
     * names specified in the {@link java.rmi.server.RemoteObject
     * RemoteObject} <code>writeObject</code> method
     * <b>serialData</b> specification.  Similarly, the data
     * written by the <code>writeExternal</code> method and read
     * by the <code>readExternal</code> method of
     * <code>RemoteRef</code> implementation classes
     * corresponding to each of the defined external ref type
     * names is specified in the {@link
     * java.rmi.server.RemoteObject RemoteObject}
     * <code>writeObject</code> method <b>serialData</b>
     * specification.
     **/
private void writeObject(ObjectOutputStream out) throws IOException, ClassNotFoundException {
    out.writeObject(uid);
    RemoteRef ref;
    if (activator instanceof RemoteObject) {
        ref = ((RemoteObject) activator).getRef();
    } else if (Proxy.isProxyClass(activator.getClass())) {
        InvocationHandler handler = Proxy.getInvocationHandler(activator);
        if (!(handler instanceof RemoteObjectInvocationHandler)) {
            throw new InvalidObjectException("unexpected invocation handler");
        }
        ref = ((RemoteObjectInvocationHandler) handler).getRef();
    } else {
        throw new InvalidObjectException("unexpected activator type");
    }
    out.writeUTF(ref.getRefClass(out));
    ref.writeExternal(out);
}
Also used : RemoteObject(java.rmi.server.RemoteObject) RemoteObjectInvocationHandler(java.rmi.server.RemoteObjectInvocationHandler) RemoteRef(java.rmi.server.RemoteRef) InvalidObjectException(java.io.InvalidObjectException) RemoteObjectInvocationHandler(java.rmi.server.RemoteObjectInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler)

Example 5 with RemoteObject

use of java.rmi.server.RemoteObject in project jdk8u_jdk by JetBrains.

the class RMIConnector method shadowJrmpStub.

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;
}
Also used : RemoteRef(java.rmi.server.RemoteRef) MarshalledObject(java.rmi.MarshalledObject) RemoteObject(java.rmi.server.RemoteObject)

Aggregations

RemoteObject (java.rmi.server.RemoteObject)7 RemoteRef (java.rmi.server.RemoteRef)4 Remote (java.rmi.Remote)3 InvocationHandler (java.lang.reflect.InvocationHandler)2 RMIClientSocketFactory (java.rmi.server.RMIClientSocketFactory)2 RemoteObjectInvocationHandler (java.rmi.server.RemoteObjectInvocationHandler)2 SslRMIClientSocketFactory (javax.rmi.ssl.SslRMIClientSocketFactory)2 LiveRef (sun.rmi.transport.LiveRef)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InvalidObjectException (java.io.InvalidObjectException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Constructor (java.lang.reflect.Constructor)1 Method (java.lang.reflect.Method)1 MarshalledObject (java.rmi.MarshalledObject)1 RemoteException (java.rmi.RemoteException)1 LocateRegistry (java.rmi.registry.LocateRegistry)1 Registry (java.rmi.registry.Registry)1