当前位置: 首页>>代码示例>>Java>>正文


Java RemoteObjectInvocationHandler类代码示例

本文整理汇总了Java中java.rmi.server.RemoteObjectInvocationHandler的典型用法代码示例。如果您正苦于以下问题:Java RemoteObjectInvocationHandler类的具体用法?Java RemoteObjectInvocationHandler怎么用?Java RemoteObjectInvocationHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RemoteObjectInvocationHandler类属于java.rmi.server包,在下文中一共展示了RemoteObjectInvocationHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getObject

import java.rmi.server.RemoteObjectInvocationHandler; //导入依赖的package包/类
public Registry getObject ( final String command ) throws Exception {

        String host;
        int port;
        int sep = command.indexOf(':');
        if ( sep < 0 ) {
            port = new Random().nextInt(65535);
            host = command;
        }
        else {
            host = command.substring(0, sep);
            port = Integer.valueOf(command.substring(sep + 1));
        }
        ObjID id = new ObjID(new Random().nextInt()); // RMI registry
        TCPEndpoint te = new TCPEndpoint(host, port);
        UnicastRef ref = new UnicastRef(new LiveRef(id, te, false));
        RemoteObjectInvocationHandler obj = new RemoteObjectInvocationHandler(ref);
        Registry proxy = (Registry) Proxy.newProxyInstance(JRMPClient.class.getClassLoader(), new Class[] {
            Registry.class
        }, obj);
        return proxy;
    }
 
开发者ID:hucheat,项目名称:APacheSynapseSimplePOC,代码行数:23,代码来源:JRMPClient.java

示例2: getObject

import java.rmi.server.RemoteObjectInvocationHandler; //导入依赖的package包/类
public Registry getObject ( String connection ) throws Exception {

        String host;
        int port;
        int sep = connection.indexOf(':');
        if ( sep < 0 ) {
            port = new Random().nextInt(65535);
            host = connection;
        }
        else {
            host = connection.substring(0, sep);
            port = Integer.valueOf(connection.substring(sep + 1));
        }
        ObjID id = new ObjID(new Random().nextInt()); // RMI registry
        TCPEndpoint te = new TCPEndpoint(host, port);
        UnicastRef ref = new UnicastRef(new LiveRef(id, te, false));
        RemoteObjectInvocationHandler obj = new RemoteObjectInvocationHandler(ref);
        Registry proxy = (Registry) Proxy.newProxyInstance(JRMPClient.class.getClassLoader(), new Class[] {
            Registry.class
        }, obj);
        return proxy;
    }
 
开发者ID:pimps,项目名称:ysoserial-modified,代码行数:23,代码来源:JRMPClient.java

示例3: replaceObject

import java.rmi.server.RemoteObjectInvocationHandler; //导入依赖的package包/类
/**
 * Returns a stub if the object to be serialized is a
 * {@link java.rmi.Remote} instance.
 * 
 * @param obj
 *            the object to be replaced if needed be.
 * @return if the argument was a {@link java.rmi.Remote} object locally
 *         exported a stub for that object is returned, in case it is not a
 *         {@link java.rmi.Remote} the object is returned
 * @throws IOException
 *             if the I/O operation fails
 */
