Skip to content

Commit

Permalink
Fix invalid routes in tests, add EHC.SkipRouteValitation option
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Mar 17, 2013
1 parent 12cca58 commit 4060921
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 35 deletions.
13 changes: 8 additions & 5 deletions src/ServiceStack/ServiceHost/ServiceController.cs
Expand Up @@ -172,11 +172,14 @@ public void RegisterRestPaths(Type requestType)


public void RegisterRestPath(RestPath restPath) public void RegisterRestPath(RestPath restPath)
{ {
if (!restPath.Path.StartsWith("/")) if (!EndpointHostConfig.SkipRouteValidation)
throw new ArgumentException("Route '{0}' on '{1}' must start with a '/'".Fmt(restPath.Path, restPath.RequestType.Name)); {
if (restPath.Path.IndexOfAny(InvalidRouteChars) != -1) if (!restPath.Path.StartsWith("/"))
throw new ArgumentException("Route '{0}' on '{1}' contains invalid chars. " + throw new ArgumentException("Route '{0}' on '{1}' must start with a '/'".Fmt(restPath.Path, restPath.RequestType.Name));
"See https://github.com/ServiceStack/ServiceStack/wiki/Routing for info on valid routes.".Fmt(restPath.Path, restPath.RequestType.Name)); if (restPath.Path.IndexOfAny(InvalidRouteChars) != -1)
throw new ArgumentException("Route '{0}' on '{1}' contains invalid chars. " +
"See https://github.com/ServiceStack/ServiceStack/wiki/Routing for info on valid routes.".Fmt(restPath.Path, restPath.RequestType.Name));
}


List<RestPath> pathsAtFirstMatch; List<RestPath> pathsAtFirstMatch;
if (!RestPathMap.TryGetValue(restPath.FirstMatchHashKey, out pathsAtFirstMatch)) if (!RestPathMap.TryGetValue(restPath.FirstMatchHashKey, out pathsAtFirstMatch))
Expand Down
2 changes: 2 additions & 0 deletions src/ServiceStack/WebHost.Endpoints/EndpointHostConfig.cs
Expand Up @@ -33,6 +33,8 @@ public class EndpointHostConfig
public static readonly string LicensePublicKey = "<RSAKeyValue><Modulus>19kx2dJoOIrMYypMTf8ssiCALJ7RS/Iz2QG0rJtYJ2X0+GI+NrgOCapkh/9aDVBieobdClnuBgW08C5QkfBdLRqsptiSu50YIqzVaNBMwZPT0e7Ke02L/fV/M/fVPsolHwzMstKhdWGdK8eNLF4SsLEcvnb79cx3/GnZbXku/ro5eOrTseKL3s4nM4SdMRNn7rEAU0o0Ijb3/RQbhab8IIRB4pHwk1mB+j/mcAQAtMerwpHfwpEBLWlQyVpu0kyKJCEkQjbaPzvfglDRpyBOT5GMUnrcTT/sBr5kSJYpYrgHnA5n4xJnvrnyFqdzXwgGFlikRTbc60pk1cQEWcHgYw==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>"; public static readonly string LicensePublicKey = "<RSAKeyValue><Modulus>19kx2dJoOIrMYypMTf8ssiCALJ7RS/Iz2QG0rJtYJ2X0+GI+NrgOCapkh/9aDVBieobdClnuBgW08C5QkfBdLRqsptiSu50YIqzVaNBMwZPT0e7Ke02L/fV/M/fVPsolHwzMstKhdWGdK8eNLF4SsLEcvnb79cx3/GnZbXku/ro5eOrTseKL3s4nM4SdMRNn7rEAU0o0Ijb3/RQbhab8IIRB4pHwk1mB+j/mcAQAtMerwpHfwpEBLWlQyVpu0kyKJCEkQjbaPzvfglDRpyBOT5GMUnrcTT/sBr5kSJYpYrgHnA5n4xJnvrnyFqdzXwgGFlikRTbc60pk1cQEWcHgYw==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";


public static bool SkipPathValidation = false; public static bool SkipPathValidation = false;
public static bool SkipRouteValidation = false;

public static string ServiceStackPath = null; public static string ServiceStackPath = null;


private static EndpointHostConfig instance; private static EndpointHostConfig instance;
Expand Down
Expand Up @@ -38,10 +38,9 @@ public class GetFactorialResponse
public long Result { get; set; } public long Result { get; set; }
} }


