java.rmi.Naming Java Examples

The following examples show how to use java.rmi.Naming. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: main.java    From sigar-system_runtime with MIT License 6 votes vote down vote up
public static void main(String args[]) {
    try {
        System.setProperty("java.library.path", "monitor_libs");
        if(args.length==0) ip = "192.168.191.5";
        else ip = args[0];
        System.setProperty("java.rmi.server.hostname", ip);
        systemStatusService sss = new systemStatusServiceImpl();
        LocateRegistry.createRegistry(8828);
        Naming.bind("rmi://"+ip+":8828/systemstatus",sss);
        System.out.println("启动成功!"+System.getProperty("java.library.path"));
    } catch (Exception e) {
        System.out.println("创建远程对象发生异常!"); 
        System.out.println(e);
    }
    

}
 
Example #2
Source File: ChildVM.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
  try {
    int namingPort = Integer.getInteger(DUnitLauncher.RMI_PORT_PARAM).intValue();
    int vmNum = Integer.getInteger(DUnitLauncher.VM_NUM_PARAM).intValue();
    LogWriter log = Log.createLogWriter("dunit-vm-" + vmNum, DUnitLauncher.LOG_LEVEL);
    System.out.println("VM" + vmNum + " is launching");
    DUnitLauncher.initSystemProperties(log);
    MasterRemote holder = (MasterRemote) Naming.lookup("//localhost:" + namingPort + "/" + DUnitLauncher.MASTER_PARAM);
    RemoteTestModule.Master = new FakeMaster();
    DUnitLauncher.locatorPort = holder.getLocatorPort();
    Naming.bind("//localhost:" + namingPort + "/vm" + vmNum, new FakeRemoteTestModule(log));
    holder.signalVMReady();
    //This loop is here so this VM will die even if the master is mean killed.
    while(true) {
      holder.ping();
      Thread.sleep(1000);
    }
  } catch (Throwable t) {
    t.printStackTrace();
    System.exit(1);
  }
}
 
Example #3
Source File: BeanService.java    From Fourinone with Apache License 2.0 6 votes vote down vote up
final static ParkActive getBean(String TPYYM,  int TPYDK, String rmname) throws RemoteException
{
	try{
		if(ConfigContext.getTMOT()>0l)
			System.setProperty(ConfigContext.getQSXYSJ(), ConfigContext.getTMOT()+"");
		return (ParkActive)Naming.lookup(ConfigContext.getProtocolInfo(TPYYM,TPYDK,rmname));
	}catch(Exception e){
		//LogUtil.info("[BeanService]", "[getBean]", "getBean:"+e.getClass());
		if(e instanceof RemoteException)
			throw (RemoteException)e;
		else{
			//e.printStackTrace();
			LogUtil.info("[ObjectService]", "[getBean]", "[Error Exception:]", e);
		}
	}
	return null;
}
 
Example #4
Source File: ChildVM.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
  try {
    int namingPort = Integer.getInteger(DUnitLauncher.RMI_PORT_PARAM).intValue();
    int vmNum = Integer.getInteger(DUnitLauncher.VM_NUM_PARAM).intValue();
    LogWriter log = Log.createLogWriter("dunit-vm-" + vmNum, DUnitLauncher.LOG_LEVEL);
    System.out.println("VM" + vmNum + " is launching");
    DUnitLauncher.initSystemProperties(log);
    MasterRemote holder = (MasterRemote) Naming.lookup("//localhost:" + namingPort + "/" + DUnitLauncher.MASTER_PARAM);
    RemoteTestModule.Master = new FakeMaster();
    DUnitLauncher.locatorPort = holder.getLocatorPort();
    Naming.bind("//localhost:" + namingPort + "/vm" + vmNum, new FakeRemoteTestModule(log));
    holder.signalVMReady();
    //This loop is here so this VM will die even if the master is mean killed.
    while(true) {
      holder.ping();
      Thread.sleep(1000);
    }
  } catch (Throwable t) {
    t.printStackTrace();
    System.exit(1);
  }
}
 
