Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/remote/mandatory/connection/NoIIOP.java
38867 views
/*1* Copyright (c) 2013, 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/* @test24* @bug 800450225* @summary Sanity check that attempts to use the IIOP transport or26* RMIIIOPServerImpl when RMI/IIOP not present throws the expected exceptions27*/2829import javax.management.MBeanServer;30import javax.management.MBeanServerFactory;31import javax.management.remote.*;32import javax.management.remote.rmi.*;33import java.net.MalformedURLException;34import java.io.IOException;35import javax.security.auth.Subject;36import java.rmi.NoSuchObjectException;37import javax.management.remote.JMXConnectorFactory;38import javax.management.remote.JMXConnectorServerFactory;3940public class NoIIOP {4142/**43* RMIIIOPServerImpl implementation for testing purposes (methods are44* overridden to be public to allow for testing)45*/46static class MyRMIIIOPServerImpl extends RMIIIOPServerImpl {47MyRMIIIOPServerImpl() throws IOException {48super(null);49}50@Override51public void export() throws IOException {52super.export();53}54@Override55public String getProtocol() {56return super.getProtocol();57}58@Override59public RMIConnection makeClient(String connectionId, Subject subject)60throws IOException61{62return super.makeClient(connectionId, subject);63}64@Override65public void closeClient(RMIConnection client) throws IOException {66super.closeClient(client);67}68@Override69public void closeServer() throws IOException {70super.closeServer();71}72}737475public static void main(String[] args) throws Exception {76try {77Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie");78System.out.println("RMI/IIOP appears to be supported, test skipped");79return;80} catch (ClassNotFoundException okay) { }8182JMXServiceURL url = new JMXServiceURL("service:jmx:iiop://");83MBeanServer mbs = MBeanServerFactory.createMBeanServer();848586// test JMXConnectorFactory/JMXConnectorServerFactory8788try {89JMXConnectorFactory.connect(url);90throw new RuntimeException("connect did not throw MalformedURLException");91} catch (MalformedURLException expected) { }9293try {94JMXConnectorServerFactory.newJMXConnectorServer(url, null, null);95throw new RuntimeException("newJMXConnectorServer did not throw MalformedURLException");96} catch (MalformedURLException expected) { }979899// test RMIConnector/RMIConnectorServer100101RMIConnector connector = new RMIConnector(url, null);102try {103connector.connect();104throw new RuntimeException("connect did not throw IOException");105} catch (IOException expected) { }106107RMIConnectorServer server = new RMIConnectorServer(url, null, mbs);108try {109server.start();110throw new RuntimeException("start did not throw IOException");111} catch (IOException expected) { }112113114// test RMIIIOPServerImpl115116MyRMIIIOPServerImpl impl = new MyRMIIIOPServerImpl();117impl.setMBeanServer(mbs);118System.out.println(impl.getProtocol());119120try {121impl.export();122throw new RuntimeException("export did not throw IOException");123} catch (IOException expected) { }124125try {126impl.newClient(null);127throw new RuntimeException("newClient did not throw IOException");128} catch (IOException expected) { }129130try {131impl.toStub();132throw new RuntimeException("toStub did not throw NoSuchObjectException");133} catch (NoSuchObjectException expected) { }134135try {136impl.closeServer();137throw new RuntimeException("closeServer did not throw NoSuchObjectException");138} catch (NoSuchObjectException expected) { }139}140}141142143