--- jboss-eap-4.3-src/jboss-as/naming/src/main/org/jnp/interfaces/NamingContext.java	2009-05-27 12:00:58.000000000 -0400
+++ jboss-eap-4.3-src-modified/jboss-as/naming/src/main/org/jnp/interfaces/NamingContext.java	2009-10-19 17:44:00.000000000 -0400
@@ -331,37 +331,63 @@
          while (tokenizer.hasMoreElements())
          {
             String url = tokenizer.nextToken();
-
             try
             {
-               // Parse the url into a host:port form, stripping any protocol
-               Name urlAsName = new NamingParser().parse(url);
-               String server = parseNameForScheme(urlAsName, null);
-               if (server != null)
-                  url = server;
-               int colon = url.indexOf(':');
-               if (colon < 0)
-               {
-                  host = url.trim();
-               }
-               else
-               {
-                  host = url.substring(0, colon).trim();
-                  try
-                  {
-                     port = Integer.parseInt(url.substring(colon + 1).trim());
-                  }
-                  catch (Exception ex)
-                  {
-                     // Use default;
-                  }
-               }
-
-               // Remove server from map
-               synchronized (NamingContext.class)
-               {
-                  cachedServers.remove(host + ":" + port);
-               }
+            	// Parse the url into a host:port form, stripping any protocol
+            	Name urlAsName = new NamingParser().parse(url);
+            	String server = parseNameForScheme(urlAsName, null);
+            	if (server != null)
+            		url = server;
+  
+            	// assume host port combinations <IPv4>, <IPv4>:port, [<IPv6>] or [<IPv6>]:port
+            	int colon = url.indexOf(':');
+            	int rightbracket = url.indexOf(']') ;
+            	int lastcolon = url.lastIndexOf(':') ;
+
+            	if (rightbracket < 0) {
+            		// assume IPv4 host port combination
+            		if (colon < 0)
+            		{
+            			host = url.trim();
+            		}
+            		else
+            		{
+            			host = url.substring(0, colon).trim();
+            			try
+            			{
+            				port = Integer.parseInt(url.substring(colon + 1).trim());
+            			}
+            			catch (Exception ex)
+            			{
+            				// Use default;
+            			}
+            		}
+            	}
+            	else {
+            		// assume IPv6 host port combination
+            		if (lastcolon < rightbracket)
+            		{
+            			host = url.substring(0,rightbracket+1).trim() ;
+            		}
+            		else
+            		{
+            			host = url.substring(0,rightbracket+1).trim() ;
+            			try
+            			{
+            				port = Integer.parseInt(url.substring(lastcolon + 1).trim());
+            			}
+            			catch (Exception ex)
+            			{
+            				// Use default;
+            			}
+            		}
+            	}
+
+            	// Remove server from map
+            	synchronized (NamingContext.class)
+            	{
+            		cachedServers.remove(host + ":" + port);
+            	}
             }
             catch (NamingException ignored)
             {
@@ -379,7 +405,7 @@
          }
       }
    }
-
+   
    /**
     * Called to remove any url scheme atoms and extract the naming service
     * hostname:port information.
@@ -1504,65 +1530,93 @@
 
             while (naming == null && tokenizer.hasMoreElements())
             {
-               String url = tokenizer.nextToken();
-               // Parse the url into a host:port form, stripping any protocol
-               Name urlAsName = getNameParser("").parse(url);
-               String server = parseNameForScheme(urlAsName, null);
-               if (server != null)
-                  url = server;
-               int colon = url.indexOf(':');
-               if (colon < 0)
-               {
-                  host = url;
-               }
-               else
-               {
-                  host = url.substring(0, colon).trim();
-                  try
-                  {
-                     port = Integer.parseInt(url.substring(colon + 1).trim());
-                  }
-                  catch (Exception ex)
-                  {
-                     // Use default;
-                  }
-               }
-               try
-               {
-                  // Get server from cache
-                  naming = getServer(host, port, refEnv);
-               }
-               catch (Exception e)
-               {
-                  serverEx = e;
-                  log.debug("Failed to connect to " + host + ":" + port, e);
-               }
+            	String url = tokenizer.nextToken();
+            	// Parse the url into a host:port form, stripping any protocol
+            	Name urlAsName = getNameParser("").parse(url);
+            	String server = parseNameForScheme(urlAsName, null);
+            	if (server != null)
+            		url = server;
+            	//
+            	// assume host port combinations <IPv4>, <IPv4>:port, [<IPv6>] or [<IPv6>]:port
+            	int colon = url.indexOf(':');
+            	int rightbracket = url.indexOf(']') ;
+            	int lastcolon = url.lastIndexOf(':') ;
+
+            	if (rightbracket < 0) {
+            		// assume IPv4 host port combination
+            		if (colon < 0)
+            		{
+            			host = url.trim();
+            		}
+            		else
+            		{
+            			host = url.substring(0, colon).trim();
+            			try
+            			{
+            				port = Integer.parseInt(url.substring(colon + 1).trim());
+            			}
+            			catch (Exception ex)
+            			{
+            				// Use default;
+            			}
+            		}
+            	}
+            	else {
+            		// assume IPv6 host port combination
+            		if (lastcolon < rightbracket)
+            		{
+            			host = url.substring(0,rightbracket+1).trim() ;
+            		}
+            		else
+            		{
+            			host = url.substring(0,rightbracket+1).trim() ;
+            			try
+            			{
+            				port = Integer.parseInt(url.substring(lastcolon + 1).trim());
+            			}
+            			catch (Exception ex)
+            			{
+            				// Use default;
+            			}
+            		}
+            	}
+
+            	try
+            	{
+            		// Get server from cache
+            		naming = getServer(host, port, refEnv);
+            	}
+            	catch (Exception e)
+            	{
+            		serverEx = e;
+            		log.debug("Failed to connect to " + host + ":" + port, e);
+            	}
             }
 
             // If there is still no
             Exception discoveryFailure = null;
             if (naming == null)
             {
-               try
-               {
-                  naming = discoverServer(refEnv);
-               }
-               catch (Exception e)
-               {
-                  discoveryFailure = e;
-                  if (serverEx == null)
-                     serverEx = e;
-               }
-               if (naming == null)
-               {
-                  StringBuffer buffer = new StringBuffer(50);
-                  buffer.append("Could not obtain connection to any of these urls: ").append(urls);
-                  if (discoveryFailure != null)
-                     buffer.append(" and discovery failed with error: ").append(discoveryFailure);
-                  CommunicationException ce = new CommunicationException(buffer.toString());
-                  ce.setRootCause(serverEx);
-                  throw ce;
-               }
+            	try
+            	{
+            		naming = discoverServer(refEnv);
+            	}
+            	catch (Exception e)
+            	{
+            		discoveryFailure = e;
+            		if (serverEx == null)
+            			serverEx = e;
+            	}
+            	if (naming == null)
+            	{
+            		StringBuffer buffer = new StringBuffer(50);
+            		buffer.append("Could not obtain connection to any of these urls: ").append(urls);
+            		if (discoveryFailure != null)
+            			buffer.append(" and discovery failed with error: ").append(discoveryFailure);
+            		CommunicationException ce = new CommunicationException(buffer.toString());
+            		ce.setRootCause(serverEx);
+            		throw ce;
+            	}
             }
          }
          else