Example #5
Source File: MainRemote.java    From public with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    KeyValueStoreRemote store;

    try {
        store = (KeyValueStoreRemote) Naming.lookup("//localhost/kvstore");

        store.put(3, 1993);
        System.out.println(store.get(3));

        store.put(9, 1873);
        System.out.println(store.get(9));

        store.remove(3);
        System.out.println(store.get(3));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #6
Source File: UnderscoreHost.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    UnderscoreHost t = null;
    try {
        HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory();
        RMISocketFactory.setSocketFactory(hvf);
        Registry r = TestLibrary.createRegistryOnUnusedPort();
        int port = TestLibrary.getRegistryPort(r);
        t = new UnderscoreHost();
        r.rebind(NAME, t);
        Naming.lookup("rmi://" + HOSTNAME +
                      ":" + port + "/" + NAME);
        /*
         * This test is coded to pass whether java.net.URI obeys
         * RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.).
         *
         * If java.net.URI obeys RFC 3986, so host names may
         * contain underscores, then the Naming.lookup invocation
         * should succeed-- but the host actually connected to
         * must equal HOSTNAME.
         */
        if (!hvf.host.equals(HOSTNAME)) {
            throw new RuntimeException(
                "java.rmi.Naming Parsing error:" +
                hvf.host + ":" + HOSTNAME);
        }
    } catch (MalformedURLException e) {
        /*
         * If java.net.URI obeys RFC 2396, so host names must not
         * contain underscores, then the Naming.lookup invocation
         * should throw MalformedURLException-- so this is OK.
         */
    } catch (IOException ioe) {
        TestLibrary.bomb(ioe);
    } catch (java.rmi.NotBoundException nbe) {
        TestLibrary.bomb(nbe);
    } finally {
        TestLibrary.unexport(t);
    }

}
 
Example #7
Source File: NumberCruncherClient.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void main(String[] args) {
   if(args.length == 1) {
     try {
       String url = "rmi://"+args[0]+ "/Factor";
     	NumberCruncher nc = (NumberCruncher) Naming.lookup(url);
loop(nc);
     }
     catch(Exception e) {
e.printStackTrace();
     }      
   }
   else
     usage("Wrong number of arguments.");
 }
 
Example #8
Source File: RemoteCacheServerFactory.java    From commons-jcs with Apache License 2.0 5 votes vote down vote up
/**
 * Look up the remote cache service admin instance
 *
 * @param config the configuration properties
 * @param port the local port
 * @return the admin object instance
 *
 * @throws Exception if lookup fails
 */
private static ICacheServiceAdmin lookupCacheServiceAdmin(Properties config, int port) throws Exception
{
    String remoteServiceName = config.getProperty( REMOTE_CACHE_SERVICE_NAME, REMOTE_CACHE_SERVICE_VAL ).trim();
    String registry = RemoteUtils.getNamingURL("", port, remoteServiceName);

    log.debug( "looking up server {0}", registry );
    Object obj = Naming.lookup( registry );
    log.debug( "server found" );

    return (ICacheServiceAdmin) obj;
}
 
