Path: blob/master/test/jdk/javax/management/remote/mandatory/connection/IIOPURLTest.java
41159 views
/*1* Copyright (c) 2003, 2015, 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*29* @run clean IIOPURLTest30* @run build IIOPURLTest31* @run main IIOPURLTest32*/3334import javax.management.MBeanServer;35import javax.management.MBeanServerConnection;36import javax.management.MBeanServerFactory;37import javax.management.Notification;38import javax.management.NotificationListener;39import javax.management.ObjectName;4041import javax.management.remote.JMXConnector;42import javax.management.remote.JMXConnectorFactory;43import javax.management.remote.JMXConnectorServer;44import javax.management.remote.JMXConnectorServerFactory;45import javax.management.remote.JMXServiceURL;4647public class IIOPURLTest {4849public static void main(String[] args) throws Exception {50JMXServiceURL inputAddr =51new JMXServiceURL("service:jmx:iiop://");52JMXConnectorServer s;53try {54s = JMXConnectorServerFactory.newJMXConnectorServer(inputAddr, null, null);55} catch (java.net.MalformedURLException x) {56try {57Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie");58throw new RuntimeException("MalformedURLException thrown but iiop appears to be supported");59} catch (ClassNotFoundException expected) { }60System.out.println("IIOP protocol not supported, test skipped");61return;62}63MBeanServer mbs = MBeanServerFactory.createMBeanServer();64mbs.registerMBean(s, new ObjectName("a:b=c"));65s.start();66JMXServiceURL outputAddr = s.getAddress();67if (!outputAddr.getURLPath().startsWith("/ior/IOR:")) {68throw new RuntimeException("URL path should start with \"/ior/IOR:\": " +69outputAddr);70}71System.out.println("IIOP URL path looks OK: " + outputAddr);72JMXConnector c = JMXConnectorFactory.connect(outputAddr);73System.out.println("Successfully got default domain: " +74c.getMBeanServerConnection().getDefaultDomain());75c.close();76s.stop();77}78}798081