Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Created ISession with SessionFactory provider using ICacheClient.

Can now share the same session between MVC and ServiceStack with ISession
Can now RequestContext.Get<IHttpResponse>()
Can now Filter = (req, res, dto) => req.TryResolve<IDependency>();
  • Loading branch information...
commit 490cbffd5e0253e3154da4207d40ace4867eb6b6 1 parent 4678449
@mythz mythz authored
Showing with 359 additions and 392 deletions.
  1. +1 −1  NuGet/ServiceStack.Common/servicestack.common.nuspec
  2. +1 −1  NuGet/ServiceStack.Host.AspNet/servicestack.host.aspnet.nuspec
  3. +14 −0 NuGet/ServiceStack.Host.Mvc/content/App_Start/ControllerBase.cs.pp
  4. +2 −0  NuGet/ServiceStack.Host.Mvc/content/App_Start/ServiceStackFramework.cs.pp
  5. +1 −1  NuGet/ServiceStack.Host.Mvc/servicestack.host.mvc.nuspec
  6. +1 −1  NuGet/ServiceStack/servicestack.nuspec
  7. +1 −1  src/RazorEngine/RazorHandler.cs
  8. +31 −0 src/ServiceStack.Interfaces/CacheAccess/ISession.cs
  9. +18 −0 src/ServiceStack.Interfaces/CacheAccess/ISessionFactory.cs
  10. +2 −0  src/ServiceStack.Interfaces/ServiceHost/IHttpRequest.cs
  11. +2 −0  src/ServiceStack.Interfaces/ServiceStack.Interfaces.csproj
  12. +22 −0 src/ServiceStack.ServiceInterface/ServiceBase.cs
  13. +1 −0  src/ServiceStack.ServiceInterface/ServiceStack.ServiceInterface.csproj
  14. +61 −0 src/ServiceStack.ServiceInterface/SessionFactory.cs
  15. +19 −6 src/ServiceStack.ServiceInterface/SessionFeature.cs
  16. +5 −0 src/ServiceStack.ServiceInterface/Testing/MockHttpRequest.cs
  17. +1 −1  src/ServiceStack.ServiceInterface/Testing/TestBase.cs
  18. +1 −1  src/ServiceStack/Properties/AssemblyInfo.cs
  19. +8 −4 src/ServiceStack/ServiceHost/HttpRequestContext.cs
  20. +2 −2 src/ServiceStack/WebHost.EndPoints/EndpointHost.cs
  21. +13 −3 src/ServiceStack/WebHost.EndPoints/Extensions/HttpListenerRequestWrapper.cs
  22. +13 −3 src/ServiceStack/WebHost.EndPoints/Extensions/HttpRequestWrapper.cs
  23. +1 −1  src/ServiceStack/WebHost.EndPoints/Extensions/HttpResponseWrapper.cs
  24. +1 −1  src/ServiceStack/WebHost.EndPoints/Extensions/IHttpResponseExtensions.cs
  25. +3 −3 src/ServiceStack/WebHost.EndPoints/GenericHandler.cs
  26. +1 −1  src/ServiceStack/WebHost.EndPoints/JsvSyncReplyHandler.cs
  27. +3 −3 src/ServiceStack/WebHost.EndPoints/RestHandler.cs
  28. +4 −3 src/ServiceStack/WebHost.EndPoints/Support/EndpointHandlerBase.cs
  29. +1 −1  src/ServiceStack/WebHost.EndPoints/Support/Markdown/MarkdownHandler.cs
  30. +5 −0 src/ServiceStack/WebHost.EndPoints/Support/Mocks/HttpRequestMock.cs
  31. +2 −2 src/ServiceStack/WebHost.EndPoints/Support/SoapHandler.cs
  32. +3 −4 tests/ServiceStack.Common.Tests/ReflectionUtilTests.cs
  33. +0 −4 tests/ServiceStack.Common.Tests/ServiceStack.Common.Tests.csproj
  34. +0 −226 tests/ServiceStack.Common.Tests/Support/InvokeSimpleCommandsTests.cs
  35. +0 −37 tests/ServiceStack.Common.Tests/Support/ModelWithFieldsOfDifferentTypes.cs
  36. +0 −27 tests/ServiceStack.Common.Tests/Support/ModelWithOnlyStringFields.cs
  37. +0 −31 tests/ServiceStack.Common.Tests/Support/PathInfoTests.cs
  38. +1 −1  tests/ServiceStack.ServiceHost.Tests/Formats/ViewTests.cs
  39. +22 −17 tests/ServiceStack.ServiceHost.Tests/Routes/SimpleRestServices.cs
  40. +5 −0 tests/ServiceStack.ServiceHost.Tests/ServiceStackHandlerUrlTests.cs
  41. +1 −1  tests/ServiceStack.WebHost.Endpoints.Tests/HttpResultTests.cs
  42. +1 −1  tests/ServiceStack.WebHost.Endpoints.Tests/Support/EndpointHandlerBaseTests.cs
  43. +5 −0 tests/ServiceStack.WebHost.IntegrationTests/Global.asax.cs
  44. +2 −0  tests/ServiceStack.WebHost.IntegrationTests/ServiceStack.WebHost.IntegrationTests.csproj
  45. +65 −0 tests/ServiceStack.WebHost.IntegrationTests/Services/SessionService.cs
  46. +10 −0 tests/ServiceStack.WebHost.IntegrationTests/Tests/SessionTests.cs
  47. +3 −3 tests/ServiceStack.WebHost.IntegrationTests/Web.config
