Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/remote/mandatory/connection/IIOPURLTest.java
38867 views
/*1* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 488679926* @summary Check that IIOP URLs have /ior/ in the path27* @author Eamonn McManus28* @run clean IIOPURLTest29* @run build IIOPURLTest30* @run main IIOPURLTest31*/3233import javax.management.MBeanServer;34import javax.management.MBeanServerConnection;35import javax.management.MBeanServerFactory;36import javax.management.Notification;37import javax.management.NotificationListener;38import javax.management.ObjectName;3940import javax.management.remote.JMXConnector;41import javax.management.remote.JMXConnectorFactory;42import javax.management.remote.JMXConnectorServer;43import javax.management.remote.JMXConnectorServerFactory;44import javax.management.remote.JMXServiceURL;4546public class IIOPURLTest {4748public static void main(String[] args) throws Exception {49JMXServiceURL inputAddr =50new JMXServiceURL("service:jmx:iiop://");51JMXConnectorServer s;52try {53s = JMXConnectorServerFactory.newJMXConnectorServer(inputAddr, null, null);54} catch (java.net.MalformedURLException x) {55try {56Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie");57throw new RuntimeException("MalformedURLException thrown but iiop appears to be supported");58} catch (ClassNotFoundException expected) { }59System.out.println("IIOP protocol not supported, test skipped");60return;61}62MBeanServer mbs = MBeanServerFactory.createMBeanServer();63mbs.registerMBean(s, new ObjectName("a:b=c"));64s.start();65JMXServiceURL outputAddr = s.getAddress();66if (!outputAddr.getURLPath().startsWith("/ior/IOR:")) {67throw new RuntimeException("URL path should start with \"/ior/IOR:\": " +68outputAddr);69}70System.out.println("IIOP URL path looks OK: " + outputAddr);71JMXConnector c = JMXConnectorFactory.connect(outputAddr);72System.out.println("Successfully got default domain: " +73c.getMBeanServerConnection().getDefaultDomain());74c.close();75s.stop();76}77}787980