@Override
protected final Object replaceObject(Object obj) throws IOException {

    if (obj instanceof Remote) {
        RemoteReferenceManager rrm = RemoteReferenceManager
                .getRemoteReferenceManager();
        if (rrm.isExported((Remote) obj)) {
            writesRemote = true;
            return RemoteObject.toStub((Remote) obj);
        }
        if (obj instanceof RemoteStub) {
            writesRemote = true;
            return obj;
        }
        if (Proxy.isProxyClass(obj.getClass())) {
            InvocationHandler ih = Proxy.getInvocationHandler(obj);
            if (ih instanceof RemoteObjectInvocationHandler) {
                writesRemote = true;
            }
        }
    }
    return obj;
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:36,代码来源:RMIObjectOutputStream.java

示例4: testInvoke004

import java.rmi.server.RemoteObjectInvocationHandler; //导入依赖的package包/类
public final void testInvoke004() throws RemoteException {
    EchoUnicast_Imp eui = new EchoUnicast_Imp() {
        public String echo(String msg) throws RemoteException {
            return msg;
        }
    };
    RemoteRef ref = eui.getRef();
    Echo proxy = (Echo) RemoteObject.toStub(eui);
    String toSend = "hola invoquer";
    try {
        r = new RemoteObjectInvocationHandler(ref);
        assertEquals("The result is what we expect", toSend, r.invoke(
                proxy, Echo.class.getMethods()[0], new Object[] { toSend }));
    } catch (Throwable e) {
        fail("Failed with:" + e);
    }
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:18,代码来源:TestRemoteObjectInvocationHandler.java

示例5: testInvoke006

import java.rmi.server.RemoteObjectInvocationHandler; //导入依赖的package包/类
public final void testInvoke006() throws RemoteException {
    Echo_Imp eui = new Echo_Imp() {
        public String echo(String msg) throws RemoteException {
            return msg;
        }
    };
    Remote proxy = UnicastRemoteObject.exportObject(eui, 1100);
    String toSend = "hola invoquer";
    r = (RemoteObjectInvocationHandler) Proxy.getInvocationHandler(proxy);
    try {
        assertEquals("The result is what we expect", toSend, r.invoke(
                proxy, Echo.class.getMethods()[0], new Object[] { toSend }));
    } catch (Throwable e) {
        fail("Failed with:" + e);
    }
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:17,代码来源:TestRemoteObjectInvocationHandler.java

示例6: testInvoke008

import java.rmi.server.RemoteObjectInvocationHandler; //导入依赖的package包/类
public final void testInvoke008() throws RemoteException {
    EchoUnicast_Imp eui = new EchoUnicast_Imp() {
        public String echo(String msg) throws RemoteException {
            return msg;
        }
    };
    RemoteRef ref = eui.getRef();
    Echo proxy = (Echo) RemoteObject.toStub(eui);
    String toSend = "hola invoquer";
    try {
        r = new RemoteObjectInvocationHandler(ref);
        assertEquals("The result is what we expected", toSend, r.invoke(
                proxy, Echo.class.getMethods()[0], new Object[] { toSend,
                        toSend }));
    } catch (Throwable e) {
        fail("Failed with:" + e);
    }
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:19,代码来源:TestRemoteObjectInvocationHandler.java

示例7: testInvoke011

import java.rmi.server.RemoteObjectInvocationHandler; //导入依赖的package包/类
public final void testInvoke011() throws RemoteException {
    BigEcho_imp bei = new BigEcho_imp() {
        public void echo() throws RemoteException {
            throw new RemoteException("Always pass throw here");
        }

        public void echo(Object... objs) throws RemoteException {
            if (objs == null) {
                throw new RemoteException("Objs Null");
            }
        }
    };
    RemoteRef ref = bei.getRef();
    BigEcho proxy = (BigEcho) RemoteObject.toStub(bei);
    try {
        r = new RemoteObjectInvocationHandler(ref);
        assertNull(r.invoke(proxy, BigEcho.class.getMethods()[1],
                new Object[] { new Object[] { 1, 2, 3, 4 } }));
    } catch (Throwable e) {
        fail("Failed with:" + e);
    }
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:23,代码来源:TestRemoteObjectInvocationHandler.java

示例8: testInvoke012

import java.rmi.server.RemoteObjectInvocationHandler; //导入依赖的package包/类
public final void testInvoke012() throws RemoteException {
    BigEcho_imp bei = new BigEcho_imp() {
        public void echo() throws RemoteException {
            throw new RemoteException("Always pass throw here");
        }

        public void echo(Object... objs) throws RemoteException {
            if (objs == null) {
                throw new RemoteException("Objs Null");
            }
        }
    };
    RemoteRef ref = bei.getRef();
    BigEcho proxy = (BigEcho) RemoteObject.toStub(bei);
    try {
        r = new RemoteObjectInvocationHandler(ref);
        assertNull(r.invoke(proxy, BigEcho.class.getMethods()[1],
                new Object[] { new Object[] {} }));
    } catch (Throwable e) {
        fail("Failed with:" + e);
    }
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:23,代码来源:TestRemoteObjectInvocationHandler.java

示例9: createProxy

import java.rmi.server.RemoteObjectInvocationHandler; //导入依赖的package包/类
/**
 * Returns a proxy for the specified implClass.
 *
 * If both of the following criteria is satisfied, a dynamic proxy for
 * the specified implClass is returned (otherwise a RemoteStub instance
 * for the specified implClass is returned):
 *
 *    a) either the property java.rmi.server.ignoreStubClasses is true or
 *       a pregenerated stub class does not exist for the impl class, and
 *    b) forceStubUse is false.
 *
 * If the above criteria are satisfied, this method constructs a
 * dynamic proxy instance (that implements the remote interfaces of
 * implClass) constructed with a RemoteObjectInvocationHandler instance
 * constructed with the clientRef.
 *
 * Otherwise, this method loads the pregenerated stub class (which
 * extends RemoteStub and implements the remote interfaces of
 * implClass) and constructs an instance of the pregenerated stub
 * class with the clientRef.
 *
 * @param implClass the class to obtain remote interfaces from
 * @param clientRef the remote ref to use in the invocation handler
 * @param forceStubUse if true, forces creation of a RemoteStub
 * @throws IllegalArgumentException if implClass implements illegal
 * remote interfaces
 * @throws StubNotFoundException if problem locating/creating stub or
 * creating the dynamic proxy instance
 **/
public static Remote createProxy(Class<?> implClass,
                                 RemoteRef clientRef,
                                 boolean forceStubUse)
    throws StubNotFoundException
{
    Class<?> remoteClass;

    try {
        remoteClass = getRemoteClass(implClass);
    } catch (ClassNotFoundException ex ) {
        throw new StubNotFoundException(
            "object does not implement a remote interface: " +
            implClass.getName());
    }

    if (forceStubUse ||
        !(ignoreStubClasses || !stubClassExists(remoteClass)))
    {
        return createStub(remoteClass, clientRef);
    }

    final ClassLoader loader = implClass.getClassLoader();
    final Class<?>[] interfaces = getRemoteInterfaces(implClass);
    final InvocationHandler handler =
        new RemoteObjectInvocationHandler(clientRef);

    /* REMIND: private remote interfaces? */

    try {
        return AccessController.doPrivileged(new PrivilegedAction<Remote>() {
            public Remote run() {
                return (Remote) Proxy.newProxyInstance(loader,
                                                       interfaces,
                                                       handler);
            }});
    } catch (IllegalArgumentException e) {
        throw new StubNotFoundException("unable to create proxy", e);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:69,代码来源:Util.java

示例10: checkStub

import java.rmi.server.RemoteObjectInvocationHandler; //导入依赖的package包/类
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!");
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:41,代码来源:RMIConnector.java

示例11: getAddress

import java.rmi.server.RemoteObjectInvocationHandler; //导入依赖的package包/类
public static String getAddress(final Service svc)
throws RemoteException {
	final RemoteObjectInvocationHandler h = (RemoteObjectInvocationHandler) getInvocationHandler(svc);
	final LiveRef ref = ((UnicastRef) h.getRef()).getLiveRef();
	final Channel channel = ref.getChannel();
	final TCPEndpoint endpoint = (TCPEndpoint) channel.getEndpoint();
	return endpoint.getHost() + ":" + endpoint.getPort();
}
 
开发者ID:emc-mongoose,项目名称:mongoose-base,代码行数:9,代码来源:ServiceUtil.java

示例12: checkStub

import java.rmi.server.RemoteObjectInvocationHandler; //导入依赖的package包/类
private static void checkStub(Remote stub,
                              Class<? extends Remote> 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!");
    }
}
 
开发者ID:toomanyopenfiles,项目名称:jmxmon,代码行数:41,代码来源:ProxyClient.java

示例13: createProxyStub

import java.rmi.server.RemoteObjectInvocationHandler; //导入依赖的package包/类
/**
 * Create the 1.2 proxy stub in the case when the pre-generated stub is not
 * available of the system is explicitly instructed to use proxy stubs.
 *
 * @param stubFor the class for that the proxy class must be constructed.
 * @param reference the remote reference, used to find the given object
 *
 * @return the applicable proxy stub.
 *
 * @author Audrius Meskauskas ([email protected])
 */
Remote createProxyStub(Class stubFor, RemoteRef reference)
{
  // Collect all interfaces, implemented by stubFor and derived from
  // Remote (also Remote itself):
  HashSet interfaces = new HashSet();
  Class c = stubFor;
  Class[] intfs;

  while (c != null)
    {
      intfs = c.getInterfaces();
      for (int i = 0; i < intfs.length; i++)
        {
          if (Remote.class.isAssignableFrom(intfs[i]))
            interfaces.add(intfs[i]);
        }
      c = c.getSuperclass();
    }

  intfs = new Class[interfaces.size()];
  Iterator it = interfaces.iterator();

  for (int i = 0; i < intfs.length; i++)
    intfs[i] = (Class) it.next();

  RemoteObjectInvocationHandler handler =
    new RemoteObjectInvocationHandler(reference);

  Object proxy =
    Proxy.newProxyInstance(stubFor.getClassLoader(), intfs, handler);

  return (Remote) proxy;
}
 
开发者ID:vilie,项目名称:javify,代码行数:45,代码来源:UnicastServerRef.java

示例14: createProxyStub

import java.rmi.server.RemoteObjectInvocationHandler; //导入依赖的package包/类
/**
 * Create the 1.2 proxy stub in the case when the pre-generated stub is not
 * available of the system is explicitly instructed to use proxy stubs.
 * 
 * @param stubFor the class for that the proxy class must be constructed.
 * @param reference the remote reference, used to find the given object
 * 
 * @return the applicable proxy stub.
 * 
 * @author Audrius Meskauskas ([email protected])
 */
Remote createProxyStub(Class stubFor, RemoteRef reference)
{
  // Collect all interfaces, implemented by stubFor and derived from
  // Remote (also Remote itself):
  HashSet interfaces = new HashSet();
  Class c = stubFor;
  Class[] intfs;

  while (c != null)
    {
      intfs = c.getInterfaces();
      for (int i = 0; i < intfs.length; i++)
        {
          if (Remote.class.isAssignableFrom(intfs[i]))
            interfaces.add(intfs[i]);
        }
      c = c.getSuperclass();
    }

  intfs = new Class[interfaces.size()];
  Iterator it = interfaces.iterator();

  for (int i = 0; i < intfs.length; i++)
    intfs[i] = (Class) it.next();
  
  RemoteObjectInvocationHandler handler = 
    new RemoteObjectInvocationHandler(reference);
  
  Object proxy = 
    Proxy.newProxyInstance(stubFor.getClassLoader(), intfs, handler);

  return (Remote) proxy;
}
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:45,代码来源:UnicastServerRef.java

示例15: createProxy

import java.rmi.server.RemoteObjectInvocationHandler; //导入依赖的package包/类
/**
 * Returns a proxy for the specified implClass.
 *
 * If both of the following criteria is satisfied, a dynamic proxy for
 * the specified implClass is returned (otherwise a RemoteStub instance
 * for the specified implClass is returned):
 *
 *    a) either the property java.rmi.server.ignoreStubClasses is true or
 *       a pregenerated stub class does not exist for the impl class, and
 *    b) forceStubUse is false.
 *
 * If the above criteria are satisfied, this method constructs a
 * dynamic proxy instance (that implements the remote interfaces of
 * implClass) constructed with a RemoteObjectInvocationHandler instance
 * constructed with the clientRef.
 *
 * Otherwise, this method loads the pregenerated stub class (which
 * extends RemoteStub and implements the remote interfaces of
 * implClass) and constructs an instance of the pregenerated stub
 * class with the clientRef.
 *
 * @param implClass the class to obtain remote interfaces from
 * @param clientRef the remote ref to use in the invocation handler
 * @param forceStubUse if true, forces creation of a RemoteStub
 * @throws IllegalArgumentException if implClass implements illegal
 * remote interfaces
 * @throws StubNotFoundException if problem locating/creating stub or
 * creating the dynamic proxy instance
 **/
public static Remote createProxy(Class implClass,
                                 RemoteRef clientRef,
                                 boolean forceStubUse)
    throws StubNotFoundException
{
    Class remoteClass;

    try {
        remoteClass = getRemoteClass(implClass);
    } catch (ClassNotFoundException ex ) {
        throw new StubNotFoundException(
            "object does not implement a remote interface: " +
            implClass.getName());
    }

    if (forceStubUse ||
        !(ignoreStubClasses || !stubClassExists(remoteClass)))
    {
        return createStub(remoteClass, clientRef);
    }

    ClassLoader loader = implClass.getClassLoader();
    Class[] interfaces = getRemoteInterfaces(implClass);
    InvocationHandler handler =
        new RemoteObjectInvocationHandler(clientRef);

    /* REMIND: private remote interfaces? */

    try {
        return (Remote) Proxy.newProxyInstance(loader,
                                               interfaces,
                                               handler);
    } catch (IllegalArgumentException e) {
        throw new StubNotFoundException("unable to create proxy", e);
    }
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:66,代码来源:Util.java


注:本文中的java.rmi.server.RemoteObjectInvocationHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。