Example #9
Source File: GumballMonitorTestDrive.java    From head-first-design-patterns-Java with MIT License 5 votes vote down vote up
public static void main(String[] args) {
    String[] location = {"rmi://santafe.mightygumball.com/gumballmachine",
            "rmi://boulder.mightygumball.com/gumballmachine",
            "rmi://seattle.mightygumball.com/gumballmachine"};

    if (args.length >= 0) {
        location = new String[1];
        location[0] = "rmi://" + args[0] + "/gumballmachine";
    }

    GumballMonitor[] monitor = new GumballMonitor[location.length];


    for (int i = 0; i < location.length; i++) {
        try {
            GumballMachineRemote machine = (GumballMachineRemote) Naming.lookup(location[i]);
            monitor[i] = new GumballMonitor(machine);
            System.out.println(monitor[i]);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    for (int i = 0; i < monitor.length; i++) {
        monitor[i].report();
    }
}
 
Example #10
Source File: BootstrapperClient.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private static BootstrapperProxyIF lookup(String url) {
  System.out.println("Looking up bootstrapper at " + url);
  try {
    return (BootstrapperProxyIF)Naming.lookup(url);
  } catch (Exception e) {
    return null;
  }
}
 
Example #11
Source File: ServerConnector.java    From ChatRoomFX with MIT License 5 votes vote down vote up
private ServerConnector() throws IOException, NotBoundException {
        Properties properties=new Properties();
//        InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream("settings.properties");
        InputStream input = new FileInputStream(new File("dbSettings/settings.properties"));

        properties.load(input);
//        System.setProperty("java.rmi.server.hostname",properties.getProperty("ip"));
        System.out.println(properties.getProperty("server-ip"));
        controller= (ChatController) Naming.lookup(String.format("rmi://%s:5050/ChatServer", properties.getProperty("server-ip")));

    }
 
Example #12
Source File: RemoteBlockingQueueTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes this test by binding an instance of
 * <code>RemoteBlockingQueueImpl</code> into the RMI registry hosted
 * in Hydra's master controller VM.
 */
public void setUp() throws Exception {
  String queueName = this.getUniqueName();
  Host host = Host.getHost(0);
  this.queueURL = RmiRegistryHelper.getMasterRegistryURL() + queueName;

  RemoteBlockingQueue queue =
    new RemoteBlockingQueueImpl(QUEUE_CAPACITY);
  DistributedTestCase.getLogWriter().info("Binding queue named \"" + this.queueURL
                           + "\"");
  Naming.bind(this.queueURL, queue);
}
 
Example #13
Source File: UnderscoreHost.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    UnderscoreHost t = null;
    try {
        HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory();
        RMISocketFactory.setSocketFactory(hvf);
        Registry r = TestLibrary.createRegistryOnUnusedPort();
        int port = TestLibrary.getRegistryPort(r);
        t = new UnderscoreHost();
        r.rebind(NAME, t);
        Naming.lookup("rmi://" + HOSTNAME +
                      ":" + port + "/" + NAME);
        /*
         * This test is coded to pass whether java.net.URI obeys
         * RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.).
         *
         * If java.net.URI obeys RFC 3986, so host names may
         * contain underscores, then the Naming.lookup invocation
         * should succeed-- but the host actually connected to
         * must equal HOSTNAME.
         */
        if (!hvf.host.equals(HOSTNAME)) {
            throw new RuntimeException(
                "java.rmi.Naming Parsing error:" +
                hvf.host + ":" + HOSTNAME);
        }
    } catch (MalformedURLException e) {
        /*
         * If java.net.URI obeys RFC 2396, so host names must not
         * contain underscores, then the Naming.lookup invocation
         * should throw MalformedURLException-- so this is OK.
         */
    } catch (IOException ioe) {
        TestLibrary.bomb(ioe);
    } catch (java.rmi.NotBoundException nbe) {
        TestLibrary.bomb(nbe);
    } finally {
        TestLibrary.unexport(t);
    }

}
 
Example #14
Source File: LookupNameWithColon.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String[] names = {
        "fairly:simple", "somewhat:more/complicated",
        "multiple:colons:in:name"
    };

    Registry reg = TestLibrary.createRegistryOnUnusedPort();
    int port = TestLibrary.getRegistryPort(reg);

    for (int i = 0; i < names.length; i++) {
        reg.rebind(names[i], reg);
        Naming.lookup("rmi://localhost:" + port + "/" + names[i]);
    }
}
 
Example #15
Source File: Server.java    From PatternViaJava with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        //both method
        Remote server = new ServerRemoteImpl();
        //ServerRemote server=new ServerRemoteImpl();
        //open local port
        java.rmi.registry.LocateRegistry.createRegistry(5099);
        Naming.rebind("//:5099/RemoteServer", server);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #16
