[jboss-cvs] JBossAS SVN: r88678 - in projects/naming/branches/Branch_5_0/jnpserver/src: test/java/org/jnp/test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon May 11 19:19:27 EDT 2009


Author: bstansberry at jboss.com
Date: 2009-05-11 19:19:27 -0400 (Mon, 11 May 2009)
New Revision: 88678

Added:
   projects/naming/branches/Branch_5_0/jnpserver/src/test/java/org/jnp/test/BootstrapURLUnitTest.java
Modified:
   projects/naming/branches/Branch_5_0/jnpserver/src/main/java/org/jnp/server/Main.java
   projects/naming/branches/Branch_5_0/jnpserver/src/main/java/org/jnp/server/MainMBean.java
   projects/naming/branches/Branch_5_0/jnpserver/src/test/java/org/jnp/test/NamingTestSuite.java
Log:
[JBNAME-33] Expose the bootstrap URL

Modified: projects/naming/branches/Branch_5_0/jnpserver/src/main/java/org/jnp/server/Main.java
===================================================================
--- projects/naming/branches/Branch_5_0/jnpserver/src/main/java/org/jnp/server/Main.java	2009-05-11 22:14:55 UTC (rev 88677)
+++ projects/naming/branches/Branch_5_0/jnpserver/src/main/java/org/jnp/server/Main.java	2009-05-11 23:19:27 UTC (rev 88678)
@@ -26,6 +26,7 @@
 import java.io.ObjectOutputStream;
 import java.io.OutputStream;
 import java.lang.reflect.Method;
+import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
@@ -249,8 +250,37 @@
       else
          rmiBindAddress = InetAddress.getByName(host);
    }
-
    
+   /**
+    * Returns a URL suitable for use as a java.naming.provider.url value in
+    * a set of naming environment properties; i.e. one that can be used to 
+    * connect to the lookup socket.
+    * 
+    * @return the URL, or <code>null</code> if no bound lookup socket exists
+    */
+   public String getBootstrapURL()
+   {    
+      if (serverSocket == null || serverSocket.getInetAddress() == null)
+         return null;
+      
+      // Determine the bootstrap URL
+      StringBuilder sb = new StringBuilder("jnp://");
+      InetAddress addr = serverSocket.getInetAddress();
+      if (addr instanceof Inet6Address)
+      {
+         sb.append('[');
+         sb.append(addr.getHostAddress());
+         sb.append(']');
+      }
+      else
+      {
+         sb.append(addr.getHostAddress());
+      }
+      sb.append(':');
+      sb.append(port);
+      return sb.toString();
+   }
+   
    public boolean isEnableRmiServerHostname()
    {
       return enableRmiServerHostname;

Modified: projects/naming/branches/Branch_5_0/jnpserver/src/main/java/org/jnp/server/MainMBean.java
===================================================================
--- projects/naming/branches/Branch_5_0/jnpserver/src/main/java/org/jnp/server/MainMBean.java	2009-05-11 22:14:55 UTC (rev 88677)
+++ projects/naming/branches/Branch_5_0/jnpserver/src/main/java/org/jnp/server/MainMBean.java	2009-05-11 23:19:27 UTC (rev 88678)
@@ -53,6 +53,15 @@
 
    void setBacklog(int backlog);   
    int getBacklog();
+   
+   /**
+    * Returns a URL suitable for use as a java.naming.provider.url value in
+    * a set of naming environment properties; i.e. one that can be used to 
+    * connect to the lookup socket.
+    * 
+    * @return the URL, or <code>null</code> if no bound lookup socket exists
+    */
+   String getBootstrapURL();
 
    public NamingBean getNamingInfo();
    /**

Added: projects/naming/branches/Branch_5_0/jnpserver/src/test/java/org/jnp/test/BootstrapURLUnitTest.java
===================================================================
--- projects/naming/branches/Branch_5_0/jnpserver/src/test/java/org/jnp/test/BootstrapURLUnitTest.java	                        (rev 0)
+++ projects/naming/branches/Branch_5_0/jnpserver/src/test/java/org/jnp/test/BootstrapURLUnitTest.java	2009-05-11 23:19:27 UTC (rev 88678)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jnp.test;
+
+import junit.framework.Test;
+
+import org.jboss.test.BaseTestCase;
+import org.jnp.server.Main;
+import org.jnp.server.NamingBeanImpl;
+
+/**
+ *
+ *
+ * @author Brian Stansberry
+ * 
+ * @version $Revision: $
+ */
+public class BootstrapURLUnitTest extends BaseTestCase
+{
+   
+   /** The actual namingMain service impl bean */
+   private static NamingBeanImpl namingBean;
+
+   private Main namingMain;
+   
+   /**
+    * Create a new BootstrapURLUnitTest.
+    * 
+    * @param name
+    */
+   public BootstrapURLUnitTest(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(BootstrapURLUnitTest.class);
+   }
+   
+   
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      if (namingBean == null)
+      {
+         namingBean = new NamingBeanImpl();
+         namingBean.start();
+      }
+      namingMain = new Main("org.jnp.server");
+      namingMain.setNamingInfo(namingBean);
+   }
+   
+   
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+      
+      if (namingMain != null)
+      {
+         namingMain.stop();
+      }
+   }
+
+   public void testLocalhost() throws Exception
+   {
+      namingMain.setPort(0);
+      namingMain.setBindAddress("127.0.0.1");
+      namingMain.start();
+      int port = namingMain.getPort();
+      assertTrue(port > 0);
+      assertEquals("jnp://127.0.0.1:" + port, namingMain.getBootstrapURL());
+   }
+
+   public void testIPv6Localhost() throws Exception
+   {
+      namingMain.setPort(0);
+      namingMain.setBindAddress("::1");
+      namingMain.start();
+      int port = namingMain.getPort();
+      assertTrue(port > 0);
+      assertEquals("jnp://[0:0:0:0:0:0:0:1]:" + port, namingMain.getBootstrapURL());
+   }
+   
+   public void testAnyAddress() throws Exception
+   {
+      namingMain.setPort(0);
+      namingMain.setBindAddress("0.0.0.0");
+      namingMain.start();
+      int port = namingMain.getPort();
+      assertTrue(port > 0);
+      assertEquals("jnp://0.0.0.0:" + port, namingMain.getBootstrapURL());      
+   }
+   
+   public void testNoServerSocket() throws Exception
+   {
+      namingMain.setPort(-1);
+      namingMain.setBindAddress("localhost");
+      namingMain.start(); 
+      assertNull(namingMain.getBootstrapURL());
+   }
+
+}


Property changes on: projects/naming/branches/Branch_5_0/jnpserver/src/test/java/org/jnp/test/BootstrapURLUnitTest.java
___________________________________________________________________
Name: svn:keywords
   + 

Modified: projects/naming/branches/Branch_5_0/jnpserver/src/test/java/org/jnp/test/NamingTestSuite.java
===================================================================
--- projects/naming/branches/Branch_5_0/jnpserver/src/test/java/org/jnp/test/NamingTestSuite.java	2009-05-11 22:14:55 UTC (rev 88677)
+++ projects/naming/branches/Branch_5_0/jnpserver/src/test/java/org/jnp/test/NamingTestSuite.java	2009-05-11 23:19:27 UTC (rev 88678)
@@ -48,6 +48,7 @@
       suite.addTest(NamingServerSecurityManagerUnitTest.suite());
       suite.addTest(TestJNPSockets.suite());
       suite.addTest(NamingContextUnitTest.suite());
+      suite.addTest(BootstrapURLUnitTest.suite());
       
       return suite;
    }




More information about the jboss-cvs-commits mailing list