in client/src/main/java/org/apache/qpid/client/BrokerDetails.java [121:277]
public BrokerDetails(String url) throws URLSyntaxException
{
// URL should be of format tcp://host:port?option='value',option='value'
try
{
URI connection = new URI(url);
String transport = connection.getScheme();
// Handles some defaults to minimise changes to existing broker URLS e.g. localhost
if (transport != null)
{
//todo this list of valid transports should be enumerated somewhere
if (!(transport.equalsIgnoreCase(BrokerDetails.TCP) || transport.equalsIgnoreCase(BrokerDetails.SOCKET)))
{
if (transport.equalsIgnoreCase("localhost"))
{
connection = new URI(DEFAULT_TRANSPORT + "://" + url);
transport = connection.getScheme();
}
else
{
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);
transport = connection.getScheme();
}
else
{
throw URLHelper.parseError(0, transport.length(), "Unknown transport", url);
}
}
}
else if (url.indexOf("//") == -1)
{
throw new URLSyntaxException(url, "Missing '//' after the transport In broker URL",transport.length()+1,1);
}
}
else
{
//Default the transport
connection = new URI(DEFAULT_TRANSPORT + "://" + url);
transport = connection.getScheme();
}
if (transport == null)
{
throw URLHelper.parseError(-1, "Unknown transport in broker URL:'"
+ url + "' Format: " + URL_FORMAT_EXAMPLE, "");
}
setTransport(transport);
String host = connection.getHost();
// Fix for Java 1.5
if (host == null)
{
host = "";
String auth = connection.getAuthority();
if (auth != null)
{
// contains both host & port myhost:5672
if (auth.contains(":"))
{
host = auth.substring(0,auth.indexOf(":"));
}
else
{
host = auth;
}
}
}
setHost(host);
int port = connection.getPort();
if (port == -1)
{
// Fix for when there is port data but it is not automatically parseable by getPort().
String auth = connection.getAuthority();
if (auth != null && auth.contains(":"))
{
int start = auth.indexOf(":") + 1;
int end = start;
boolean looking = true;
boolean found = false;
// Throw an URL exception if the port number is not specified
if (start == auth.length())
{
throw URLHelper.parseError(connection.toString().indexOf(auth) + end - 1,
connection.toString().indexOf(auth) + end, "Port number must be specified",
connection.toString());
}
//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
{
throw URLHelper.parseError(connection.toString().indexOf(connection.getAuthority()) + end - 1,
"Illegal character in port number", connection.toString());
}
}
else
{
setPort(DEFAULT_PORT);
}
}
else
{
setPort(port);
}
String queryString = connection.getQuery();
URLHelper.parseOptions(_options, queryString);
//Fragment is #string (not used)
}
catch (URISyntaxException uris)
{
if (uris instanceof URLSyntaxException)
{
throw(URLSyntaxException) uris;
}
throw URLHelper.parseError(uris.getIndex(), uris.getReason(), uris.getInput());
}
}