Source File: LookupNameWithColon.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String[] names = {
        "fairly:simple", "somewhat:more/complicated",
        "multiple:colons:in:name"
    };

    Registry reg = TestLibrary.createRegistryOnUnusedPort();
    int port = TestLibrary.getRegistryPort(reg);

    for (int i = 0; i < names.length; i++) {
        reg.rebind(names[i], reg);
        Naming.lookup("rmi://localhost:" + port + "/" + names[i]);
    }
}
 
Example #17
Source File: UnderscoreHost.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    UnderscoreHost t = null;
    try {
        HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory();
        RMISocketFactory.setSocketFactory(hvf);
        Registry r = TestLibrary.createRegistryOnUnusedPort();
        int port = TestLibrary.getRegistryPort(r);
        t = new UnderscoreHost();
        r.rebind(NAME, t);
        Naming.lookup("rmi://" + HOSTNAME +
                      ":" + port + "/" + NAME);
        /*
         * This test is coded to pass whether java.net.URI obeys
         * RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.).
         *
         * If java.net.URI obeys RFC 3986, so host names may
         * contain underscores, then the Naming.lookup invocation
         * should succeed-- but the host actually connected to
         * must equal HOSTNAME.
         */
        if (!hvf.host.equals(HOSTNAME)) {
            throw new RuntimeException(
                "java.rmi.Naming Parsing error:" +
                hvf.host + ":" + HOSTNAME);
        }
    } catch (MalformedURLException e) {
        /*
         * If java.net.URI obeys RFC 2396, so host names must not
         * contain underscores, then the Naming.lookup invocation
         * should throw MalformedURLException-- so this is OK.
         */
    } catch (IOException ioe) {
        TestLibrary.bomb(ioe);
    } catch (java.rmi.NotBoundException nbe) {
        TestLibrary.bomb(nbe);
    } finally {
        TestLibrary.unexport(t);
    }

}
 
Example #18
Source File: LookupNameWithColon.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String[] names = {
        "fairly:simple", "somewhat:more/complicated",
        "multiple:colons:in:name"
    };

    Registry reg = TestLibrary.createRegistryOnUnusedPort();
    int port = TestLibrary.getRegistryPort(reg);

    for (int i = 0; i < names.length; i++) {
        reg.rebind(names[i], reg);
        Naming.lookup("rmi://localhost:" + port + "/" + names[i]);
    }
}
 
Example #19
Source File: UnderscoreHost.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    UnderscoreHost t = null;
    try {
        HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory();
        RMISocketFactory.setSocketFactory(hvf);
        Registry r = TestLibrary.createRegistryOnUnusedPort();
        int port = TestLibrary.getRegistryPort(r);
        t = new UnderscoreHost();
        r.rebind(NAME, t);
        Naming.lookup("rmi://" + HOSTNAME +
                      ":" + port + "/" + NAME);
        /*
         * This test is coded to pass whether java.net.URI obeys
         * RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.).
         *
         * If java.net.URI obeys RFC 3986, so host names may
         * contain underscores, then the Naming.lookup invocation
         * should succeed-- but the host actually connected to
         * must equal HOSTNAME.
         */
        if (!hvf.host.equals(HOSTNAME)) {
            throw new RuntimeException(
                "java.rmi.Naming Parsing error:" +
                hvf.host + ":" + HOSTNAME);
        }
    } catch (MalformedURLException e) {
        /*
         * If java.net.URI obeys RFC 2396, so host names must not
         * contain underscores, then the Naming.lookup invocation
         * should throw MalformedURLException-- so this is OK.
         */
    } catch (IOException ioe) {
        TestLibrary.bomb(ioe);
    } catch (java.rmi.NotBoundException nbe) {
        TestLibrary.bomb(nbe);
    } finally {
        TestLibrary.unexport(t);
    }

}
 
Example #20
Source File: RmiTest.java    From MyTv with Apache License 2.0 5 votes vote down vote up
/**
 * 测试电视节目
 */
