jdk/test/java/rmi/server/clientStackTrace/ClientStackTrace.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 14778 5947768d173d
child 30820 0d4717a011d3
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
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) 1998, 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 4010355
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary RemoteException should have server's stack trace
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Laird Dornin
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @library ../../testlibrary
14778
5947768d173d 8004748: clean up @build tags in RMI tests
smarks
parents: 5506
diff changeset
    31
 * @build TestLibrary ClientStackTrace MyRemoteObject_Stub
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run main/othervm/policy=security.policy/timeout=120 ClientStackTrace
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This test ensures that the stack trace in a caught server side
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * remote exception contains the string "exceptionReceivedFromServer".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.rmi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.rmi.server.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.rmi.transport.StreamRemoteCall;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.io.ByteArrayOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
interface MyRemoteInterface extends Remote {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    void ping() throws RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
class MyRemoteObject extends UnicastRemoteObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    implements MyRemoteInterface {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public MyRemoteObject () throws RemoteException {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public void ping () throws RemoteException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        throw new RemoteException("This is a test remote exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public class ClientStackTrace {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    Object dummy = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        Object dummy = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        MyRemoteObject myRobj = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        MyRemoteInterface myStub = null;
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
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            PrintStream ps = new PrintStream(bos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            System.err.println("\nRegression test for bug 4010355\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            myRobj = new MyRemoteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            /* cause a remote exception to occur. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                myStub = (MyRemoteInterface) RemoteObject.toStub(myRobj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                myStub.ping();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            } catch (RemoteException re) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                re.printStackTrace(ps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                String trace = bos.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                if (trace.indexOf("exceptionReceivedFromServer") <0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                    throw new RuntimeException("No client stack trace on " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                               "thrown remote exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                    System.err.println("test passed with stack trace: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                                       trace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            deactivate(myRobj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            System.err.println("test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            throw new RuntimeException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            myRobj = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            myStub = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    // make sure that the remote object goes away.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    static void deactivate(RemoteServer r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        // make sure that the object goes away
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            System.err.println("deactivating object.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            UnicastRemoteObject.unexportObject(r, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            e.getMessage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
}