private static void processOptions(IConnectionInfo connectionInfo) { string brokerlist = connectionInfo.GetOption(ConnectionUrlConstants.OPTIONS_BROKERLIST); if (brokerlist != null) { //brokerlist tcp://host:port?option='value',option='value';vm://:3/virtualpath?option='value' Regex splitter = new Regex("" + URLHelper.BROKER_SEPARATOR); foreach (string broker in splitter.Split(brokerlist)) { connectionInfo.AddBrokerInfo(new AmqBrokerInfo(broker)); } connectionInfo.SetOption(ConnectionUrlConstants.OPTIONS_BROKERLIST, null); // _options.remove(OPTIONS_BROKERLIST); } string failover = connectionInfo.GetOption(ConnectionUrlConstants.OPTIONS_FAILOVER); if (failover != null) { // failover='method?option='value',option='value'' int methodIndex = failover.IndexOf('?'); if (methodIndex > -1) { connectionInfo.FailoverMethod = failover.Substring(0, methodIndex); QpidConnectionInfo qpidConnectionInfo = (QpidConnectionInfo)connectionInfo; URLHelper.parseOptions(qpidConnectionInfo.GetFailoverOptions(), failover.Substring(methodIndex + 1)); } else { connectionInfo.FailoverMethod = failover; } connectionInfo.SetOption(ConnectionUrlConstants.OPTIONS_FAILOVER, null); // _options.remove(OPTIONS_FAILOVER); } }
internal static IConnectionInfo FromUrl(string fullURL) { //_url = fullURL; IConnectionInfo connectionInfo = new QpidConnectionInfo(); // _options = new HashMap<String, String>(); // _brokers = new LinkedList(); // _failoverOptions = new HashMap<String, String>(); // Connection URL format //amqp://[user:pass@][clientid]/virtualhost?brokerlist='tcp://host:port?option=\'value\',option=\'value\';vm://:3/virtualpath?option=\'value\'',failover='method?option=\'value\',option='value''" // Options are of course optional except for requiring a single broker in the broker list. try { Uri connection = new Uri(fullURL); if (connection.Scheme == null || !(connection.Scheme.Equals(ConnectionUrlConstants.AMQ_PROTOCOL))) { throw new UrlSyntaxException(fullURL, "Not an AMQP URL"); } if (connection.Host != null && connection.Host.Length > 0 && !connection.Host.Equals("default")) { connectionInfo.ClientName = connection.Host; } String userInfo = connection.UserInfo; if (userInfo == null || userInfo.Length == 0) { URLHelper.parseError(ConnectionUrlConstants.AMQ_PROTOCOL.Length + 3, "User information not found on url", fullURL); } else { parseUserInfo(userInfo, fullURL, connectionInfo); } String virtualHost = connection.AbsolutePath; // XXX: is AbsolutePath corrrect? if (virtualHost != null && virtualHost.Length > 0) { connectionInfo.VirtualHost = virtualHost; } else { int authLength = connection.Authority.Length; int start = ConnectionUrlConstants.AMQ_PROTOCOL.Length + 3; int testIndex = start + authLength; if (testIndex < fullURL.Length && fullURL[testIndex] == '?') { URLHelper.parseError(start, testIndex - start, "Virtual host found", fullURL); } else { URLHelper.parseError(-1, "Virtual host not specified", fullURL); } } QpidConnectionInfo qci = (QpidConnectionInfo)connectionInfo; string query = connection.Query; if (query[0] == '?') { query = query.Substring(1); } URLHelper.parseOptions(qci.GetOptions(), query); processOptions(connectionInfo); //Fragment is #string (not used) //System.out.println(connection.getFragment()); return(connectionInfo); } catch (UriFormatException uris) { throw uris; // if (uris is UrlSyntaxException) // { // throw uris; // } // // int slash = fullURL.IndexOf("\\"); // // if (slash == -1) // { // URLHelper.parseError(uris.GetIndex(), uris.getReason(), uris.getInput()); // } // else // { // if (slash != 0 && fullURL.charAt(slash - 1) == ':') // { // URLHelper.parseError(slash - 2, fullURL.indexOf('?') - slash + 2, "Virtual host looks like a windows path, forward slash not allowed in URL", fullURL); // } // else // { // URLHelper.parseError(slash, "Forward slash not allowed in URL", fullURL); // } // } } }