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
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,14 @@ public void RegisterRestPaths(Type requestType)

public void RegisterRestPath(RestPath restPath)
{
if (!restPath.Path.StartsWith("/"))
throw new ArgumentException("Route '{0}' on '{1}' must start with a '/'".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));
if (!EndpointHostConfig.SkipRouteValidation)
{
if (!restPath.Path.StartsWith("/"))
throw new ArgumentException("Route '{0}' on '{1}' must start with a '/'".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;
if (!RestPathMap.TryGetValue(restPath.FirstMatchHashKey, out pathsAtFirstMatch))
Expand Down
2 changes: 2 additions & 0 deletions src/ServiceStack/WebHost.Endpoints/EndpointHostConfig.cs
Original file line number Diff line number Diff line change
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 bool SkipPathValidation = false;
public static bool SkipRouteValidation = false;

public static string ServiceStackPath = null;

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

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

public class AlwaysThrowsService
: ServiceBase<AlwaysThrows>
public class AlwaysThrowsService : ServiceInterface.Service
{
protected override object Run(AlwaysThrows request)
public object Any(AlwaysThrows request)
{
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; }

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


[Route("inbox/{Id}/responses", "GET, PUT, OPTIONS")]
[Route("/inbox/{Id}/responses", "GET, PUT, OPTIONS")]
public class InboxPostResponseRequest
{
public int Id { get; set; }
Expand All @@ -363,9 +361,9 @@ public class PageElementResponseDTO
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)
{
Expand All @@ -385,9 +383,9 @@ public class InboxPost
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)
throw new ArgumentNullException("Throw");
Expand All @@ -400,9 +398,9 @@ protected override object Run(InboxPost request)
[Route("/long_running")]
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);

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

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

class UncachedProtoBufEmailService : ServiceBase<UncachedProtoBufEmail>
class UncachedProtoBufEmailService : ServiceInterface.Service
{
public IDbConnectionFactory DbFactory { get; set; }

public ICacheClient CacheClient { get; set; }

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

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

0 comments on commit 4060921

Please sign in to comment.