jdk/test/javax/management/remote/mandatory/connection/NoIIOP.java
author alanb
Mon, 21 Jan 2013 23:35:36 -0500
changeset 15685 14c6889b6132
child 30376 2ccf2cf7ea48
permissions -rw-r--r--
8004502: Compact Profiles contents Reviewed-by: dholmes, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15685
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     1
/*
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     4
 *
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     8
 *
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    13
 * accompanied this code).
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    14
 *
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    18
 *
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    21
 * questions.
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    22
 */
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    23
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    24
/* @test
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    25
 * @bug 8004502
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    26
 * @summary Sanity check that attempts to use the IIOP transport or
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    27
 *   RMIIIOPServerImpl when RMI/IIOP not present throws the expected exceptions
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    28
 */
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    29
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    30
import javax.management.MBeanServer;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    31
import javax.management.MBeanServerFactory;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    32
import javax.management.remote.*;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    33
import javax.management.remote.rmi.*;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    34
import java.net.MalformedURLException;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    35
import java.io.IOException;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    36
import javax.security.auth.Subject;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    37
import java.rmi.NoSuchObjectException;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    38
import javax.management.remote.JMXConnectorFactory;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    39
import javax.management.remote.JMXConnectorServerFactory;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    40
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    41
public class NoIIOP {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    42
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    43
    /**
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    44
     * RMIIIOPServerImpl implementation for testing purposes (methods are
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    45
     * overridden to be public to allow for testing)
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    46
     */
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    47
    static class MyRMIIIOPServerImpl extends RMIIIOPServerImpl {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    48
        MyRMIIIOPServerImpl() throws IOException {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    49
            super(null);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    50
        }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    51
        @Override
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    52
        public void export() throws IOException {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    53
            super.export();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    54
        }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    55
        @Override
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    56
        public String getProtocol() {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    57
            return super.getProtocol();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    58
        }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    59
        @Override
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    60
        public RMIConnection makeClient(String connectionId, Subject subject)
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    61
            throws IOException
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    62
        {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    63
            return super.makeClient(connectionId, subject);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    64
        }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    65
        @Override
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    66
        public void closeClient(RMIConnection client) throws IOException {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    67
            super.closeClient(client);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    68
        }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    69
        @Override
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    70
        public void closeServer() throws IOException {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    71
            super.closeServer();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    72
        }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    73
    }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    74
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    75
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    76
    public static void main(String[] args) throws Exception {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    77
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    78
            Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    79
            System.out.println("RMI/IIOP appears to be supported, test skipped");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    80
            return;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    81
        } catch (ClassNotFoundException okay) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    82
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    83
        JMXServiceURL url = new JMXServiceURL("service:jmx:iiop://");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    84
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    85
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    86
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    87
        // test JMXConnectorFactory/JMXConnectorServerFactory
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    88
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    89
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    90
            JMXConnectorFactory.connect(url);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    91
            throw new RuntimeException("connect did not throw MalformedURLException");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    92
        } catch (MalformedURLException expected) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    93
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    94
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    95
            JMXConnectorServerFactory.newJMXConnectorServer(url, null, null);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    96
            throw new RuntimeException("newJMXConnectorServer did not throw MalformedURLException");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    97
        } catch (MalformedURLException expected) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    98
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    99
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   100
        // test RMIConnector/RMIConnectorServer
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   101
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   102
        RMIConnector connector = new RMIConnector(url, null);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   103
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   104
            connector.connect();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   105
            throw new RuntimeException("connect did not throw IOException");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   106
        } catch (IOException expected) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   107
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   108
        RMIConnectorServer server = new RMIConnectorServer(url, null, mbs);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   109
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   110
            server.start();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   111
            throw new RuntimeException("start did not throw IOException");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   112
        } catch (IOException expected) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   113
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   114
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   115
        // test RMIIIOPServerImpl
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   116
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   117
        MyRMIIIOPServerImpl impl = new MyRMIIIOPServerImpl();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   118
        impl.setMBeanServer(mbs);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   119
        System.out.println(impl.getProtocol());
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   120
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   121
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   122
            impl.export();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   123
            throw new RuntimeException("export did not throw IOException");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   124
        } catch (IOException expected) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   125
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   126
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   127
            impl.newClient(null);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   128
            throw new RuntimeException("newClient did not throw IOException");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   129
        } catch (IOException expected) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   130
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   131
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   132
            impl.toStub();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   133
            throw new RuntimeException("toStub did not throw NoSuchObjectException");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   134
        } catch (NoSuchObjectException expected) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   135
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   136
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   137
            impl.closeServer();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   138
            throw new RuntimeException("closeServer did not throw NoSuchObjectException");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   139
        } catch (NoSuchObjectException expected) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   140
    }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   141
}