Search in sources :

Example 1 with UnicastServerRef

use of sun.rmi.server.UnicastServerRef in project jdk8u_jdk by JetBrains.

the class FilterUSRTest method UnicastServerRef.

/*
     * Test exporting an object with a serialFilter using UnicastServerRef.exportObject().
     * Send some objects and check the number of calls to the serialFilter.
     */
@Test(dataProvider = "bindData")
public void UnicastServerRef(String name, Object obj, int expectedFilterCount) throws RemoteException {
    try {
        RemoteImpl impl = RemoteImpl.create();
        UnicastServerRef ref = new UnicastServerRef(new LiveRef(0), impl.checker);
        Echo client = (Echo) ref.exportObject(impl, null, false);
        int count = client.filterCount(obj);
        System.out.printf("count: %d, obj: %s%n", count, obj);
        Assert.assertEquals(count, expectedFilterCount, "wrong number of filter calls");
    } catch (RemoteException rex) {
        if (expectedFilterCount == -1 && UnmarshalException.class.equals(rex.getCause().getClass()) && InvalidClassException.class.equals(rex.getCause().getCause().getClass())) {
            // normal expected exception
            return;
        }
        rex.printStackTrace();
        Assert.fail("unexpected remote exception", rex);
    } catch (Exception ex) {
        Assert.fail("unexpected exception", ex);
    }
}
Also used : LiveRef(sun.rmi.transport.LiveRef) UnmarshalException(java.rmi.UnmarshalException) UnicastServerRef(sun.rmi.server.UnicastServerRef) RemoteException(java.rmi.RemoteException) UnmarshalException(java.rmi.UnmarshalException) RemoteException(java.rmi.RemoteException) InvalidClassException(java.io.InvalidClassException) Test(org.testng.annotations.Test)

Example 2 with UnicastServerRef

use of sun.rmi.server.UnicastServerRef in project jdk8u_jdk by JetBrains.

the class RMIJRMPServerImpl method export.

private void export(Remote obj) throws RemoteException {
    final RMIExporter exporter = (RMIExporter) env.get(RMIExporter.EXPORTER_ATTRIBUTE);
    final boolean daemon = EnvHelp.isServerDaemon(env);
    if (daemon && exporter != null) {
        throw new IllegalArgumentException("If " + EnvHelp.JMX_SERVER_DAEMON + " is specified as true, " + RMIExporter.EXPORTER_ATTRIBUTE + " cannot be used to specify an exporter!");
    }
    if (daemon) {
        if (csf == null && ssf == null) {
            new UnicastServerRef(port).exportObject(obj, null, true);
        } else {
            new UnicastServerRef2(port, csf, ssf).exportObject(obj, null, true);
        }
    } else if (exporter != null) {
        exporter.exportObject(obj, port, csf, ssf);
    } else {
        UnicastRemoteObject.exportObject(obj, port, csf, ssf);
    }
}
Also used : RMIExporter(com.sun.jmx.remote.internal.RMIExporter) UnicastServerRef2(sun.rmi.server.UnicastServerRef2) UnicastServerRef(sun.rmi.server.UnicastServerRef)

Example 3 with UnicastServerRef

use of sun.rmi.server.UnicastServerRef in project jdk8u_jdk by JetBrains.

the class TestLibrary method getRegistryPort.

/**
     * Returns the port number the RMI {@link Registry} is running on.
     *
     * @param registry the registry to find the port of.
     * @return the port number the registry is using.
     * @throws RuntimeException if there was a problem getting the port number.
     */
public static int getRegistryPort(Registry registry) {
    int port = -1;
    try {
        RemoteRef remoteRef = ((RegistryImpl) registry).getRef();
        LiveRef liveRef = ((UnicastServerRef) remoteRef).getLiveRef();
        Endpoint endpoint = liveRef.getChannel().getEndpoint();
        TCPEndpoint tcpEndpoint = (TCPEndpoint) endpoint;
        port = tcpEndpoint.getPort();
    } catch (Exception ex) {
        throw new RuntimeException("Error getting registry port.", ex);
    }
    return port;
}
Also used : RegistryImpl(sun.rmi.registry.RegistryImpl) TCPEndpoint(sun.rmi.transport.tcp.TCPEndpoint) LiveRef(sun.rmi.transport.LiveRef) Endpoint(sun.rmi.transport.Endpoint) TCPEndpoint(sun.rmi.transport.tcp.TCPEndpoint) RemoteRef(java.rmi.server.RemoteRef) UnicastServerRef(sun.rmi.server.UnicastServerRef) Endpoint(sun.rmi.transport.Endpoint) TCPEndpoint(sun.rmi.transport.tcp.TCPEndpoint) NoSuchObjectException(java.rmi.NoSuchObjectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException)

Example 4 with UnicastServerRef

use of sun.rmi.server.UnicastServerRef in project ysoserial by frohoff.

the class JRMPListener method getObject.

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;
}
Also used : UnicastRemoteObject(java.rmi.server.UnicastRemoteObject) UnicastServerRef(sun.rmi.server.UnicastServerRef)

Aggregations

UnicastServerRef (sun.rmi.server.UnicastServerRef)4 RemoteException (java.rmi.RemoteException)2 LiveRef (sun.rmi.transport.LiveRef)2 RMIExporter (com.sun.jmx.remote.internal.RMIExporter)1 IOException (java.io.IOException)1 InvalidClassException (java.io.InvalidClassException)1 MalformedURLException (java.net.MalformedURLException)1 NoSuchObjectException (java.rmi.NoSuchObjectException)1 UnmarshalException (java.rmi.UnmarshalException)1 RemoteRef (java.rmi.server.RemoteRef)1 UnicastRemoteObject (java.rmi.server.UnicastRemoteObject)1 Test (org.testng.annotations.Test)1 RegistryImpl (sun.rmi.registry.RegistryImpl)1 UnicastServerRef2 (sun.rmi.server.UnicastServerRef2)1 Endpoint (sun.rmi.transport.Endpoint)1 TCPEndpoint (sun.rmi.transport.tcp.TCPEndpoint)1