Java Code Examples for java.rmi.MarshalledObject#get()

The following examples show how to use java.rmi.MarshalledObject#get() . 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: MOFilterTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test that MarshalledObject inherits the ObjectInputFilter from
 * the stream it was deserialized from.
 */
@Test(dataProvider="FilterCases")
static void delegatesToMO(boolean withFilter) {
    try {
        Serializable testobj = Integer.valueOf(5);
        MarshalledObject<Serializable> mo = new MarshalledObject<>(testobj);
        Assert.assertEquals(mo.get(), testobj, "MarshalledObject.get returned a non-equals test object");

        byte[] bytes = writeObjects(mo);

        try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
             ObjectInputStream ois = new ObjectInputStream(bais)) {

            CountingFilter filter1 = new CountingFilter();
            ObjectInputFilter.Config.setObjectInputFilter(ois, withFilter ? filter1 : null);
            MarshalledObject<?> actualMO = (MarshalledObject<?>)ois.readObject();
            int count = filter1.getCount();

            actualMO.get();
            int expectedCount = withFilter ? count + 2 : count;
            int actualCount = filter1.getCount();
            Assert.assertEquals(actualCount, expectedCount, "filter called wrong number of times during get()");
        }
    } catch (IOException ioe) {
        Assert.fail("Unexpected IOException", ioe);
    } catch (ClassNotFoundException cnf) {
        Assert.fail("Deserializing", cnf);
    }
}
 
Example 2
Source File: TestDataSourceSerialization.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testDataSourceSerialization() throws Exception {
    FBManagedConnectionFactory mcf = initMcf();
    DataSource ds = (DataSource) mcf.createConnectionFactory();
    assertNotNull("Could not get DataSource", ds);

    Connection c = ds.getConnection();
    assertNotNull("Could not get Connection", c);

    c.close();
    MarshalledObject<DataSource> mo = new MarshalledObject<DataSource>(ds);
    ds = mo.get();
    c = ds.getConnection();
    c.close();
}
 
Example 3
Source File: MOFilterTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test that MarshalledObject inherits the ObjectInputFilter from
 * the stream it was deserialized from.
 */
@Test(dataProvider="FilterCases")
static void delegatesToMO(boolean withFilter) {
    try {
        Serializable testobj = Integer.valueOf(5);
        MarshalledObject<Serializable> mo = new MarshalledObject<>(testobj);
        Assert.assertEquals(mo.get(), testobj, "MarshalledObject.get returned a non-equals test object");

        byte[] bytes = writeObjects(mo);

        try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
             ObjectInputStream ois = new ObjectInputStream(bais)) {

            CountingFilter filter1 = new CountingFilter();
            ObjectInputFilter.Config.setObjectInputFilter(ois, withFilter ? filter1 : null);
            MarshalledObject<?> actualMO = (MarshalledObject<?>)ois.readObject();
            int count = filter1.getCount();

            actualMO.get();
            int expectedCount = withFilter ? count + 2 : count;
            int actualCount = filter1.getCount();
            Assert.assertEquals(actualCount, expectedCount, "filter called wrong number of times during get()");
        }
    } catch (IOException ioe) {
        Assert.fail("Unexpected IOException", ioe);
    } catch (ClassNotFoundException cnf) {
        Assert.fail("Deserializing", cnf);
    }
}
 
Example 4
Source File: MOFilterTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test that MarshalledObject inherits the ObjectInputFilter from
 * the stream it was deserialized from.
 */
@Test(dataProvider="FilterCases")
static void delegatesToMO(boolean withFilter) {
    try {
        Serializable testobj = Integer.valueOf(5);
        MarshalledObject<Serializable> mo = new MarshalledObject<>(testobj);
        Assert.assertEquals(mo.get(), testobj, "MarshalledObject.get returned a non-equals test object");

        byte[] bytes = writeObjects(mo);

        try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
             ObjectInputStream ois = new ObjectInputStream(bais)) {

            CountingFilter filter1 = new CountingFilter();
            ObjectInputFilter.Config.setObjectInputFilter(ois, withFilter ? filter1 : null);
            MarshalledObject<?> actualMO = (MarshalledObject<?>)ois.readObject();
            int count = filter1.getCount();

            actualMO.get();
            int expectedCount = withFilter ? count + 2 : count;
            int actualCount = filter1.getCount();
            Assert.assertEquals(actualCount, expectedCount, "filter called wrong number of times during get()");
        }
    } catch (IOException ioe) {
        Assert.fail("Unexpected IOException", ioe);
    } catch (ClassNotFoundException cnf) {
        Assert.fail("Deserializing", cnf);
    }
}
 
