jdk/test/sun/rmi/server/MarshalOutputStream/marshalForeignStub/MarshalForeignStub.java
author ant
Wed, 19 Mar 2008 16:23:50 +0300
changeset 131 fe5ccd4774b4
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6567410: PIT : java/awt/Focus/AutoRequestFocusTest/AutoRequestFocusSetVisibleTest.java fails Summary: A filter flag has been added to the HCBT focus hook. Reviewed-by: dcherepanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2000 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @build TestLibrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @build TestFailedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @build MarshalForeignStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @build Receiver
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @build MarshalForeignStub_Stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @run main/othervm/policy=security.policy MarshalForeignStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.rmi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.rmi.server.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class MarshalForeignStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    extends UnicastRemoteObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    implements Receiver
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static class ForeignStub implements Remote, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public MarshalForeignStub() throws RemoteException {
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 void receive(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        System.err.println("+ receive(): received object " + obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        System.err.println("\nRegression test for bug 4117427\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        TestLibrary.suggestSecurityManager(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        System.err.println("Creating remote object.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        MarshalForeignStub obj = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            obj = new MarshalForeignStub();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        } catch (RemoteException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            TestLibrary.bomb(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            Receiver stub = (Receiver) RemoteObject.toStub(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
             * Pass an instance of ForeignStub to the remote object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
             * This should succeed, because MarshalOutputStream now
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
             * allows objects that implement Remote, but not RemoteStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
             * to be serialized in an RMI call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                "Passing a foreign stub to remote object.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            stub.receive(new ForeignStub());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            System.err.println("TEST SUCCEEDED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            System.err.println("TEST FAILED: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            throw new RuntimeException("TEST FAILED: " + e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                UnicastRemoteObject.unexportObject(obj, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            } catch (Throwable e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
}