public class GetFactorialService public class GetFactorialService : IService
: IService<GetFactorial>
{ {
public object Execute(GetFactorial request) public object Any(GetFactorial request)
{ {
return new GetFactorialResponse { Result = GetFactorial(request.ForNumber) }; return new GetFactorialResponse { Result = GetFactorial(request.ForNumber) };
} }
Expand All @@ -62,10 +61,9 @@ public class AlwaysThrowsResponse : IHasResponseStatus
public ResponseStatus ResponseStatus { get; set; } public ResponseStatus ResponseStatus { get; set; }
} }


public class AlwaysThrowsService public class AlwaysThrowsService : ServiceInterface.Service
: ServiceBase<AlwaysThrows>
{ {
protected override object Run(AlwaysThrows request) public object Any(AlwaysThrows request)
{ {
throw new ArgumentException("This service always throws an error"); throw new ArgumentException("This service always throws an error");
} }
Expand Down Expand Up @@ -144,14 +142,14 @@ public class MovieResponse
} }




public class MovieService : RestServiceBase<Movie> public class MovieService : ServiceInterface.Service
{ {
public IDbConnectionFactory DbFactory { get; set; } public IDbConnectionFactory DbFactory { get; set; }


/// <summary> /// <summary>
/// GET /movies/{Id} /// GET /movies/{Id}
/// </summary> /// </summary>
public override object OnGet(Movie movie) public object Get(Movie movie)
{ {
return new MovieResponse { return new MovieResponse {
Movie = DbFactory.Run(db => db.GetById<Movie>(movie.Id)) Movie = DbFactory.Run(db => db.GetById<Movie>(movie.Id))
Expand All @@ -161,7 +159,7 @@ public override object OnGet(Movie movie)
/// <summary> /// <summary>
/// POST /movies /// POST /movies
/// </summary> /// </summary>
public override object OnPost(Movie movie) public object Post(Movie movie)
{ {
var newMovieId = DbFactory.Run(db => { var newMovieId = DbFactory.Run(db => {
db.Insert(movie); db.Insert(movie);
Expand All @@ -182,7 +180,7 @@ public override object OnPost(Movie movie)
/// <summary> /// <summary>
/// PUT /movies /// PUT /movies
/// </summary> /// </summary>
public override object OnPut(Movie movie) public object Put(Movie movie)
{ {
DbFactory.Run(db => db.Save(movie)); DbFactory.Run(db => db.Save(movie));
return new MovieResponse(); return new MovieResponse();
Expand All @@ -191,7 +189,7 @@ public override object OnPut(Movie movie)
/// <summary> /// <summary>
/// DELETE /movies/{Id} /// DELETE /movies/{Id}
/// </summary> /// </summary>
public override object OnDelete(Movie request) public object Delete(Movie request)
{ {
DbFactory.Run(db => db.DeleteById<Movie>(request.Id)); DbFactory.Run(db => db.DeleteById<Movie>(request.Id));
return new MovieResponse(); return new MovieResponse();
Expand Down Expand Up @@ -333,17 +331,17 @@ public class GetHttpResultResponse
public string Result { get; set; } public string Result { get; set; }
} }


public class HttpResultService : IService<GetHttpResult> public class HttpResultService : IService
{ {
public object Execute(GetHttpResult request) public object Any(GetHttpResult request)
{ {
var getHttpResultResponse = new GetHttpResultResponse { Result = "result" }; var getHttpResultResponse = new GetHttpResultResponse { Result = "result" };
return new HttpResult(getHttpResultResponse); return new HttpResult(getHttpResultResponse);
} }
} }




[Route("inbox/{Id}/responses", "GET, PUT, OPTIONS")] [Route("/inbox/{Id}/responses", "GET, PUT, OPTIONS")]
public class InboxPostResponseRequest public class InboxPostResponseRequest
{ {
public int Id { get; set; } public int Id { get; set; }
Expand All @@ -363,9 +361,9 @@ public class PageElementResponseDTO
public string PageElementResponse { get; set; } public string PageElementResponse { get; set; }
} }


public class InboxPostResponseRequestService : ServiceBase<InboxPostResponseRequest> public class InboxPostResponseRequestService : ServiceInterface.Service
{ {
protected override object Run(InboxPostResponseRequest request) public object Any(InboxPostResponseRequest request)
{ {
if (request.Responses == null || request.Responses.Count == 0) if (request.Responses == null || request.Responses.Count == 0)
{ {
Expand All @@ -385,9 +383,9 @@ public class InboxPost
public int Id { get; set; } public int Id { get; set; }
} }


public class InboxPostService : ServiceBase<InboxPost> public class InboxPostService : ServiceInterface.Service
{ {
protected override object Run(InboxPost request) public object Any(InboxPost request)
{ {
if (request.Throw) if (request.Throw)
throw new ArgumentNullException("Throw"); throw new ArgumentNullException("Throw");
Expand All @@ -400,9 +398,9 @@ protected override object Run(InboxPost request)
[Route("/long_running")] [Route("/long_running")]
public class LongRunning { } public class LongRunning { }


public class LongRunningService : ServiceBase<LongRunning> public class LongRunningService : ServiceInterface.Service
{ {
protected override object Run(LongRunning request) public object Any(LongRunning request)
{ {
Thread.Sleep(5000); Thread.Sleep(5000);


Expand Down
@@ -1,9 +1,6 @@
using System.Runtime.Serialization; using System.Runtime.Serialization;
using ServiceStack.CacheAccess;
using ServiceStack.Common; using ServiceStack.Common;
using ServiceStack.OrmLite;
using ServiceStack.ServiceHost; using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface;
using ServiceStack.WebHost.IntegrationTests.Tests; using ServiceStack.WebHost.IntegrationTests.Tests;


namespace ServiceStack.WebHost.IntegrationTests.Services namespace ServiceStack.WebHost.IntegrationTests.Services
Expand All @@ -26,21 +23,17 @@ public class UncachedProtoBufEmail
public string FromAddress { get; set; } public string FromAddress { get; set; }
} }


class UncachedProtoBufEmailService : ServiceBase<UncachedProtoBufEmail> class UncachedProtoBufEmailService : ServiceInterface.Service
{ {
public IDbConnectionFactory DbFactory { get; set; } public object Any(UncachedProtoBufEmail request)

public ICacheClient CacheClient { get; set; }

protected override object Run(UncachedProtoBufEmail request)
{ {
return new ProtoBufEmail { FromAddress = request.FromAddress ?? "none" }; return new ProtoBufEmail { FromAddress = request.FromAddress ?? "none" };
} }
} }


class CachedProtoBufEmailService : ServiceInterface.Service class CachedProtoBufEmailService : ServiceInterface.Service
{ {
protected object Any(CachedProtoBufEmail request) public object Any(CachedProtoBufEmail request)
{ {
return base.RequestContext.ToOptimizedResultUsingCache(this.Cache, return base.RequestContext.ToOptimizedResultUsingCache(this.Cache,
UrnId.Create<ProtoBufEmail>(request.FromAddress ?? "none"), UrnId.Create<ProtoBufEmail>(request.FromAddress ?? "none"),
Expand Down

0 comments on commit 4060921

Please sign in to comment.