View
2  NuGet/ServiceStack.Common/servicestack.common.nuspec
@@ -2,7 +2,7 @@
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>ServiceStack.Common</id>
- <version>3.1.3</version>
+ <version>3.1.6</version>
<authors>Demis Bellot</authors>
<owners>Demis Bellot</owners>
<summary>Opensource .NET and Mono REST Web Services framework</summary>
View
2  NuGet/ServiceStack.Host.AspNet/servicestack.host.aspnet.nuspec
@@ -2,7 +2,7 @@
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>ServiceStack.Host.AspNet</id>
- <version>3.1.5</version>
+ <version>3.1.6</version>
<authors>Demis Bellot</authors>
<owners>Demis Bellot</owners>
<summary>Opensource .NET and Mono REST Web Services framework</summary>
View
14 NuGet/ServiceStack.Host.Mvc/content/App_Start/ControllerBase.cs.pp
@@ -10,6 +10,20 @@
public abstract class ControllerBase : Controller
{
public ICacheClient Cache { get; set; }
+ public ISessionFactory SessionFactory { get; set; }
+
+ private ISession session;
+ public ISession Session
+ {
+ get
+ {
+ return session ?? (session =
+ SessionFactory.GetOrCreateSession(
+ new ServiceStack.WebHost.Endpoints.Extensions.HttpRequestWrapper(null, System.Web.HttpContext.Current.Request),
+ new ServiceStack.WebHost.Endpoints.Extensions.HttpResponseWrapper(System.Web.HttpContext.Current.Response)
+ ));
+ }
+ }
protected override JsonResult Json(object data, string contentType, Encoding contentEncoding, JsonRequestBehavior behavior)
{
View
2  NuGet/ServiceStack.Host.Mvc/content/App_Start/ServiceStackFramework.cs.pp
@@ -48,6 +48,8 @@
//Register In-Memory Cache provider.
//For Distributed Cache Providers Use: PooledRedisClientManager, BasicRedisClientManager or see: https://github.com/ServiceStack/ServiceStack/wiki/Caching
container.Register<ICacheClient>(new MemoryCacheClient());
+ container.Register<ISessionFactory>(c =>
+ new SessionFactory(c.Resolve<ICacheClient>()));
//Set MVC to use the same Funq IOC as ServiceStack
ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
View
2  NuGet/ServiceStack.Host.Mvc/servicestack.host.mvc.nuspec
@@ -2,7 +2,7 @@
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>ServiceStack.Host.Mvc</id>
- <version>3.1.5</version>
+ <version>3.1.6</version>
<authors>Demis Bellot</authors>
<owners>Demis Bellot</owners>
<summary>Opensource .NET and Mono REST Web Services framework</summary>
View
2  NuGet/ServiceStack/servicestack.nuspec
@@ -2,7 +2,7 @@
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>ServiceStack</id>
- <version>3.1.3</version>
+ <version>3.1.6</version>
<authors>Demis Bellot</authors>
<owners>Demis Bellot</owners>
<summary>Opensource .NET and Mono REST Web Services framework</summary>
View
2  src/RazorEngine/RazorHandler.cs
@@ -40,7 +40,7 @@ public override object CreateRequest(IHttpRequest request, string operationName)
return null;
}
- public override object GetResponse(IHttpRequest httpReq, object request)
+ public override object GetResponse(IHttpRequest httpReq, IHttpResponse httpRes, object request)
{
return null;
}
View
31 src/ServiceStack.Interfaces/CacheAccess/ISession.cs
@@ -0,0 +1,31 @@
+namespace ServiceStack.CacheAccess
+{
+ /// <summary>
+ /// A Users Session
+ /// </summary>
+ public interface ISession
+ {
+ /// <summary>
+ /// Store any object at key
+ /// </summary>
+ /// <param name="key"></param>
+ /// <returns></returns>
+ object this[string key] { get; set; }
+
+ /// <summary>
+ /// Set a typed value at key
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="key"></param>
+ /// <param name="value"></param>
+ void Set<T>(string key, T value);
+
+ /// <summary>
+ /// Get a typed value at key
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="key"></param>
+ /// <returns></returns>
+ T Get<T>(string key);
+ }
+}
View
18 src/ServiceStack.Interfaces/CacheAccess/ISessionFactory.cs
@@ -0,0 +1,18 @@
+using ServiceStack.ServiceHost;
+
+namespace ServiceStack.CacheAccess
+{
+ /// <summary>
+ /// Retrieves a User Session
+ /// </summary>
+ public interface ISessionFactory
+ {
+ /// <summary>
+ /// Gets the session for this request, creates one if it doesn't exist.
+ /// </summary>
+ /// <param name="httpReq"></param>
+ /// <param name="httpRes"></param>
+ /// <returns></returns>
+ ISession GetOrCreateSession(IHttpRequest httpReq, IHttpResponse httpRes);
+ }
+}
View
2  src/ServiceStack.Interfaces/ServiceHost/IHttpRequest.cs
@@ -10,6 +10,8 @@ public interface IHttpRequest
{
object OriginalRequest { get; }
+ T TryResolve<T>();
+
string OperationName { get; }
string ContentType { get; }
View
2  src/ServiceStack.Interfaces/ServiceStack.Interfaces.csproj
@@ -83,6 +83,8 @@
<Compile Include="CacheAccess\IMemcachedClient.cs" />
<Compile Include="CacheAccess\IPersistenceProviderCache.cs" />
<Compile Include="CacheAccess\IPersistenceProviderCacheFactory.cs" />
+ <Compile Include="CacheAccess\ISession.cs" />
+ <Compile Include="CacheAccess\ISessionFactory.cs" />
<Compile Include="Configuration\IFactoryProvider.cs" />
<Compile Include="Configuration\IContainerAdapter.cs" />
<Compile Include="Configuration\IResourceManager.cs" />
View
22 src/ServiceStack.ServiceInterface/ServiceBase.cs
@@ -1,5 +1,8 @@
using System;
using System.Net;
+using System.Web;
+using ServiceStack.CacheAccess;
+using ServiceStack.CacheAccess.Providers;
using ServiceStack.Common;
using ServiceStack.Common.Utils;
using ServiceStack.Common.Web;
@@ -10,6 +13,7 @@
using ServiceStack.ServiceInterface.ServiceModel;
using ServiceStack.Text;
using ServiceStack.WebHost.Endpoints;
+using ServiceStack.WebHost.Endpoints.Extensions;
namespace ServiceStack.ServiceInterface
{
@@ -73,6 +77,24 @@ public virtual IAppHost AppHost
public IRequestContext RequestContext { get; set; }
+ public ISessionFactory SessionFactory { get; set; }
+
+ private ISession session;
+ public ISession Session
+ {
+ get
+ {
+ if (SessionFactory == null)
+ SessionFactory = new SessionFactory(this.GetCacheClient());
+
+ return session ?? (session =
+ SessionFactory.GetOrCreateSession(
+ RequestContext.Get<IHttpRequest>(),
+ RequestContext.Get<IHttpResponse>()
+ ));
+ }
+ }
+
/// <summary>
/// Resolve an alternate Web Service from ServiceStack's IOC container.
/// </summary>
View
1  src/ServiceStack.ServiceInterface/ServiceStack.ServiceInterface.csproj
@@ -132,6 +132,7 @@
<Compile Include="Deprecated.Session\PublicAndPrivateClientSessions.cs" />
<Compile Include="Deprecated.Session\UserSession.cs" />
<Compile Include="ServiceRoutesExtension.cs" />
+ <Compile Include="SessionFactory.cs" />
<Compile Include="SessionFeature.cs" />
<Compile Include="Testing\BasicAppHost.cs" />
<Compile Include="Testing\MockHttpRequest.cs">
View
61 src/ServiceStack.ServiceInterface/SessionFactory.cs
@@ -0,0 +1,61 @@
+using System;
+using ServiceStack.CacheAccess;
+using ServiceStack.ServiceHost;
+using ServiceStack.Text;
+using ServiceStack.Text.Common;
+
+namespace ServiceStack.ServiceInterface
+{
+ public class SessionFactory : ISessionFactory
+ {
+ private readonly ICacheClient cacheClient;
+
+ public SessionFactory(ICacheClient cacheClient)
+ {
+ this.cacheClient = cacheClient;
+ }
+
+ public class SessionCacheClient : ISession
+ {
+ private readonly ICacheClient cacheClient;
+ private string prefixNs;
+
+ public SessionCacheClient(ICacheClient cacheClient, string sessionId)
+ {
+ this.cacheClient = cacheClient;
+ this.prefixNs = "sess:" + sessionId + ":";
+ }
+
+ public object this[string key]
+ {
+ get
+ {
+ return cacheClient.Get<object>(this.prefixNs + key);
+ }
+ set
+ {
+ JsWriter.WriteDynamic(() =>
+ cacheClient.Set(this.prefixNs + key, value));
+ }
+ }
+
+ public void Set<T>(string key, T value)
+ {
+ cacheClient.Set(this.prefixNs + key, value);
+ }
+
+ public T Get<T>(string key)
+ {
+ return cacheClient.Get<T>(this.prefixNs + key);
+ }
+ }
+
+ public ISession GetOrCreateSession(IHttpRequest httpReq, IHttpResponse httpRes)
+ {
+ var sessionId = httpReq.GetCookieValue(SessionFeature.PermanentSessionId)
+ ?? httpRes.CreatePermanentSessionId(httpReq);
+
+ return new SessionCacheClient(cacheClient, sessionId);
+ }
+ }
+}
View
25 src/ServiceStack.ServiceInterface/SessionFeature.cs
@@ -21,15 +21,11 @@ public static void Init(IAppHost appHost)
appHost.RequestFilters.Add((req, res, dto) => {
if (req.GetCookieValue(SessionId) == null)
{
- var sessionId = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
- res.SetSessionCookie(SessionId, sessionId);
- req.Items[SessionId] = sessionId;
+ res.CreateTemporarySessionId(req);
}
if (req.GetCookieValue(PermanentSessionId) == null)
{
- var permanentId = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
- res.SetPermanentCookie(PermanentSessionId, permanentId);
- req.Items[PermanentSessionId] = permanentId;
+ res.CreatePermanentSessionId(req);
}
});
}
@@ -43,5 +39,22 @@ public static string GetTemporarySessionId(this IHttpRequest httpReq)
{
return httpReq.GetItemOrCookie(SessionId);
}
+
+ public static string CreatePermanentSessionId(this IHttpResponse res, IHttpRequest req)
+ {
+ var sessionId = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
+ res.SetPermanentCookie(PermanentSessionId, sessionId);
+ req.Items[PermanentSessionId] = sessionId;
+ return sessionId;
+ }
+
+ public static string CreateTemporarySessionId(this IHttpResponse res, IHttpRequest req)
+ {
+ var sessionId = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
+ res.SetSessionCookie(SessionId, sessionId);
+ req.Items[SessionId] = sessionId;
+ return sessionId;
+ }
+
}
}
View
5 src/ServiceStack.ServiceInterface/Testing/MockHttpRequest.cs
@@ -37,6 +37,11 @@ public object OriginalRequest
get { return null; }
}
+ public T TryResolve<T>()
+ {
+ throw new NotImplementedException();
+ }
+
public string OperationName { get; set; }
public string ContentType { get; set; }
public string HttpMethod { get; set; }
View
2  src/ServiceStack.ServiceInterface/Testing/TestBase.cs
@@ -332,7 +332,7 @@ public TResponse ExecutePath<TResponse>(string httpMethod, string pathInfo, obje
);
var request = httpHandler.CreateRequest(httpReq, httpHandler.RequestName);
- var response = httpHandler.GetResponse(httpReq, request);
+ var response = httpHandler.GetResponse(httpReq, null, request);
var httpRes = response as IHttpResult;
if (httpRes != null)
View
2  src/ServiceStack/Properties/AssemblyInfo.cs
@@ -33,5 +33,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("3.1.3.*")]
+[assembly: AssemblyVersion("3.1.6.*")]
//[assembly: AssemblyFileVersion("1.0.*")]
View
12 src/ServiceStack/ServiceHost/HttpRequestContext.cs
@@ -11,6 +11,7 @@ public class HttpRequestContext
: IRequestContext
{
private readonly IHttpRequest httpReq;
+ private readonly IHttpResponse httpRes;
public HttpRequestContext(object dto)
: this(dto, null)
@@ -22,15 +23,16 @@ public HttpRequestContext(object dto, EndpointAttributes endpointAttributes)
{
}
- public HttpRequestContext(IHttpRequest httpReq, object dto)
- : this(httpReq, dto, EndpointAttributes.None)
+ public HttpRequestContext(IHttpRequest httpReq, IHttpResponse httpRes, object dto)
+ : this(httpReq, httpRes, dto, EndpointAttributes.None)
{
}
- public HttpRequestContext(IHttpRequest httpReq, object dto, EndpointAttributes endpointAttributes)
+ public HttpRequestContext(IHttpRequest httpReq, IHttpResponse httpRes, object dto, EndpointAttributes endpointAttributes)
: this(dto, endpointAttributes, null)
{
this.httpReq = httpReq;
+ this.httpRes = httpRes;
if (this.httpReq != null)
{
this.Files = httpReq.Files;
@@ -83,7 +85,9 @@ public string ResponseContentType
public T Get<T>() where T : class
{
if (typeof(T) == typeof(IHttpRequest))
- return (T) this.httpReq;
+ return (T)this.httpReq;
+ if (typeof(T) == typeof(IHttpResponse))
+ return (T)this.httpRes;
var isDto = this.Dto as T;
return isDto ?? (this.Factory != null ? this.Factory.Resolve<T>() : null);
View
4 src/ServiceStack/WebHost.EndPoints/EndpointHost.cs
@@ -188,12 +188,12 @@ public static void SetOperationTypes(ServiceOperations operationTypes, ServiceOp
AllServiceOperations = allOperationTypes;
}
- internal static object ExecuteService(object request, EndpointAttributes endpointAttributes, IHttpRequest httpReq)
+ internal static object ExecuteService(object request, EndpointAttributes endpointAttributes, IHttpRequest httpReq, IHttpResponse httpRes)
{
using (Profiler.Current.Step("Execute Service"))
{
return config.ServiceController.Execute(request,
- new HttpRequestContext(httpReq, request, endpointAttributes));
+ new HttpRequestContext(httpReq, httpRes, request, endpointAttributes));
}
}
View
16 src/ServiceStack/WebHost.EndPoints/Extensions/HttpListenerRequestWrapper.cs
@@ -41,6 +41,7 @@
using System.Net;
using System.Text;
using System.Web;
+using Funq;
using ServiceStack.Common.Utils;
using ServiceStack.ServiceHost;
using ServiceStack.Text;
@@ -51,6 +52,9 @@ public class HttpListenerRequestWrapper
: IHttpRequest
{
private static readonly string physicalFilePath;
+ private readonly HttpListenerRequest request;
+ public Container Container { get; set; }
+
static HttpListenerRequestWrapper()
{
physicalFilePath = "~".MapAbsolutePath();
@@ -66,14 +70,20 @@ public object OriginalRequest
get { return request; }
}
- private readonly HttpListenerRequest request;
-
- public HttpListenerRequestWrapper(string operationName, HttpListenerRequest request)
+ public HttpListenerRequestWrapper(
+ string operationName, HttpListenerRequest request)
{
this.OperationName = operationName;
this.request = request;
}
+ public T TryResolve<T>()
+ {
+ return Container == null
+ ? EndpointHost.AppHost.TryResolve<T>()
+ : Container.TryResolve<T>();
+ }
+
public string OperationName { get; set; }
public string GetRawBody()
View
16 src/ServiceStack/WebHost.EndPoints/Extensions/HttpRequestWrapper.cs
@@ -4,15 +4,19 @@
using System.IO;
using System.Net;
using System.Web;
+using Funq;
using ServiceStack.Common.Utils;
using ServiceStack.ServiceHost;
namespace ServiceStack.WebHost.Endpoints.Extensions
{
- internal class HttpRequestWrapper
+ public class HttpRequestWrapper
: IHttpRequest
{
private static readonly string physicalFilePath;
+ public Container Container { get; set; }
+ private readonly HttpRequest request;
+
static HttpRequestWrapper()
{
physicalFilePath = "~".MapHostAbsolutePath();
@@ -28,12 +32,18 @@ public object OriginalRequest
get { return request; }
}
- private readonly HttpRequest request;
-
public HttpRequestWrapper(string operationName, HttpRequest request)
{
this.OperationName = operationName;
this.request = request;
+ this.Container = Container;
+ }
+
+ public T TryResolve<T>()
+ {
+ return Container == null
+ ? EndpointHost.AppHost.TryResolve<T>()
+ : Container.TryResolve<T>();
}
public string OperationName { get; set; }
View
2  src/ServiceStack/WebHost.EndPoints/Extensions/HttpResponseWrapper.cs
@@ -8,7 +8,7 @@
namespace ServiceStack.WebHost.Endpoints.Extensions
{
- internal class HttpResponseWrapper
+ public class HttpResponseWrapper
: IHttpResponse
{
//private static readonly ILog Log = LogManager.GetLogger(typeof(HttpResponseWrapper));
View
2  src/ServiceStack/WebHost.EndPoints/Extensions/IHttpResponseExtensions.cs
@@ -59,7 +59,7 @@ public static bool WriteToResponse(this IHttpResponse httpRes, IHttpRequest http
{
if (result == null) return true;
- var serializationContext = new HttpRequestContext(httpReq, result);
+ var serializationContext = new HttpRequestContext(httpReq, httpRes, result);
var httpResult = result as IHttpResult;
if (httpResult != null)
{
View
6 src/ServiceStack/WebHost.EndPoints/GenericHandler.cs
@@ -30,10 +30,10 @@ public override object CreateRequest(IHttpRequest request, string operationName)
return GetRequest(request, operationName);
}
- public override object GetResponse(IHttpRequest httpReq, object request)
+ public override object GetResponse(IHttpRequest httpReq, IHttpResponse httpRes, object request)
{
var response = ExecuteService(request,
- HandlerAttributes | GetEndpointAttributes(httpReq), httpReq);
+ HandlerAttributes | GetEndpointAttributes(httpReq), httpReq, httpRes);
return response;
}
@@ -65,7 +65,7 @@ public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes,
var request = CreateRequest(httpReq, operationName);
if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) return;
- var response = GetResponse(httpReq, request);
+ var response = GetResponse(httpReq, httpRes, request);
if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) return;
if (doJsonp)
View
2  src/ServiceStack/WebHost.EndPoints/JsvSyncReplyHandler.cs
@@ -39,7 +39,7 @@ public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes,
var request = CreateRequest(httpReq, operationName);
var response = ExecuteService(request,
- HandlerAttributes | GetEndpointAttributes(httpReq), httpReq);
+ HandlerAttributes | GetEndpointAttributes(httpReq), httpReq, httpRes);
WriteDebugResponse(httpRes, response);
}
View
6 src/ServiceStack/WebHost.EndPoints/RestHandler.cs
@@ -60,7 +60,7 @@ public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes,
var request = GetRequest(httpReq, restPath);
if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) return;
- var response = GetResponse(httpReq, request);
+ var response = GetResponse(httpReq, httpRes, request);
if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) return;
if (responseContentType.Contains("jsv") && !string.IsNullOrEmpty(httpReq.QueryString["debug"]))
@@ -81,12 +81,12 @@ public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes,
}
}
- public override object GetResponse(IHttpRequest httpReq, object request)
+ public override object GetResponse(IHttpRequest httpReq, IHttpResponse httpRes, object request)
{
var requestContentType = ContentType.GetEndpointAttributes(httpReq.ResponseContentType);
return ExecuteService(request,
- HandlerAttributes | requestContentType | GetEndpointAttributes(httpReq), httpReq);
+ HandlerAttributes | requestContentType | GetEndpointAttributes(httpReq), httpReq, httpRes);
}
private static object GetRequest(IHttpRequest httpReq, IRestPath restPath)
View
7 src/ServiceStack/WebHost.EndPoints/Support/EndpointHandlerBase.cs
@@ -45,7 +45,7 @@ public bool IsReusable
}
public abstract object CreateRequest(IHttpRequest request, string operationName);
- public abstract object GetResponse(IHttpRequest httpReq, object request);
+ public abstract object GetResponse(IHttpRequest httpReq, IHttpResponse httpRes, object request);
public virtual void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
@@ -164,9 +164,10 @@ public static Type GetOperationType(string operationName)
: EndpointHost.ServiceOperations.GetOperationType(operationName);
}
- protected static object ExecuteService(object request, EndpointAttributes endpointAttributes, IHttpRequest httpReq)
+ protected static object ExecuteService(object request, EndpointAttributes endpointAttributes,
+ IHttpRequest httpReq, IHttpResponse httpRes)
{
- return EndpointHost.ExecuteService(request, endpointAttributes, httpReq);
+ return EndpointHost.ExecuteService(request, endpointAttributes, httpReq, httpRes);
}
public EndpointAttributes GetEndpointAttributes(System.ServiceModel.OperationContext operationContext)
View
2  src/ServiceStack/WebHost.EndPoints/Support/Markdown/MarkdownHandler.cs
@@ -43,7 +43,7 @@ public override object CreateRequest(IHttpRequest request, string operationName)
return null;
}
- public override object GetResponse(IHttpRequest httpReq, object request)
+ public override object GetResponse(IHttpRequest httpReq, IHttpResponse httpRes, object request)
{
return null;
}
View
5 src/ServiceStack/WebHost.EndPoints/Support/Mocks/HttpRequestMock.cs
@@ -37,6 +37,11 @@ public object OriginalRequest
get { return null; }
}
+ public T TryResolve<T>()
+ {
+ throw new NotImplementedException();
+ }
+
public string OperationName { get; set; }
public string ContentType { get; set; }
public string HttpMethod { get; set; }
View
4 src/ServiceStack/WebHost.EndPoints/Support/SoapHandler.cs
@@ -80,7 +80,7 @@ protected Message ExecuteMessage(Message requestMsg, EndpointAttributes endpoint
if (hasRequestFilters && EndpointHost.ApplyRequestFilters(httpReq, httpRes, request))
return EmptyResponse(requestMsg, requestType);
- var response = ExecuteService(request, endpointAttributes, null);
+ var response = ExecuteService(request, endpointAttributes, httpReq, httpRes);
if (hasResponseFilters && EndpointHost.ApplyResponseFilters(httpReq, httpRes, response))
return EmptyResponse(requestMsg, requestType);
@@ -199,7 +199,7 @@ public override object CreateRequest(IHttpRequest request, string operationName)
throw new NotImplementedException();
}
- public override object GetResponse(IHttpRequest httpReq, object request)
+ public override object GetResponse(IHttpRequest httpReq, IHttpResponse httpRes, object request)
{
throw new NotImplementedException();
}
View
7 tests/ServiceStack.Common.Tests/ReflectionUtilTests.cs
@@ -2,7 +2,7 @@
using System.ComponentModel.DataAnnotations;
using System.Linq;
using NUnit.Framework;
-using ServiceStack.Common.Tests.Support;
+using ServiceStack.Common.Tests.Models;
using ServiceStack.Common.Utils;
using ServiceStack.DataAnnotations;
using System.Collections.Generic;
@@ -168,7 +168,7 @@ public void Populate_Same_Objects()
var toObj = ModelWithFieldsOfDifferentTypes.Create(1);
var fromObj = ModelWithFieldsOfDifferentTypes.Create(2);
- var obj3 = (ModelWithFieldsOfDifferentTypes)ReflectionUtils.PopulateObject(toObj, fromObj);
+ var obj3 = ReflectionUtils.PopulateObject(toObj, fromObj);
Assert.IsTrue(obj3 == toObj);
Assert.That(obj3.Bool, Is.EqualTo(fromObj.Bool));
@@ -186,8 +186,7 @@ public void Populate_Different_Objects_with_different_property_types()
var toObj = ModelWithFieldsOfDifferentTypes.Create(1);
var fromObj = ModelWithOnlyStringFields.Create("2");
- var obj3 = (ModelWithFieldsOfDifferentTypes)
- ReflectionUtils.PopulateObject(toObj, fromObj);
+ var obj3 = ReflectionUtils.PopulateObject(toObj, fromObj);
Assert.IsTrue(obj3 == toObj);
Assert.That(obj3.Id, Is.EqualTo(2));
View
4 tests/ServiceStack.Common.Tests/ServiceStack.Common.Tests.csproj
@@ -176,10 +176,6 @@
<Compile Include="StringExtensionTests.cs" />
<Compile Include="ReflectionUtilTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="Support\InvokeSimpleCommandsTests.cs" />
- <Compile Include="Support\ModelWithFieldsOfDifferentTypes.cs" />
- <Compile Include="Support\ModelWithOnlyStringFields.cs" />
- <Compile Include="Support\PathInfoTests.cs" />
<Compile Include="Text\AdhocJsTests.cs" />
<Compile Include="OAuth\OAuthUserSessionTests.cs" />
<Compile Include="Xlinq\XlinqExtensionsTests.cs" />
View
226 tests/ServiceStack.Common.Tests/Support/InvokeSimpleCommandsTests.cs
@@ -1,226 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using NUnit.Framework;
-using ServiceStack.Text.Controller;
-
-namespace ServiceStack.Common.Tests.Support
-{
-
- [TestFixture]
- public class InvokeSimpleCommandsTests
- {
- SimpleController simpleController;
-
- public class SimpleController
- {
- public List<string> History = new List<string>();
-
- public void Test()
- {
- History.Add("Test()");
- }
-
- public void TestWithOneStringArg(string value)
- {
- AddFormat("TestWithOneStringArg({0})", value);
- }
-
- public void TestWithOneGuidArg(Guid value)
- {
- AddFormat("TestWithOneGuidArg({0})", value);
- }
-
- public void TestWithOneArrayOfStringArg(string[] values)
- {
- AddFormat("TestWithOneArrayOfStringArg({0})", string.Join(",", values));
- }
-
- public void TestWithOneListOfStringArg(List<string> values)
- {
- AddFormat("TestWithOneListOfStringArg({0})", string.Join(",", values.ToArray()));
- }
-
- public void OverloadedMethod(int value1)
- {
- AddFormat("OverloadedMethod({0})", value1);
- }
-
- public void OverloadedMethod(int value1, float value2)
- {
- AddFormat("OverloadedMethod({0},{1})", value1, value2);
- }
-
- public string HitoryJoined
- {
- get
- {
- return string.Join(",", this.History.ToArray());
- }
- }
-
- public void Add(string text)
- {
- this.History.Add(text);
- }
-
- public void AddFormat(string text, params object[] args)
- {
- this.History.Add(string.Format(text, args));
- }
- }
-
- private CommandProcessor CreateInvokerWithSimpleController()
- {
- simpleController = new SimpleController();
- var objects = new[] { simpleController };
- var actionInvoke = new CommandProcessor(objects);
- return actionInvoke;
- }
-
-
- [Test]
- public void Can_call_method_with_no_args()
- {
-
- try
- {
- var actionInvoke = CreateInvokerWithSimpleController();
-
- actionInvoke.Invoke(typeof(SimpleController).Name + "://Test");
-
- Assert.That(simpleController.HitoryJoined, Is.EqualTo("Test()"));
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
-
- [Test]
- public void Can_call_method_with_one_string_arg()
- {
- try
- {
- var actionInvoke = CreateInvokerWithSimpleController();
-
- actionInvoke.Invoke(typeof(SimpleController).Name + "://TestWithOneStringArg/arg1");
-
- Assert.That(simpleController.HitoryJoined, Is.EqualTo("TestWithOneStringArg(arg1)"));
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
-
- [Test]
- public void Can_call_method_with_one_guid_arg()
- {
- try
- {
- var guidValue = Guid.NewGuid();
-
- var actionInvoke = CreateInvokerWithSimpleController();
-
- actionInvoke.Invoke(typeof(SimpleController).Name
- + "://TestWithOneGuidArg/" + guidValue);
-
- Assert.That(simpleController.HitoryJoined,
- Is.EqualTo("TestWithOneGuidArg(" + guidValue + ")"));
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
-
- [Test]
- public void Can_call_method_with_one_array_of_string_arg()
- {
- try
- {
- var arrayValue = new[] { "Hello", "World" };
- var valueString = string.Join(",", arrayValue);
-
- var actionInvoke = CreateInvokerWithSimpleController();
-
- actionInvoke.Invoke(typeof(SimpleController).Name
- + "://TestWithOneArrayOfStringArg/" + valueString);
-
- Assert.That(simpleController.HitoryJoined,
- Is.EqualTo("TestWithOneArrayOfStringArg(" + valueString + ")"));
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
-
- [Test]
- public void Can_call_method_with_one_list_of_string_arg()
- {
- try
- {
- var listValue = new[] { "Hello", "World" }.ToList();
- var valueString = string.Join(",", listValue.ToArray());
-
- var actionInvoke = CreateInvokerWithSimpleController();
-
- actionInvoke.Invoke(typeof(SimpleController).Name
- + "://TestWithOneListOfStringArg/" + valueString);
-
- Assert.That(simpleController.HitoryJoined,
- Is.EqualTo("TestWithOneListOfStringArg(" + valueString + ")"));
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
-
- [Test]
- public void Can_call_overloaded_method_with_one_arg()
- {
- try
- {
- const int intValue = 1;
-
- var actionInvoke = CreateInvokerWithSimpleController();
-
- actionInvoke.Invoke(typeof(SimpleController).Name
- + "://OverloadedMethod/" + intValue);
-
- Assert.That(simpleController.HitoryJoined,
- Is.EqualTo("OverloadedMethod(" + intValue + ")"));
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
-
- [Test]
- public void Can_call_overloaded_method_with_two_args()
- {
- try
- {
- const int intValue = 1;
- const double floatValue = 2.2;
-
- var actionInvoke = CreateInvokerWithSimpleController();
-
- actionInvoke.Invoke(typeof(SimpleController).Name
- + "://OverloadedMethod/" + intValue + "/" + floatValue);
-
- Assert.That(simpleController.HitoryJoined,
- Is.EqualTo("OverloadedMethod(" + intValue + "," + floatValue + ")"));
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
-
- }
-}
View
37 tests/ServiceStack.Common.Tests/Support/ModelWithFieldsOfDifferentTypes.cs
@@ -1,37 +0,0 @@
-using System;
-
-namespace ServiceStack.Common.Tests.Support
-{
- public class ModelWithFieldsOfDifferentTypes
- {
- public int Id { get; set; }
-
- public string Name { get; set; }
-
- public long LongId { get; set; }
-
- public Guid Guid { get; set; }
-
- public bool Bool { get; set; }
-
- public DateTime DateTime { get; set; }
-
- public double Double { get; set; }
-
- public static ModelWithFieldsOfDifferentTypes Create(int id)
- {
- var row = new ModelWithFieldsOfDifferentTypes {
- Id = id,
- Bool = id % 2 == 0,
- DateTime = DateTime.Now.AddDays(id),
- Double = 1.11d + id,
- Guid = Guid.NewGuid(),
- LongId = 999 + id,
- Name = "Name" + id
- };
-
- return row;
- }
-
- }
-}
View
27 tests/ServiceStack.Common.Tests/Support/ModelWithOnlyStringFields.cs
@@ -1,27 +0,0 @@
-using ServiceStack.DataAnnotations;
-
-namespace ServiceStack.Common.Tests.Support
-{
- public class ModelWithOnlyStringFields
- {
- public string Id { get; set; }
-
- [Index]
- public string Name { get; set; }
-
- public string AlbumId { get; set; }
-
- [Index]
- public string AlbumName { get; set; }
-
- public static ModelWithOnlyStringFields Create(string id)
- {
- return new ModelWithOnlyStringFields {
- Id = id,
- Name = "Name" + id,
- AlbumId = "AlbumId" + id,
- AlbumName = "AlbumName" + id,
- };
- }
- }
-}
View
31 tests/ServiceStack.Common.Tests/Support/PathInfoTests.cs
@@ -1,31 +0,0 @@
-using NUnit.Framework;
-using ServiceStack.Text.Controller;
-
-namespace ServiceStack.Common.Tests.Support
-{
- [TestFixture]
- public class PathInfoTests
- {
- [Test]
- public void Test_with_full_path_uri()
- {
- var pathInfo = PathInfo.Parse("Controller://Action/arg1/arg2?Name=foo&Age=10");
-
- Assert.That(pathInfo.ControllerName, Is.EqualTo("Controller"));
- Assert.That(pathInfo.ActionName, Is.EqualTo("Action"));
- Assert.That(pathInfo.Arguments.Count, Is.EqualTo(2));
- Assert.That(pathInfo.Options.Count, Is.EqualTo(2));
- }
-
- [Test]
- public void Test_with_controller_and_pathUri()
- {
- var pathInfo = PathInfo.Parse("Controller://Action/arg1");
-
- Assert.That(pathInfo.ControllerName, Is.EqualTo("Controller"));
- Assert.That(pathInfo.ActionName, Is.EqualTo("Action"));
- Assert.That(pathInfo.Arguments.Count, Is.EqualTo(1));
- }
-
- }
-}
View
2  tests/ServiceStack.ServiceHost.Tests/Formats/ViewTests.cs
@@ -83,7 +83,7 @@ public string GetHtml(object dto, string format)
QueryString = new NameValueCollection(),
};
httpReq.QueryString.Add("format", format);
- var requestContext = new HttpRequestContext(httpReq, dto);
+ var requestContext = new HttpRequestContext(httpReq, null, dto);
using (var ms = new MemoryStream())
{
var httpRes = new HttpResponseStreamWrapper(ms);
View
39 tests/ServiceStack.ServiceHost.Tests/Routes/SimpleRestServices.cs
@@ -20,31 +20,36 @@ public override object OnPut(RequestDto request)
{
return new HttpResult { StatusCode = HttpStatusCode.OK };
}
- }
-
- public class RestServiceWithAllVerbsImplemented : RestServiceBase<RequestDto>
- {
- public override object OnGet(RequestDto request)
+ }
+
+ public class RequestDto2
+ {
+ public string Name { get; set; }
+ }
+
+ public class RestServiceWithAllVerbsImplemented : RestServiceBase<RequestDto2>
+ {
+ public override object OnGet(RequestDto2 request)
{
return new HttpResult {StatusCode = HttpStatusCode.OK};
- }
-
- public override object OnPut(RequestDto request)
+ }
+
+ public override object OnPut(RequestDto2 request)
{
return new HttpResult {StatusCode = HttpStatusCode.OK};
- }
-
- public override object OnPost(RequestDto request)
+ }
+
+ public override object OnPost(RequestDto2 request)
{
return new HttpResult {StatusCode = HttpStatusCode.OK};
- }
-
- public override object OnDelete(RequestDto request)
+ }
+
+ public override object OnDelete(RequestDto2 request)
{
return new HttpResult {StatusCode = HttpStatusCode.OK};
- }
-
- public override object OnPatch(RequestDto request)
+ }
+
+ public override object OnPatch(RequestDto2 request)
{
return new HttpResult {StatusCode = HttpStatusCode.OK};
}
View
5 tests/ServiceStack.ServiceHost.Tests/ServiceStackHandlerUrlTests.cs
@@ -34,6 +34,11 @@ public object OriginalRequest
get { throw new NotImplementedException(); }
}
+ public T TryResolve<T>()
+ {
+ throw new NotImplementedException();
+ }
+
public string OperationName { get; private set; }
public string ContentType { get; private set; }
public string HttpMethod { get; private set; }
View
2  tests/ServiceStack.WebHost.Endpoints.Tests/HttpResultTests.cs
@@ -70,7 +70,7 @@ public void Can_send_ResponseStream_test_with_Custom_Header()
public void Can_send_ResponseText_test_with_StatusDescription()
{
var mockRequest = new MockHttpRequest { ContentType = ContentType.Json };
- var mockRequestContext = new HttpRequestContext(mockRequest, new object());
+ var mockRequestContext = new HttpRequestContext(mockRequest, null, new object());
var mockResponse = new HttpResponseMock();
var customStatus = "Custom Status Description";
View
2  tests/ServiceStack.WebHost.Endpoints.Tests/Support/EndpointHandlerBaseTests.cs
@@ -18,7 +18,7 @@ public override object CreateRequest(ServiceHost.IHttpRequest request, string op
throw new NotImplementedException();
}
- public override object GetResponse(ServiceHost.IHttpRequest httpReq, object request)
+ public override object GetResponse(IHttpRequest httpReq, IHttpResponse httpRes, object request)
{
throw new NotImplementedException();
}
View
5 tests/ServiceStack.WebHost.IntegrationTests/Global.asax.cs
@@ -13,6 +13,7 @@
using ServiceStack.Redis;
using ServiceStack.Redis.Messaging;
using ServiceStack.ServiceHost;
+using ServiceStack.ServiceInterface;
using ServiceStack.WebHost.Endpoints;
using ServiceStack.WebHost.IntegrationTests.Services;
@@ -57,6 +58,10 @@ public override void Configure(Container container)
});
this.Container.Register<ICacheClient>(new MemoryCacheClient());
+ //this.Container.Register<ICacheClient>(new BasicRedisClientManager());
+
+ //this.Container.Register<ISessionFactory>(
+ // c => new SessionFactory(c.Resolve<ICacheClient>()));
var dbFactory = this.Container.Resolve<IDbConnectionFactory>();
dbFactory.Exec(dbCmd => dbCmd.CreateTable<Movie>(true));
View
2  tests/ServiceStack.WebHost.IntegrationTests/ServiceStack.WebHost.IntegrationTests.csproj
@@ -117,6 +117,7 @@
</Compile>
<Compile Include="Services\BatchWidgetValidationService.cs" />
<Compile Include="Services\CachedMoviesService.cs" />
+ <Compile Include="Services\SessionService.cs" />
<Compile Include="Services\MqHostStatsService.cs" />
<Compile Include="Services\HttpResultsService.cs" />
<Compile Include="Services\CustomFormDataService.cs" />
@@ -158,6 +159,7 @@
<Compile Include="Tests\RestPathResolutionUnitTests.cs" />
<Compile Include="Tests\RestsTestBase.cs" />
<Compile Include="Tests\RestWebServiceTests.cs" />
+ <Compile Include="Tests\SessionTests.cs" />
<Compile Include="Tests\WebServicesTests.cs" />
</ItemGroup>
<ItemGroup>
View
65 tests/ServiceStack.WebHost.IntegrationTests/Services/SessionService.cs
@@ -0,0 +1,65 @@
+using System.Runtime.Serialization;
+using System.Web;
+using ServiceStack.CacheAccess;
+using ServiceStack.ServiceHost;
+using ServiceStack.ServiceInterface;
+using ServiceStack.Text;
+using ServiceStack.WebHost.Endpoints.Extensions;
+
+namespace ServiceStack.WebHost.IntegrationTests.Services
+{
+ public class CustomSession
+ {
+ public int Counter { get; set; }
+ }
+
+ [RestService("/session")]
+ public class Session
+ {
+ public string Value { get; set; }
+ }
+
+ public class SessionResponse
+ {
+ public CustomSession Typed { get; set; }
+ public CustomSession UnTyped { get; set; }
+ }
+
+ public class SessionService
+ : ServiceBase<Session>
+ {
+ //public ISessionFactory SessionFactory { get; set; }
+
+ //private ISession session;
+ //public ISession Session
+ //{
+ // get
+ // {
+ // return session ?? (session =
+ // SessionFactory.GetOrCreateSession(
+ // new HttpRequestWrapper(null, HttpContext.Current.Request),
+ // new HttpResponseWrapper(HttpContext.Current.Response)
+ // ));
+ // }
+ //}
+
+ protected override object Run(Session request)
+ {
+ var untyped = Session["untyped"] as CustomSession ?? new CustomSession();
+ var typed = Session.Get<CustomSession>("typed") ?? new CustomSession();
+
+ untyped.Counter++;
+ typed.Counter++;
+
+ Session["untyped"] = untyped;
+ Session.Set("typed", typed);
+
+ var response = new SessionResponse {
+ Typed = typed,
+ UnTyped = untyped,
+ };
+
+ return response;
+ }
+ }
+}
View
10 tests/ServiceStack.WebHost.IntegrationTests/Tests/SessionTests.cs
@@ -0,0 +1,10 @@
+using NUnit.Framework;
+
+namespace ServiceStack.WebHost.IntegrationTests.Tests
+{
+ [TestFixture]
+ public class SessionTests
+ {
+
+ }
+}
View
6 tests/ServiceStack.WebHost.IntegrationTests/Web.config
@@ -15,10 +15,10 @@
</configSections>
<appSettings>
<add key="test" value="val"/>
- </appSettings>
- <connectionStrings/>
+ </appSettings>
+ <connectionStrings/>
- <location path="api">
+ <location path="api">
<system.web>
<httpHandlers>
<add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
Please sign in to comment.
Something went wrong with that request. Please try again.