jdk/test/javax/management/remote/mandatory/connection/NoIIOP.java
changeset 15685 14c6889b6132
child 30376 2ccf2cf7ea48
equal deleted inserted replaced
15684:e5b41bd22ec9 15685:14c6889b6132
       
     1 /*
       
     2  * Copyright (c) 2013, 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  */
       
    29 
       
    30 import javax.management.MBeanServer;
       
    31 import javax.management.MBeanServerFactory;
       
    32 import javax.management.remote.*;
       
    33 import javax.management.remote.rmi.*;
       
    34 import java.net.MalformedURLException;
       
    35 import java.io.IOException;
       
    36 import javax.security.auth.Subject;
       
    37 import java.rmi.NoSuchObjectException;
       
    38 import javax.management.remote.JMXConnectorFactory;
       
    39 import javax.management.remote.JMXConnectorServerFactory;
       
    40 
       
    41 public class NoIIOP {
       
    42 
       
    43     /**
       
    44      * RMIIIOPServerImpl implementation for testing purposes (methods are
       
    45      * overridden to be public to allow for testing)
       
    46      */
       
    47     static class MyRMIIIOPServerImpl extends RMIIIOPServerImpl {
       
    48         MyRMIIIOPServerImpl() throws IOException {
       
    49             super(null);
       
    50         }
       
    51         @Override
       
    52         public void export() throws IOException {
       
    53             super.export();
       
    54         }
       
    55         @Override
       
    56         public String getProtocol() {
       
    57             return super.getProtocol();
       
    58         }
       
    59         @Override
       
    60         public RMIConnection makeClient(String connectionId, Subject subject)
       
    61             throws IOException
       
    62         {
       
    63             return super.makeClient(connectionId, subject);
       
    64         }
       
    65         @Override
       
    66         public void closeClient(RMIConnection client) throws IOException {
       
    67             super.closeClient(client);
       
    68         }
       
    69         @Override
       
    70         public void closeServer() throws IOException {
       
    71             super.closeServer();
       
    72         }
       
    73     }
       
    74 
       
    75 
       
    76     public static void main(String[] args) throws Exception {
       
    77         try {
       
    78             Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie");
       
    79             System.out.println("RMI/IIOP appears to be supported, test skipped");
       
    80             return;
       
    81         } catch (ClassNotFoundException okay) { }
       
    82 
       
    83         JMXServiceURL url = new JMXServiceURL("service:jmx:iiop://");
       
    84         MBeanServer mbs = MBeanServerFactory.createMBeanServer();
       
    85 
       
    86 
       
    87         // test JMXConnectorFactory/JMXConnectorServerFactory
       
    88 
       
    89         try {
       
    90             JMXConnectorFactory.connect(url);
       
    91             throw new RuntimeException("connect did not throw MalformedURLException");
       
    92         } catch (MalformedURLException expected) { }
       
    93 
       
    94         try {
       
    95             JMXConnectorServerFactory.newJMXConnectorServer(url, null, null);
       
    96             throw new RuntimeException("newJMXConnectorServer did not throw MalformedURLException");
       
    97         } catch (MalformedURLException expected) { }
       
    98 
       
    99 
       
   100         // test RMIConnector/RMIConnectorServer
       
   101 
       
   102         RMIConnector connector = new RMIConnector(url, null);
       
   103         try {
       
   104             connector.connect();
       
   105             throw new RuntimeException("connect did not throw IOException");
       
   106         } catch (IOException expected) { }
       
   107 
       
   108         RMIConnectorServer server = new RMIConnectorServer(url, null, mbs);
       
   109         try {
       
   110             server.start();
       
   111             throw new RuntimeException("start did not throw IOException");
       
   112         } catch (IOException expected) { }
       
   113 
       
   114 
       
   115         // test RMIIIOPServerImpl
       
   116 
       
   117         MyRMIIIOPServerImpl impl = new MyRMIIIOPServerImpl();
       
   118         impl.setMBeanServer(mbs);
       
   119         System.out.println(impl.getProtocol());
       
   120 
       
   121         try {
       
   122             impl.export();
       
   123             throw new RuntimeException("export did not throw IOException");
       
   124         } catch (IOException expected) { }
       
   125 
       
   126         try {
       
   127             impl.newClient(null);
       
   128             throw new RuntimeException("newClient did not throw IOException");
       
   129         } catch (IOException expected) { }
       
   130 
       
   131         try {
       
   132             impl.toStub();
       
   133             throw new RuntimeException("toStub did not throw NoSuchObjectException");
       
   134         } catch (NoSuchObjectException expected) { }
       
   135 
       
   136         try {
       
   137             impl.closeServer();
       
   138             throw new RuntimeException("closeServer did not throw NoSuchObjectException");
       
   139         } catch (NoSuchObjectException expected) { }
       
   140     }
       
   141 }