jdk/test/javax/management/remote/mandatory/provider/ProviderTest.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 14917 bf08557604f8
child 30376 2ccf2cf7ea48
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: 14917
diff changeset
     2
 * Copyright (c) 2003, 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: 1639
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test ProviderTest.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary Tests jar services provider are called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @run clean ProviderTest provider.JMXConnectorProviderImpl provider.JMXConnectorServerProviderImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @run build ProviderTest provider.JMXConnectorProviderImpl provider.JMXConnectorServerProviderImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @run main ProviderTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.management.remote.JMXConnectorFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.management.remote.JMXConnectorServerFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.management.remote.JMXConnector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.management.remote.JMXConnectorServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.management.remote.JMXServiceURL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.management.remote.JMXProviderException;
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 javax.management.MBeanServerConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.management.MBeanServerFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Tests jar services provider are called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
    49
import provider.JMXConnectorProviderImpl;
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
    50
import provider.JMXConnectorServerProviderImpl;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public class ProviderTest {
14917
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    52
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        System.out.println("Starting ProviderTest");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
14917
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    57
        // First do the test with a protocol handled by Service providers
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    58
        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        dotest(url, mbs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
    61
        boolean clientCalled = provider.JMXConnectorProviderImpl.called();
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
    62
        boolean serverCalled = provider.JMXConnectorServerProviderImpl.called();
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
    63
        boolean ok = clientCalled && serverCalled;
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
    64
        if (!ok) {
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
    65
            if (!clientCalled)
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
    66
                System.out.println("Client provider not called");
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
    67
            if (!serverCalled)
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
    68
                System.out.println("Server provider not called");
14917
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    69
            throw new RuntimeException("Test failed - see log for details");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
14917
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    72
        // The Service Provider doesn't handle IIOP. Default providers MUST
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    73
        // be called, which may or may not support IIOP.
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    74
        url = new JMXServiceURL("service:jmx:iiop://");
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    75
        try {
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    76
            dotest(url, mbs);
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    77
        } catch (MalformedURLException e) {
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    78
            try {
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    79
                Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie");
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    80
                e.printStackTrace(System.out);
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    81
                throw new RuntimeException("MalformedURLException throw but IIOP appears to be supported");
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    82
            } catch (ClassNotFoundException expected) { }
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    83
            System.out.println("MalformedURLException thrown, IIOP transport not supported");
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    84
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        // Unsupported protocol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        JMXConnectorServer server = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        JMXConnector client = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        url =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            new JMXServiceURL("service:jmx:unknown-protocol://");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            server =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                JMXConnectorServerFactory.newJMXConnectorServer(url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                                                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                                                                mbs);
14917
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    96
            throw new RuntimeException("Exception not thrown.");
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
    97
        } catch (MalformedURLException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            System.out.println("Expected MalformedURLException thrown.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            client =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                JMXConnectorFactory.newJMXConnector(url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                                                    null);
14917
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
   105
            throw new RuntimeException("Exception not thrown.");
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
   106
        } catch (MalformedURLException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            System.out.println("Expected MalformedURLException thrown.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        //JMXConnectorProviderException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        url =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            new JMXServiceURL("service:jmx:throw-provider-exception://");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            server =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                JMXConnectorServerFactory.newJMXConnectorServer(url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                                                mbs);
14917
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
   118
            throw new RuntimeException("Exception not thrown.");
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
   119
        } catch(JMXProviderException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            System.out.println("Expected JMXProviderException thrown.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            client =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                JMXConnectorFactory.newJMXConnector(url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                                                    null);
14917
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
   127
            throw new RuntimeException("Exception not thrown.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }catch(JMXProviderException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            System.out.println("Expected JMXProviderException thrown.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        System.out.println("Test OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    private static void dotest(JMXServiceURL url, MBeanServer mbs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        JMXConnectorServer server = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        JMXConnector client = null;
14917
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
   139
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
   140
        server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        server.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        JMXServiceURL outputAddr = server.getAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        System.out.println("Server started ["+ outputAddr+ "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
14917
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 5506
diff changeset
   145
        client = JMXConnectorFactory.newJMXConnector(outputAddr, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        client.connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        System.out.println("Client connected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        MBeanServerConnection connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            = client.getMBeanServerConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        System.out.println(connection.getDefaultDomain());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
}