jdk/test/sun/rmi/server/MarshalOutputStream/marshalForeignStub/MarshalForeignStub.java
author stefank
Mon, 25 Aug 2014 09:10:13 +0200
changeset 26314 f8bc1966fb30
parent 23010 6dadb192ad81
child 30820 0d4717a011d3
permissions -rw-r--r--
8055416: Several vm/gc/heap/summary "After GC" events emitted for the same GC ID Reviewed-by: brutisso, ehelin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 14778
diff changeset
     2
 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/* @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @bug 4117427
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary When marshalling an object that implements java.rmi.Remote,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * but is not a RemoteStub and its corresponding stub class is not known
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * by the RMI runtime, RMI's MarshalOutputStream should assume that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * object is a proxy of some sort (like an RMI/IIOP stub) and simply
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * allow the object to be serialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @author Ann Wollrath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @library ../../../../../java/rmi/testlibrary
14778
5947768d173d 8004748: clean up @build tags in RMI tests
smarks
parents: 5506
diff changeset
    34
 * @build TestLibrary Receiver MarshalForeignStub_Stub
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @run main/othervm/policy=security.policy MarshalForeignStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.rmi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.rmi.server.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class MarshalForeignStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    extends UnicastRemoteObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    implements Receiver
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public static class ForeignStub implements Remote, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public MarshalForeignStub() throws RemoteException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public void receive(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        System.err.println("+ receive(): received object " + obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        System.err.println("\nRegression test for bug 4117427\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        TestLibrary.suggestSecurityManager(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        System.err.println("Creating remote object.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        MarshalForeignStub obj = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            obj = new MarshalForeignStub();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        } catch (RemoteException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            TestLibrary.bomb(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            Receiver stub = (Receiver) RemoteObject.toStub(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
             * Pass an instance of ForeignStub to the remote object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
             * This should succeed, because MarshalOutputStream now
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
             * allows objects that implement Remote, but not RemoteStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
             * to be serialized in an RMI call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                "Passing a foreign stub to remote object.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            stub.receive(new ForeignStub());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            System.err.println("TEST SUCCEEDED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            System.err.println("TEST FAILED: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            throw new RuntimeException("TEST FAILED: " + e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                UnicastRemoteObject.unexportObject(obj, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            } catch (Throwable e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
}