Example 5
Source File: MOFilterTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test that MarshalledObject inherits the ObjectInputFilter from
 * the stream it was deserialized from.
 */
@Test(dataProvider="FilterCases")
static void delegatesToMO(boolean withFilter) {
    try {
        Serializable testobj = Integer.valueOf(5);
        MarshalledObject<Serializable> mo = new MarshalledObject<>(testobj);
        Assert.assertEquals(mo.get(), testobj, "MarshalledObject.get returned a non-equals test object");

        byte[] bytes = writeObjects(mo);

        try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
             ObjectInputStream ois = new ObjectInputStream(bais)) {

            CountingFilter filter1 = new CountingFilter();
            ObjectInputFilter.Config.setObjectInputFilter(ois, withFilter ? filter1 : null);
            MarshalledObject<?> actualMO = (MarshalledObject<?>)ois.readObject();
            int count = filter1.getCount();

            actualMO.get();
            int expectedCount = withFilter ? count + 2 : count;
            int actualCount = filter1.getCount();
            Assert.assertEquals(actualCount, expectedCount, "filter called wrong number of times during get()");
        }
    } catch (IOException ioe) {
        Assert.fail("Unexpected IOException", ioe);
    } catch (ClassNotFoundException cnf) {
        Assert.fail("Deserializing", cnf);
    }
}
 
Example 6
Source File: MOFilterTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test that MarshalledObject inherits the ObjectInputFilter from
 * the stream it was deserialized from.
 */
@Test(dataProvider="FilterCases")
static void delegatesToMO(boolean withFilter) {
    try {
        Serializable testobj = Integer.valueOf(5);
        MarshalledObject<Serializable> mo = new MarshalledObject<>(testobj);
        Assert.assertEquals(mo.get(), testobj, "MarshalledObject.get returned a non-equals test object");

        byte[] bytes = writeObjects(mo);

        try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
             ObjectInputStream ois = new ObjectInputStream(bais)) {

            CountingFilter filter1 = new CountingFilter();
            ObjectInputFilter.Config.setObjectInputFilter(ois, withFilter ? filter1 : null);
            MarshalledObject<?> actualMO = (MarshalledObject<?>)ois.readObject();
            int count = filter1.getCount();

            actualMO.get();
            int expectedCount = withFilter ? count + 2 : count;
            int actualCount = filter1.getCount();
            Assert.assertEquals(actualCount, expectedCount, "filter called wrong number of times during get()");
        }
    } catch (IOException ioe) {
        Assert.fail("Unexpected IOException", ioe);
    } catch (ClassNotFoundException cnf) {
        Assert.fail("Deserializing", cnf);
    }
}
 
Example 7
Source File: MOFilterTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test that MarshalledObject inherits the ObjectInputFilter from
 * the stream it was deserialized from.
 */
@Test(dataProvider="FilterCases")
static void delegatesToMO(boolean withFilter) {
    try {
        Serializable testobj = Integer.valueOf(5);
        MarshalledObject<Serializable> mo = new MarshalledObject<>(testobj);
        Assert.assertEquals(mo.get(), testobj, "MarshalledObject.get returned a non-equals test object");

        byte[] bytes = writeObjects(mo);

        try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
             ObjectInputStream ois = new ObjectInputStream(bais)) {

            CountingFilter filter1 = new CountingFilter();
            ObjectInputFilter.Config.setObjectInputFilter(ois, withFilter ? filter1 : null);
            MarshalledObject<?> actualMO = (MarshalledObject<?>)ois.readObject();
            int count = filter1.getCount();

            actualMO.get();
            int expectedCount = withFilter ? count + 2 : count;
            int actualCount = filter1.getCount();
            Assert.assertEquals(actualCount, expectedCount, "filter called wrong number of times during get()");
        }
    } catch (IOException ioe) {
        Assert.fail("Unexpected IOException", ioe);
    } catch (ClassNotFoundException cnf) {
        Assert.fail("Deserializing", cnf);
    }
}
 
Example 8
Source File: FnnClass.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public Object unmarshal(MarshalledObject mobj)
    throws IOException, ClassNotFoundException
{
    return mobj.get();
}
 
