1 /* 2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 * @bug 8004502 26 * @summary Sanity check that attempts to use the IIOP transport or 27 * RMIIIOPServerImpl when RMI/IIOP not present throws the expected exceptions 28 * @modules java.management 29 */ 30 31 import javax.management.MBeanServer; 32 import javax.management.MBeanServerFactory; 33 import javax.management.remote.*; 34 import javax.management.remote.rmi.*; 35 import java.net.MalformedURLException; 36 import java.io.IOException; 37 import javax.security.auth.Subject; 38 import java.rmi.NoSuchObjectException; 39 import javax.management.remote.JMXConnectorFactory; 40 import javax.management.remote.JMXConnectorServerFactory; 41 42 public class NoIIOP { 43 44 /** 45 * RMIIIOPServerImpl implementation for testing purposes (methods are 46 * overridden to be public to allow for testing) 47 */ 48 static class MyRMIIIOPServerImpl extends RMIIIOPServerImpl { 49 MyRMIIIOPServerImpl() throws IOException { 50 super(null); 51 } 52 @Override 53 public void export() throws IOException { 54 super.export(); 55 } 56 @Override 57 public String getProtocol() { 58 return super.getProtocol(); 59 } 60 @Override 61 public RMIConnection makeClient(String connectionId, Subject subject) 62 throws IOException 63 { 64 return super.makeClient(connectionId, subject); 65 } 66 @Override 67 public void closeClient(RMIConnection client) throws IOException { 68 super.closeClient(client); 69 } 70 @Override 71 public void closeServer() throws IOException { 72 super.closeServer(); 73 } 74 } 75 76 77 public static void main(String[] args) throws Exception { 78 try { 79 Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie"); 80 System.out.println("RMI/IIOP appears to be supported, test skipped"); 81 return; 82 } catch (ClassNotFoundException okay) { } 83 84 JMXServiceURL url = new JMXServiceURL("service:jmx:iiop://"); 85 MBeanServer mbs = MBeanServerFactory.createMBeanServer(); 86 87 88 // test JMXConnectorFactory/JMXConnectorServerFactory 89 90 try { 91 JMXConnectorFactory.connect(url); 92 throw new RuntimeException("connect did not throw MalformedURLException"); 93 } catch (MalformedURLException expected) { } 94 95 try { 96 JMXConnectorServerFactory.newJMXConnectorServer(url, null, null); 97 throw new RuntimeException("newJMXConnectorServer did not throw MalformedURLException"); 98 } catch (MalformedURLException expected) { } 99 100 101 // test RMIConnector/RMIConnectorServer 102 103 RMIConnector connector = new RMIConnector(url, null); 104 try { 105 connector.connect(); 106 throw new RuntimeException("connect did not throw IOException"); 107 } catch (IOException expected) { } 108 109 RMIConnectorServer server = new RMIConnectorServer(url, null, mbs); 110 try { 111 server.start(); 112 throw new RuntimeException("start did not throw IOException"); 113 } catch (IOException expected) { } 114 115 116 // test RMIIIOPServerImpl 117 118 MyRMIIIOPServerImpl impl = new MyRMIIIOPServerImpl(); 119 impl.setMBeanServer(mbs); 120 System.out.println(impl.getProtocol()); 121 122 try { 123 impl.export(); 124 throw new RuntimeException("export did not throw IOException"); 125 } catch (IOException expected) { } 126 127 try { 128 impl.newClient(null); 129 throw new RuntimeException("newClient did not throw IOException"); 130 } catch (IOException expected) { } 131 132 try { 133 impl.toStub(); 134 throw new RuntimeException("toStub did not throw NoSuchObjectException"); 135 } catch (NoSuchObjectException expected) { } 136 137 try { 138 impl.closeServer(); 139 throw new RuntimeException("closeServer did not throw NoSuchObjectException"); 140 } catch (NoSuchObjectException expected) { } 141 } 142 }