test/java/rmi/transport/handshakeFailure/HandshakeFailure.java

Print this page


   1 /*
   2  * Copyright (c) 2001, 2008, 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 4485966
  26  * @summary Whan an RMI (JRMP) connection is made to a TCP address that is
  27  * listening, so the connection is accepted, but the server responds with
  28  * invalid JRMP protocol (such as because a non-JRMP server is currently
  29  * listening at that address), the client application should receive a
  30  * java.rmi.ConnectException or ConnectIOException, not a MarshalException.
  31  * @author Peter Jones
  32  *
  33  * @build HandshakeFailure

  34  * @run main/othervm HandshakeFailure
  35  */
  36 
  37 import java.net.ServerSocket;
  38 import java.net.Socket;
  39 import java.rmi.ConnectException;
  40 import java.rmi.ConnectIOException;
  41 import java.rmi.MarshalException;
  42 import java.rmi.registry.LocateRegistry;
  43 import java.rmi.registry.Registry;
  44 
  45 public class HandshakeFailure {
  46 
  47     private static final int PORT = 2020;
  48     private static final int TIMEOUT = 10000;
  49 
  50     public static void main(String[] args) throws Exception {
  51 
  52         /*
  53          * Listen on port...
  54          */
  55         ServerSocket serverSocket = new ServerSocket(PORT);
  56 
  57         /*
  58          * (Attempt RMI call to port in separate thread.)
  59          */
  60         Registry registry = LocateRegistry.getRegistry(PORT);
  61         Connector connector = new Connector(registry);
  62         Thread t = new Thread(connector);
  63         t.setDaemon(true);
  64         t.start();
  65 
  66         /*
  67          * ...accept one connection from port and send non-JRMP data.


   1 /*
   2  * Copyright (c) 2001, 2012, 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 4485966
  26  * @summary Whan an RMI (JRMP) connection is made to a TCP address that is
  27  * listening, so the connection is accepted, but the server responds with
  28  * invalid JRMP protocol (such as because a non-JRMP server is currently
  29  * listening at that address), the client application should receive a
  30  * java.rmi.ConnectException or ConnectIOException, not a MarshalException.
  31  * @author Peter Jones
  32  *
  33  * @library ../../testlibrary
  34  * @build HandshakeFailure TestLibrary
  35  * @run main/othervm HandshakeFailure
  36  */
  37 
  38 import java.net.ServerSocket;
  39 import java.net.Socket;
  40 import java.rmi.ConnectException;
  41 import java.rmi.ConnectIOException;
  42 import java.rmi.MarshalException;
  43 import java.rmi.registry.LocateRegistry;
  44 import java.rmi.registry.Registry;
  45 
  46 public class HandshakeFailure {
  47 
  48     private static final int PORT = TestLibrary.getUnusedRandomPort();
  49     private static final int TIMEOUT = 10000;
  50 
  51     public static void main(String[] args) throws Exception {
  52 
  53         /*
  54          * Listen on port...
  55          */
  56         ServerSocket serverSocket = new ServerSocket(PORT);
  57 
  58         /*
  59          * (Attempt RMI call to port in separate thread.)
  60          */
  61         Registry registry = LocateRegistry.getRegistry(PORT);
  62         Connector connector = new Connector(registry);
  63         Thread t = new Thread(connector);
  64         t.setDaemon(true);
  65         t.start();
  66 
  67         /*
  68          * ...accept one connection from port and send non-JRMP data.