public void testEpgProgram() {
	String program = null;
	try {
		JolynnTv jolynnTv = (JolynnTv) Naming.lookup(url);
		program = jolynnTv.getProgramTable("CCTV-1 综合", "番禺有线",
				DateUtils.today());
	} catch (Exception e) {
		e.printStackTrace();
	}
	JSONArray array = JSON.parseArray(program);
	assertNotNull(array);
}
 
Example #21
Source File: RmiTest.java    From MyTv with Apache License 2.0 5 votes vote down vote up
/**
 * 测试电视台
 */
public void testEpgStation() {
	String stations = null;
	try {
		JolynnTv jolynnTv = (JolynnTv) Naming.lookup(url);
		stations = jolynnTv.getMyTvByClassify("番禺有线");
	} catch (Exception e) {
		e.printStackTrace();
	}
	JSONArray array = JSON.parseArray(stations);
	assertNotNull(array);
}
 
Example #22
Source File: LookupNameWithColon.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String[] names = {
        "fairly:simple", "somewhat:more/complicated",
        "multiple:colons:in:name"
    };

    Registry reg = TestLibrary.createRegistryOnUnusedPort();
    int port = TestLibrary.getRegistryPort(reg);

    for (int i = 0; i < names.length; i++) {
        reg.rebind(names[i], reg);
        Naming.lookup("rmi://localhost:" + port + "/" + names[i]);
    }
}
 
Example #23
Source File: UnderscoreHost.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    UnderscoreHost t = null;
    try {
        HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory();
        RMISocketFactory.setSocketFactory(hvf);
        Registry r = TestLibrary.createRegistryOnUnusedPort();
        int port = TestLibrary.getRegistryPort(r);
        t = new UnderscoreHost();
        r.rebind(NAME, t);
        Naming.lookup("rmi://" + HOSTNAME +
                      ":" + port + "/" + NAME);
        /*
         * This test is coded to pass whether java.net.URI obeys
         * RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.).
         *
         * If java.net.URI obeys RFC 3986, so host names may
         * contain underscores, then the Naming.lookup invocation
         * should succeed-- but the host actually connected to
         * must equal HOSTNAME.
         */
        if (!hvf.host.equals(HOSTNAME)) {
            throw new RuntimeException(
                "java.rmi.Naming Parsing error:" +
                hvf.host + ":" + HOSTNAME);
        }
    } catch (MalformedURLException e) {
        /*
         * If java.net.URI obeys RFC 2396, so host names must not
         * contain underscores, then the Naming.lookup invocation
         * should throw MalformedURLException-- so this is OK.
         */
    } catch (IOException ioe) {
        TestLibrary.bomb(ioe);
    } catch (java.rmi.NotBoundException nbe) {
        TestLibrary.bomb(nbe);
    } finally {
        TestLibrary.unexport(t);
    }

}
 
Example #24
Source File: RmiTest.java    From MyTv with Apache License 2.0 5 votes vote down vote up
/**
 * 测试电视台分类
 */
public void testEpgClassify() {
	String classify = null;
	try {
		JolynnTv jolynnTv = (JolynnTv) Naming.lookup(url);
		classify = jolynnTv.getMyTvClassify();
	} catch (Exception e) {
		e.printStackTrace();
	}
	JSONArray array = JSON.parseArray(classify);
	assertNotNull(array);
}
 
Example #25
Source File: BootstrapperClient.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private static BootstrapperProxyIF lookup(String url) {
  System.out.println("Looking up bootstrapper at " + url);
  try {
    return (BootstrapperProxyIF)Naming.lookup(url);
  } catch (Exception e) {
    return null;
  }
}
 
Example #26
Source File: RemoteBlockingQueueTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes this test by binding an instance of
 * <code>RemoteBlockingQueueImpl</code> into the RMI registry hosted
 * in Hydra's master controller VM.
 */
public void setUp() throws Exception {
  String queueName = this.getUniqueName();
  Host host = Host.getHost(0);
  this.queueURL = RmiRegistryHelper.getMasterRegistryURL() + queueName;

  RemoteBlockingQueue queue =
    new RemoteBlockingQueueImpl(QUEUE_CAPACITY);
  DistributedTestCase.getLogWriter().info("Binding queue named \"" + this.queueURL
                           + "\"");
  Naming.bind(this.queueURL, queue);
}
 
