You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2006/11/28 14:06:40 UTC

svn commit: r480032 - /incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java

Author: ritchiem
Date: Tue Nov 28 05:06:39 2006
New Revision: 480032

URL: http://svn.apache.org/viewvc?view=rev&rev=480032
Log:
QPID-71
Update to handle bad characters after port value.

Modified:
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java?view=diff&rev=480032&r1=480031&r2=480032
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java Tue Nov 28 05:06:39 2006
@@ -56,7 +56,7 @@
             {
                 //todo this list of valid transports should be enumerated somewhere
                 if ((!(transport.equalsIgnoreCase("vm") ||
-                        transport.equalsIgnoreCase("tcp"))))
+                       transport.equalsIgnoreCase("tcp"))))
                 {
                     if (transport.equalsIgnoreCase("localhost"))
                     {
@@ -65,7 +65,7 @@
                     }
                     else
                     {
-                        if (url.charAt(transport.length()) == ':' && url.charAt(transport.length()+1) != '/' )
+                        if (url.charAt(transport.length()) == ':' && url.charAt(transport.length() + 1) != '/')
                         {
                             //Then most likely we have a host:port value
                             connection = new URI(DEFAULT_TRANSPORT + "://" + url);
@@ -88,7 +88,7 @@
             if (transport == null)
             {
                 URLHelper.parseError(-1, "Unknown transport:'" + transport + "'" +
-                        " In broker URL:'" + url + "' Format: " + URL_FORMAT_EXAMPLE, "");
+                                         " In broker URL:'" + url + "' Format: " + URL_FORMAT_EXAMPLE, "");
             }
 
             setTransport(transport);
@@ -107,12 +107,45 @@
 
             if (port == -1)
             {
-                // Another fix for Java 1.5 URI handling
+                // Fix for when there is port data but it is not automatically parseable by getPort().
                 String auth = connection.getAuthority();
 
-                if (auth != null && auth.startsWith(":"))
+                if (auth != null && auth.contains(":"))
                 {
-                    setPort(Integer.parseInt(auth.substring(1)));
+                    int start = auth.indexOf(":") + 1;
+                    int end = start;
+                    boolean looking = true;
+                    boolean found = false;
+                    //Walk the authority looking for a port value.
+                    while (looking)
+                    {
+                        try
+                        {
+                            end++;
+                            Integer.parseInt(auth.substring(start, end));
+
+                            if (end >= auth.length())
+                            {
+                                looking = false;
+                                found = true;
+                            }
+                        }
+                        catch (NumberFormatException nfe)
+                        {
+                            looking = false;
+                        }
+
+                    }
+                    if (found)
+                    {
+                        setPort(Integer.parseInt(auth.substring(start, end)));
+                    }
+                    else
+                    {
+                        URLHelper.parseError(connection.toString().indexOf(connection.getAuthority()) + end - 1,
+                                             "Illegal character in port number", connection.toString());
+                    }
+
                 }
                 else
                 {
@@ -134,7 +167,7 @@
         {
             if (uris instanceof URLSyntaxException)
             {
-                throw (URLSyntaxException) uris;
+                throw(URLSyntaxException) uris;
             }
 
             URLHelper.parseError(uris.getIndex(), uris.getReason(), uris.getInput());
@@ -245,9 +278,9 @@
         BrokerDetails bd = (BrokerDetails) o;
 
         return _host.equalsIgnoreCase(bd.getHost()) &&
-                (_port == bd.getPort()) &&
-                _transport.equalsIgnoreCase(bd.getTransport()) &&
-                (useSSL() == bd.useSSL());
+               (_port == bd.getPort()) &&
+               _transport.equalsIgnoreCase(bd.getTransport()) &&
+               (useSSL() == bd.useSSL());
 
         //todo do we need to compare all the options as well?
     }