jdk/test/javax/management/remote/mandatory/connection/NoIIOP.java
author ykantser
Thu, 07 May 2015 09:11:49 +0200
changeset 30376 2ccf2cf7ea48
parent 15685 14c6889b6132
permissions -rw-r--r--
8078896: Add @modules as needed to the jdk_svc tests Reviewed-by: alanb, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15685
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 15685
diff changeset
     2
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
15685
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
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 15685
diff changeset
    28
 * @modules java.management
15685
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    29
 */
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    30
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    31
import javax.management.MBeanServer;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    32
import javax.management.MBeanServerFactory;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    33
import javax.management.remote.*;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    34
import javax.management.remote.rmi.*;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    35
import java.net.MalformedURLException;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    36
import java.io.IOException;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    37
import javax.security.auth.Subject;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    38
import java.rmi.NoSuchObjectException;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    39
import javax.management.remote.JMXConnectorFactory;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    40
import javax.management.remote.JMXConnectorServerFactory;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    41
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    42
public class NoIIOP {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    43
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    44
    /**
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    45
     * RMIIIOPServerImpl implementation for testing purposes (methods are
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    46
     * overridden to be public to allow for testing)
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    47
     */
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    48
    static class MyRMIIIOPServerImpl extends RMIIIOPServerImpl {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    49
        MyRMIIIOPServerImpl() throws IOException {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    50
            super(null);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    51
        }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    52
        @Override
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    53
        public void export() throws IOException {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    54
            super.export();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    55
        }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    56
        @Override
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    57
        public String getProtocol() {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    58
            return super.getProtocol();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    59
        }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    60
        @Override
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    61
        public RMIConnection makeClient(String connectionId, Subject subject)
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    62
            throws IOException
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    63
        {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    64
            return super.makeClient(connectionId, subject);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    65
        }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    66
        @Override
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    67
        public void closeClient(RMIConnection client) throws IOException {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    68
            super.closeClient(client);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    69
        }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    70
        @Override
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    71
        public void closeServer() throws IOException {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    72
            super.closeServer();
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
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    77
    public static void main(String[] args) throws Exception {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    78
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    79
            Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    80
            System.out.println("RMI/IIOP appears to be supported, test skipped");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    81
            return;
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    82
        } catch (ClassNotFoundException okay) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    83
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    84
        JMXServiceURL url = new JMXServiceURL("service:jmx:iiop://");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    85
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    86
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    87
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    88
        // test JMXConnectorFactory/JMXConnectorServerFactory
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    89
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    90
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    91
            JMXConnectorFactory.connect(url);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    92
            throw new RuntimeException("connect did not throw MalformedURLException");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    93
        } catch (MalformedURLException expected) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    94
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    95
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    96
            JMXConnectorServerFactory.newJMXConnectorServer(url, null, null);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    97
            throw new RuntimeException("newJMXConnectorServer did not throw MalformedURLException");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    98
        } catch (MalformedURLException expected) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
    99
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   100
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   101
        // test RMIConnector/RMIConnectorServer
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   102
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   103
        RMIConnector connector = new RMIConnector(url, null);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   104
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   105
            connector.connect();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   106
            throw new RuntimeException("connect did not throw IOException");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   107
        } catch (IOException expected) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   108
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   109
        RMIConnectorServer server = new RMIConnectorServer(url, null, mbs);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   110
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   111
            server.start();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   112
            throw new RuntimeException("start did not throw IOException");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   113
        } catch (IOException expected) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   114
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   115
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   116
        // test RMIIIOPServerImpl
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   117
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   118
        MyRMIIIOPServerImpl impl = new MyRMIIIOPServerImpl();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   119
        impl.setMBeanServer(mbs);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   120
        System.out.println(impl.getProtocol());
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   121
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   122
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   123
            impl.export();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   124
            throw new RuntimeException("export did not throw IOException");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   125
        } catch (IOException expected) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   126
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   127
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   128
            impl.newClient(null);
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   129
            throw new RuntimeException("newClient did not throw IOException");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   130
        } catch (IOException expected) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   131
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   132
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   133
            impl.toStub();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   134
            throw new RuntimeException("toStub did not throw NoSuchObjectException");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   135
        } catch (NoSuchObjectException expected) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   136
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   137
        try {
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   138
            impl.closeServer();
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   139
            throw new RuntimeException("closeServer did not throw NoSuchObjectException");
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   140
        } catch (NoSuchObjectException expected) { }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   141
    }
14c6889b6132 8004502: Compact Profiles contents
alanb
parents:
diff changeset
   142
}