jdk/test/java/rmi/transport/httpSocket/HttpSocketTest.java
author mchung
Thu, 28 May 2015 10:54:48 -0700
changeset 30820 0d4717a011d3
parent 14778 5947768d173d
child 37681 b1a0f119f766
permissions -rw-r--r--
8081347: Add @modules to jdk_core tests Reviewed-by: alanb, joehw, lancea Contributed-by: alexander.kulyakhtin@oracle.com, alan.bateman@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
     1
/*
13256
5886d7607acd 7142596: RMI JPRT tests are failing
dmocek
parents: 5506
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: 715
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary HttpSocket functionality test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @author Dana Burns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @library ../../testlibrary
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 14778
diff changeset
    30
 * @modules java.rmi/sun.rmi.registry
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 14778
diff changeset
    31
 *          java.rmi/sun.rmi.server
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 14778
diff changeset
    32
 *          java.rmi/sun.rmi.transport
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 14778
diff changeset
    33
 *          java.rmi/sun.rmi.transport.proxy
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 14778
diff changeset
    34
 *          java.rmi/sun.rmi.transport.tcp
14778
5947768d173d 8004748: clean up @build tags in RMI tests
smarks
parents: 13256
diff changeset
    35
 * @build TestLibrary HttpSocketTest HttpSocketTest_Stub
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @run main/othervm/policy=security.policy HttpSocketTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *  This test assures remote methods can be carried out over RMI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *  After setting the RMI runtime socket factory to the http proxy version,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *  a registry is created, a remote object (an instance of this class) is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *  registered with it, and then it is exercised.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.rmi.RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.rmi.Naming;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.rmi.RMISecurityManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.rmi.registry.LocateRegistry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.rmi.registry.Registry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.rmi.server.RMISocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.rmi.server.UnicastRemoteObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import sun.rmi.transport.proxy.RMIHttpToPortSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
interface MyRemoteInterface extends Remote {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    void setRemoteObject( Remote r ) throws RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    Remote getRemoteObject() throws RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    61
public class HttpSocketTest extends UnicastRemoteObject
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    implements MyRemoteInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static final String NAME = "HttpSocketTest";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public HttpSocketTest() throws RemoteException{}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private Remote ro;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public static void main(String[] args)
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    71
        throws Exception
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    {
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    73
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    74
        Registry registry = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    76
        TestLibrary.suggestSecurityManager(null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    78
        // Set the socket factory.
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    79
        System.err.println("installing socket factory");
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    80
        RMISocketFactory.setSocketFactory(new RMIHttpToPortSocketFactory());
13256
5886d7607acd 7142596: RMI JPRT tests are failing
dmocek
parents: 5506
diff changeset
    81
        int registryPort = -1;
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    82
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    83
        try {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            System.err.println("Starting registry");
13256
5886d7607acd 7142596: RMI JPRT tests are failing
dmocek
parents: 5506
diff changeset
    85
            registry = TestLibrary.createRegistryOnUnusedPort();
5886d7607acd 7142596: RMI JPRT tests are failing
dmocek
parents: 5506
diff changeset
    86
            registryPort = TestLibrary.getRegistryPort(registry);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        } catch (Exception e) {
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    88
            TestLibrary.bomb(e);
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    89
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    91
        try {
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    92
            registry.rebind( NAME, new HttpSocketTest() );
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    93
            MyRemoteInterface httpTest =
13256
5886d7607acd 7142596: RMI JPRT tests are failing
dmocek
parents: 5506
diff changeset
    94
                (MyRemoteInterface)Naming.lookup("//:" + registryPort + "/" + NAME);
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    95
            httpTest.setRemoteObject( new HttpSocketTest() );
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    96
            Remote r = httpTest.getRemoteObject();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    98
        } catch (Exception e) {
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
    99
            TestLibrary.bomb(e);
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
   100
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public void setRemoteObject( Remote ro ) throws RemoteException {
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
   106
        this.ro = ro;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public Remote getRemoteObject() throws RemoteException {
309
bda219d843f6 6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents: 2
diff changeset
   110
        return( this.ro );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
}