Example 9
Source File: FnnClass.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public Object unmarshal(MarshalledObject mobj)
    throws IOException, ClassNotFoundException
{
    return mobj.get();
}
 
Example 10
Source File: FnnClass.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public Object unmarshal(MarshalledObject mobj)
    throws IOException, ClassNotFoundException
{
    return mobj.get();
}
 
Example 11
Source File: DGCImplInsulation.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        TestLibrary.suggestSecurityManager(null);

        Permissions perms = new Permissions();
        perms.add(new SocketPermission("*:1024-", "listen"));
        AccessControlContext acc =
            new AccessControlContext(new ProtectionDomain[] {
                new ProtectionDomain(
                    new CodeSource(null, (Certificate[]) null), perms) });

        Remote impl = new DGCImplInsulation();;

        try {
            Remote stub = (Remote) java.security.AccessController.doPrivileged(
                new ExportAction(impl));
            System.err.println("exported remote object; local stub: " + stub);

            MarshalledObject mobj = new MarshalledObject(stub);
            stub = (Remote) mobj.get();
            System.err.println("marshalled/unmarshalled stub: " + stub);

            ReferenceQueue refQueue = new ReferenceQueue();
            Reference weakRef = new WeakReference(impl, refQueue);
            impl = null;
            System.gc();
            if (refQueue.remove(TIMEOUT) == weakRef) {
                throw new RuntimeException(
                    "TEST FAILED: remote object garbage collected");
            } else {
                System.err.println("TEST PASSED");
                stub = null;
                System.gc();
                Thread.sleep(2000);
                System.gc();
            }
        } finally {
            try {
                UnicastRemoteObject.unexportObject(impl, true);
            } catch (Exception e) {
            }
        }
    }
 
Example 12
Source File: FnnClass.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public Object unmarshal(MarshalledObject mobj)
    throws IOException, ClassNotFoundException
{
    return mobj.get();
}
 
Example 13
Source File: FnnClass.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public Object unmarshal(MarshalledObject mobj)
    throws IOException, ClassNotFoundException
{
    return mobj.get();
}
 
Example 14
Source File: FnnClass.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public Object unmarshal(MarshalledObject mobj)
    throws IOException, ClassNotFoundException
{
    return mobj.get();
}
 
Example 15
Source File: FnnClass.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public Object unmarshal(MarshalledObject mobj)
    throws IOException, ClassNotFoundException
{
    return mobj.get();
}
 
Example 16
Source File: FnnClass.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public Object unmarshal(MarshalledObject mobj)
    throws IOException, ClassNotFoundException
{
    return mobj.get();
}
 
Example 17
Source File: FnnClass.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public Object unmarshal(MarshalledObject mobj)
    throws IOException, ClassNotFoundException
{
    return mobj.get();
}
 
Example 18
Source File: DGCImplInsulation.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        TestLibrary.suggestSecurityManager(null);

        Permissions perms = new Permissions();
        perms.add(new SocketPermission("*:1024-", "listen"));
        AccessControlContext acc =
            new AccessControlContext(new ProtectionDomain[] {
                new ProtectionDomain(
                    new CodeSource(null, (Certificate[]) null), perms) });

        Remote impl = new DGCImplInsulation();;

        try {
            Remote stub = (Remote) java.security.AccessController.doPrivileged(
                new ExportAction(impl));
            System.err.println("exported remote object; local stub: " + stub);

            MarshalledObject mobj = new MarshalledObject(stub);
            stub = (Remote) mobj.get();
            System.err.println("marshalled/unmarshalled stub: " + stub);

            ReferenceQueue refQueue = new ReferenceQueue();
            Reference weakRef = new WeakReference(impl, refQueue);
            impl = null;
            System.gc();
            if (refQueue.remove(TIMEOUT) == weakRef) {
                throw new RuntimeException(
                    "TEST FAILED: remote object garbage collected");
            } else {
                System.err.println("TEST PASSED");
                stub = null;
                System.gc();
                Thread.sleep(2000);
                System.gc();
            }
        } finally {
            try {
                UnicastRemoteObject.unexportObject(impl, true);
            } catch (Exception e) {
            }
        }
    }
 
Example 19
Source File: FnnClass.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public Object unmarshal(MarshalledObject mobj)
    throws IOException, ClassNotFoundException
{
    return mobj.get();
}
 
Example 20
Source File: FnnClass.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public Object unmarshal(MarshalledObject mobj)
    throws IOException, ClassNotFoundException
{
    return mobj.get();
}