Permalink
Browse files

removed duplicate url validation

  • Loading branch information...
1 parent 0840aef commit 93f9066aa8497e1b5a1d65dec00deb8c25699223 @mausch mausch committed Dec 23, 2011
@@ -34,6 +34,7 @@
using SolrNet.Mapping.Validation;
using SolrNet.Mapping.Validation.Rules;
using SolrNet.Schema;
+using SolrNet.Utils;
namespace AutofacContrib.SolrNet {
/// <summary>
@@ -192,7 +193,7 @@ public class SolrNetModule : Module {
var id = server.Id ?? Guid.NewGuid().ToString();
var documentType = GetCoreDocumentType(server);
var coreUrl = GetCoreUrl(server);
- ValidateUrl(coreUrl);
+ UriValidator.ValidateHTTP(coreUrl);
return new SolrCore(id, documentType, coreUrl);
}
@@ -222,17 +223,5 @@ public class SolrNetModule : Module {
return type;
}
-
- private static void ValidateUrl(string url) {
- try {
- var u = new Uri(url);
- if (u.Scheme != Uri.UriSchemeHttp && u.Scheme != Uri.UriSchemeHttps)
- throw new InvalidURLException("Only HTTP or HTTPS protocols are supported");
- } catch (ArgumentException e) {
- throw new InvalidURLException(string.Format("Invalid URL '{0}'", url), e);
- } catch (UriFormatException e) {
- throw new InvalidURLException(string.Format("Invalid URL '{0}'", url), e);
- }
- }
}
}
@@ -30,8 +30,9 @@
using SolrNet.Mapping;
using SolrNet.Mapping.Validation;
using SolrNet.Mapping.Validation.Rules;
-using SolrNet.Schema;
-
+using SolrNet.Schema;
+using SolrNet.Utils;
+
namespace Castle.Facilities.SolrNetIntegration {
/// <summary>
/// Configures SolrNet in a Windsor container
@@ -53,8 +54,8 @@ public class SolrNetFacility : AbstractFacility {
/// Configures SolrNet in a Windsor container
/// </summary>
/// <param name="solrURL"></param>
- public SolrNetFacility(string solrURL) {
- ValidateUrl(solrURL);
+ public SolrNetFacility(string solrURL) {
+ UriValidator.ValidateHTTP(solrURL);
this.solrURL = solrURL;
}
@@ -66,8 +67,8 @@ public class SolrNetFacility : AbstractFacility {
var configNode = FacilityConfig.Children["solrURL"];
if (configNode == null)
throw new FacilityException("Please add solrURL to the SolrNetFacility configuration");
- var url = configNode.Value;
- ValidateUrl(url);
+ var url = configNode.Value;
+ UriValidator.ValidateHTTP(url);
return url;
}
@@ -163,18 +164,6 @@ public class SolrNetFacility : AbstractFacility {
.ServiceOverrides(ServiceOverride.ForKey("basicServer").Eq(core.Id + SolrBasicServer)));
}
- private static void ValidateUrl(string url) {
- try {
- var u = new Uri(url);
- if (u.Scheme != Uri.UriSchemeHttp && u.Scheme != Uri.UriSchemeHttps)
- throw new FacilityException("Only HTTP or HTTPS protocols are supported");
- } catch (ArgumentException e) {
- throw new FacilityException(string.Format("Invalid URL '{0}'", url), e);
- } catch (UriFormatException e) {
- throw new FacilityException(string.Format("Invalid URL '{0}'", url), e);
- }
- }
-
/// <summary>
/// Adds a new core configuration to the facility
/// </summary>
@@ -190,8 +179,8 @@ public class SolrNetFacility : AbstractFacility {
/// <param name="coreId">Component name for <see cref="ISolrOperations{T}"/></param>
/// <param name="documentType"></param>
/// <param name="coreUrl"></param>
- public void AddCore(string coreId, Type documentType, string coreUrl) {
- ValidateUrl(coreUrl);
+ public void AddCore(string coreId, Type documentType, string coreUrl) {
+ UriValidator.ValidateHTTP(coreUrl);
cores.Add(new SolrCore(coreId, documentType, coreUrl));
}
@@ -17,9 +17,9 @@ public static class UriValidator {
throw new InvalidURLException("Only HTTP or HTTPS protocols are supported");
return s;
} catch (ArgumentException e) {
- throw new InvalidURLException(e);
+ throw new InvalidURLException(string.Format("Invalid URL '{0}'", s), e);
} catch (UriFormatException e) {
- throw new InvalidURLException(e);
+ throw new InvalidURLException(string.Format("Invalid URL '{0}'", s), e);
}
}
}
@@ -13,7 +13,8 @@
using SolrNet.Mapping;
using SolrNet.Mapping.Validation;
using SolrNet.Mapping.Validation.Rules;
-using SolrNet.Schema;
+using SolrNet.Schema;
+using SolrNet.Utils;
using StructureMap.SolrNetIntegration.Config;
namespace StructureMap.SolrNetIntegration
@@ -133,8 +134,8 @@ private static SolrCore GetCoreFrom(SolrServerElement server)
{
var id = server.Id ?? Guid.NewGuid().ToString();
var documentType = GetCoreDocumentType(server);
- var coreUrl = GetCoreUrl(server);
- ValidateUrl(coreUrl);
+ var coreUrl = GetCoreUrl(server);
+ UriValidator.ValidateHTTP(coreUrl);
return new SolrCore(id, documentType, coreUrl);
}
@@ -169,23 +170,5 @@ private static Type GetCoreDocumentType(SolrServerElement server)
return type;
}
-
- private static void ValidateUrl(string url)
- {
- try
- {
- var u = new Uri(url);
- if (u.Scheme != Uri.UriSchemeHttp && u.Scheme != Uri.UriSchemeHttps)
- throw new InvalidURLException("Only HTTP or HTTPS protocols are supported");
- }
- catch (ArgumentException e)
- {
- throw new InvalidURLException(string.Format("Invalid URL '{0}'", url), e);
- }
- catch (UriFormatException e)
- {
- throw new InvalidURLException(string.Format("Invalid URL '{0}'", url), e);
- }
- }
}
}
@@ -16,7 +16,8 @@
using SolrNet.Mapping;
using SolrNet.Mapping.Validation;
using SolrNet.Mapping.Validation.Rules;
-using SolrNet.Schema;
+using SolrNet.Schema;
+using SolrNet.Utils;
using Unity.SolrNetIntegration.Config;
namespace Unity.SolrNetIntegration {
@@ -152,8 +153,8 @@ public class SolrNetContainerConfiguration {
private static SolrCore GetCoreFrom(SolrServerElement server) {
var id = server.Id ?? Guid.NewGuid().ToString();
var documentType = GetCoreDocumentType(server);
- var coreUrl = GetCoreUrl(server);
- ValidateUrl(coreUrl);
+ var coreUrl = GetCoreUrl(server);
+ UriValidator.ValidateHTTP(coreUrl);
return new SolrCore(id, documentType, coreUrl);
}
@@ -185,18 +186,5 @@ public class SolrNetContainerConfiguration {
return type;
}
-
- private static void ValidateUrl(string url) {
- try {
- var uri = new Uri(url);
- if (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps) {
- throw new InvalidURLException("Only HTTP or HTTPS protocols are supported");
- }
- } catch (ArgumentException e) {
- throw new InvalidURLException(string.Format("Invalid URL '{0}'", url), e);
- } catch (UriFormatException e) {
- throw new InvalidURLException(string.Format("Invalid URL '{0}'", url), e);
- }
- }
}
}

0 comments on commit 93f9066

Please sign in to comment.