Example #27
Source File: UnderscoreHost.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    UnderscoreHost t = null;
    try {
        HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory();
        RMISocketFactory.setSocketFactory(hvf);
        Registry r = TestLibrary.createRegistryOnUnusedPort();
        int port = TestLibrary.getRegistryPort(r);
        t = new UnderscoreHost();
        r.rebind(NAME, t);
        Naming.lookup("rmi://" + HOSTNAME +
                      ":" + port + "/" + NAME);
        /*
         * This test is coded to pass whether java.net.URI obeys
         * RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.).
         *
         * If java.net.URI obeys RFC 3986, so host names may
         * contain underscores, then the Naming.lookup invocation
         * should succeed-- but the host actually connected to
         * must equal HOSTNAME.
         */
        if (!hvf.host.equals(HOSTNAME)) {
            throw new RuntimeException(
                "java.rmi.Naming Parsing error:" +
                hvf.host + ":" + HOSTNAME);
        }
    } catch (MalformedURLException e) {
        /*
         * If java.net.URI obeys RFC 2396, so host names must not
         * contain underscores, then the Naming.lookup invocation
         * should throw MalformedURLException-- so this is OK.
         */
    } catch (IOException ioe) {
        TestLibrary.bomb(ioe);
    } catch (java.rmi.NotBoundException nbe) {
        TestLibrary.bomb(nbe);
    } finally {
        TestLibrary.unexport(t);
    }

}
 
Example #28
Source File: LookupNameWithColon.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String[] names = {
        "fairly:simple", "somewhat:more/complicated",
        "multiple:colons:in:name"
    };

    Registry reg = TestLibrary.createRegistryOnUnusedPort();
    int port = TestLibrary.getRegistryPort(reg);

    for (int i = 0; i < names.length; i++) {
        reg.rebind(names[i], reg);
        Naming.lookup("rmi://localhost:" + port + "/" + names[i]);
    }
}
 
Example #29
Source File: LookupNameWithColon.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String[] names = {
        "fairly:simple", "somewhat:more/complicated",
        "multiple:colons:in:name"
    };

    Registry reg = TestLibrary.createRegistryOnUnusedPort();
    int port = TestLibrary.getRegistryPort(reg);

    for (int i = 0; i < names.length; i++) {
        reg.rebind(names[i], reg);
        Naming.lookup("rmi://localhost:" + port + "/" + names[i]);
    }
}
 
Example #30
Source File: UnderscoreHost.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    UnderscoreHost t = null;
    try {
        HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory();
        RMISocketFactory.setSocketFactory(hvf);
        Registry r = TestLibrary.createRegistryOnUnusedPort();
        int port = TestLibrary.getRegistryPort(r);
        t = new UnderscoreHost();
        r.rebind(NAME, t);
        Naming.lookup("rmi://" + HOSTNAME +
                      ":" + port + "/" + NAME);
        /*
         * This test is coded to pass whether java.net.URI obeys
         * RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.).
         *
         * If java.net.URI obeys RFC 3986, so host names may
         * contain underscores, then the Naming.lookup invocation
         * should succeed-- but the host actually connected to
         * must equal HOSTNAME.
         */
        if (!hvf.host.equals(HOSTNAME)) {
            throw new RuntimeException(
                "java.rmi.Naming Parsing error:" +
                hvf.host + ":" + HOSTNAME);
        }
    } catch (MalformedURLException e) {
        /*
         * If java.net.URI obeys RFC 2396, so host names must not
         * contain underscores, then the Naming.lookup invocation
         * should throw MalformedURLException-- so this is OK.
         */
    } catch (IOException ioe) {
        TestLibrary.bomb(ioe);
    } catch (java.rmi.NotBoundException nbe) {
        TestLibrary.bomb(nbe);
    } finally {
        TestLibrary.unexport(t);
    }

}