public override void Configure(Funq.Container container) { ServiceStack.Text.JsConfig.EmitCamelCaseNames = true; // Remove some unused features that by default are included Plugins.RemoveAll(p => p is CsvFormat); Plugins.RemoveAll(p => p is MetadataFeature); // Get disable features specified in Config file (i.e. Soap, Metadata, etc.) var disabled = AppHostConfigHelper.GetDisabledFeatures(); // Construct Service Endpoint Host Configuration store var config = new EndpointHostConfig { DefaultContentType = ContentType.Json, WriteErrorsToResponse = false, EnableFeatures = Feature.All.Remove(disabled), AppendUtf8CharsetOnContentTypes = new HashSet<string> { ContentType.Html }, }; // Apply configuration SetConfig(config); // Initialize Databases & associated Routes container.InitDatabaseRoutes(Routes); // Register Cache Clients container.Register<ICacheClient>(new MemoryCacheClient()); // Register Redis Client Manager container.Register<IRedisClientsManager>(c => new PooledRedisClientManager("localhost:6379")); }
public void Init( Container container, IList<IPlugin> plugins, IServiceRoutes routes, EndpointHostConfig endpointHostconfig ) { }
void setEndpointHostConfig(EndpointHostConfig endpointHostconfig) { endpointHostconfig = new EndpointHostConfig { EnableFeatures = Feature.All.Remove( Feature.Xml | Feature.Jsv | Feature.Csv | Feature.Soap), DefaultContentType = ContentType.Json }; }
public override void Configure(Container container) { container.Adapter = new WindsorContainerServiceAdapter(_container); JsConfig.EmitCamelCaseNames = true; var endpointConfig = new EndpointHostConfig { ServiceStackHandlerFactoryPath = "api" }; SetConfig(endpointConfig); }
protected override void Configure(Container container) { Plugins.Add(new global::ServiceStack.Razor.RazorFormat()); var endpointHostConfig = new EndpointHostConfig { CustomHttpHandlers = { { System.Net.HttpStatusCode.NotFound, new global::ServiceStack.Razor.RazorHandler("/notfound") } } }; SetConfig(endpointHostConfig); }
public static void AssertTestConfig(params Assembly[] assemblies) { if (Config != null) { return; } var config = EndpointHostConfig.Instance; config.ServiceName = "Test Services"; config.ServiceManager = new ServiceManager(assemblies.Length == 0 ? new[] { Assembly.GetCallingAssembly() } : assemblies); Config = config; }
public override void Configure(Container container) { JsConfig.EmitCamelCaseNames = true; Routes.Add<ItemRequest>("/Item/{ItemID}"); var config = new EndpointHostConfig { DefaultContentType = ContentType.Json, AllowJsonpRequests = true, EnableFeatures = Feature.All.Remove(GetDisabledFeatures()) }; SetConfig(config); }
public override void Configure (Container container) { LogManager.LogFactory = new NLogFactory (); this.RequestFilters.Add ((req, resp, requestDto) => { ILog log = LogManager.GetLogger (GetType ()); log.Info (string.Format ( "REQ {0}: {1} {2} {3} {4} {5}\n", DateTimeOffset.Now.Ticks, req.HttpMethod, req.OperationName, req.RemoteIp, req.RawUrl, req.UserAgent)); }); this.RequestFilters.Add ((req, resp, requestDto) => { ILog log = LogManager.GetLogger (GetType ()); log.Info (string.Format ( "RES {0}: {1} {2}\n", DateTimeOffset.Now.Ticks, resp.StatusCode, resp.ContentType)); }); JsConfig.DateHandler = JsonDateHandler.ISO8601; Plugins.Add (new AuthFeature (() => new AuthUserSession (), new IAuthProvider[] { new BasicAuthProvider () }) ); Plugins.Add (new RegistrationFeature ()); Plugins.Add (new RequestLogsFeature ()); container.RegisterAutoWiredAs<Scheduler, IScheduler> (); container.Register<ICacheClient> (new MemoryCacheClient ()); container.Register<IDbConnectionFactory> (new OrmLiteConnectionFactory (@"Data Source=db.sqlite;Version=3;", SqliteOrmLiteDialectProvider.Instance)); //Use OrmLite DB Connection to persist the UserAuth and AuthProvider info container.Register<IUserAuthRepository> (c => new OrmLiteAuthRepository (c.Resolve<IDbConnectionFactory> ())); Plugins.Add (new ValidationFeature ()); container.RegisterValidators (typeof(AppHost).Assembly); var config = new EndpointHostConfig (); if (m_debugEnabled) { config.DebugMode = true; //Show StackTraces in service responses during development config.WriteErrorsToResponse = true; config.ReturnsInnerException = true; } container.AutoWire (this); SetConfig (config); CreateMissingTables (container); }
public void SetConfig(EndpointHostConfig config) { if (config.ServiceName == null) { config.ServiceName = EndpointHostConfig.Instance.ServiceName; } if (config.ServiceManager == null) { config.ServiceManager = EndpointHostConfig.Instance.ServiceManager; } config.ServiceManager.ServiceController.EnableAccessRestrictions = config.EnableAccessRestrictions; EndpointHost.Config = config; }
public void SetConfig(EndpointHostConfig config) { if (config.ServiceName == null) { config.ServiceName = EndpointHost.Config.ServiceName; } if (config.ServiceController == null) { config.ServiceController = EndpointHost.Config.ServiceController; } EndpointHost.Config = config; this.serviceManager.ServiceController.EnableAccessRestrictions = config.EnableAccessRestrictions; JsonDataContractSerializer.Instance.UseBcl = config.UseBclJsonSerializers; JsonDataContractDeserializer.Instance.UseBcl = config.UseBclJsonSerializers; }
private static void Reset() { ContentTypeFilter = HttpResponseFilter.Instance; RawRequestFilters = new List <Action <IHttpRequest, IHttpResponse> >(); RequestFilters = new List <Action <IHttpRequest, IHttpResponse, object> >(); ResponseFilters = new List <Action <IHttpRequest, IHttpResponse, object> >(); ViewEngines = new List <IViewEngine>(); CatchAllHandlers = new List <HttpHandlerResolverDelegate>(); Plugins = new List <IPlugin> { new HtmlFormat(), new CsvFormat(), new MarkdownFormat(), new PredefinedRoutesFeature(), new MetadataFeature(), }; //Default Config for projects that want to use components but not WebFramework (e.g. MVC) Config = new EndpointHostConfig( "Empty Config", new ServiceManager(new Container(), new ServiceController(null))); }
public override void Configure(Container container) { LogManager.LogFactory = new NLogFactory (); this.RequestFilters.Add ((req, resp, requestDto) => { ILog log = LogManager.GetLogger (GetType ()); log.Info (string.Format ("REQ {0}: {1} {2} {3} {4} {5}", DateTimeOffset.Now.Ticks, req.HttpMethod, req.OperationName, req.RemoteIp, req.RawUrl, req.UserAgent)); }); this.ResponseFilters.Add ((req, resp, dto) => { ILog log = LogManager.GetLogger (GetType ()); log.Info (string.Format ("RES {0}: {1} {2}", DateTimeOffset.Now.Ticks, resp.StatusCode, resp.ContentType)); }); container.Register<IDbConnectionFactory> ( new OrmLiteConnectionFactory (@"Data Source=db.sqlite;Version=3;", SqliteOrmLiteDialectProvider.Instance) { ConnectionFilter = x => new ProfiledDbConnection (x, Profiler.Current) }); JsConfig.DateHandler = JsonDateHandler.ISO8601; Plugins.Add (new ValidationFeature ()); container.RegisterValidators (typeof(AppHost).Assembly); var config = new EndpointHostConfig (); if (m_debugEnabled) { config.DebugMode = true; //Show StackTraces in service responses during development config.WriteErrorsToResponse = true; config.ReturnsInnerException = true; } SetConfig (config); SetUpDb (container); }
public void Init( Container container, IList<IPlugin> plugins, IServiceRoutes routes, EndpointHostConfig endpointHostconfig ) { LogManager.LogFactory = new NLogFactory(); //Configure User Defined REST Paths //Routes // .Add<Hello>("/hello") // .Add<Hello>("/hello/{Name*}"); //Set JSON web services to return idiomatic JSON camelCase properties ServiceStack.Text.JsConfig.EmitCamelCaseNames = true; setPlugins(plugins); registerDependencies(container); setEndpointHostConfig(endpointHostconfig); }
public override void Configure (Container container) { JsConfig.DateHandler = JsonDateHandler.ISO8601; Plugins.Add (new AuthFeature (() => new AuthUserSession (), new IAuthProvider[] {new CredentialsAuthProvider ()}) ); Plugins.Add (new RegistrationFeature ()); Plugins.Add (new RequestLogsFeature ()); container.Register<ICacheClient> (new MemoryCacheClient ()); container.Register<IDbConnectionFactory> ( new OrmLiteConnectionFactory (@"Data Source=db.sqlite;Version=3;", SqliteOrmLiteDialectProvider.Instance) { ConnectionFilter = x => new ProfiledDbConnection (x, Profiler.Current) }); //Use OrmLite DB Connection to persist the UserAuth and AuthProvider info container.Register<IUserAuthRepository> (c => new OrmLiteAuthRepository (c.Resolve<IDbConnectionFactory> ())); Plugins.Add (new ValidationFeature ()); container.RegisterValidators (typeof(AppHost).Assembly); var config = new EndpointHostConfig (); if (m_debugEnabled) { config.DebugMode = true; //Show StackTraces in service responses during development config.WriteErrorsToResponse = true; config.ReturnsInnerException = true; } SetConfig (config); CreateMissingTables (container); }
protected void SetConfig(EndpointHostConfig config) { EndpointHost.Config = config; this.serviceManager.ServiceController.EnableAccessRestrictions = config.EnableAccessRestrictions; }
public override void Configure(Funq.Container container) { this.ComposeObjectGraph (container); JsConfig.DateHandler = JsonDateHandler.ISO8601; Plugins.Add (new SwaggerFeature ()); // register our custom exception handling this.ExceptionHandler = Rainy.ErrorHandling.ExceptionHandler.CustomExceptionHandler; this.ServiceExceptionHandler = Rainy.ErrorHandling.ExceptionHandler.CustomServiceExceptionHandler; string swagger_path; if (JsonConfig.Config.Global.Development) swagger_path = Path.Combine(Path.GetDirectoryName(this.GetType ().Assembly.Location), "../../swagger-ui/"); else swagger_path = Path.Combine(Path.GetDirectoryName(this.GetType ().Assembly.Location), "swagger-ui/"); var swagger_handler = new FilesystemHandler ("/swagger-ui/", swagger_path); IHttpHandlerDecider uihandler; if (JsonConfig.Config.Global.Development) { var webui_path = Path.Combine(Path.GetDirectoryName(this.GetType ().Assembly.Location), "../../../Rainy.UI/dist/"); uihandler = (IHttpHandlerDecider) new FilesystemHandler ("/", webui_path); } else { uihandler = (IHttpHandlerDecider) new EmbeddedResourceHandler ("/", this.GetType ().Assembly, "Rainy.WebService.Admin.UI"); } this.RequestFilters.Add ((req, resp, dto) => { if (req.HttpMethod == "OPTIONS") { resp.StatusCode = 200; resp.End (); } }); // BUG HACK // GlobalResponseHeaders are not cleared between creating instances of a new config // this will be fatal (duplicate key error) for unit tests so we clear the headers EndpointHostConfig.Instance.GlobalResponseHeaders.Clear (); var endpoint_config = new EndpointHostConfig { EnableFeatures = Feature.All.Remove (Feature.Metadata), //DefaultRedirectPath = "/admin/", // not all tomboy clients send the correct content-type // so we force application/json DefaultContentType = ContentType.Json, RawHttpHandlers = { swagger_handler.CheckAndProcess, uihandler.CheckAndProcess }, // enable cors GlobalResponseHeaders = { { "Access-Control-Allow-Origin", "*" }, { "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" }, // time in seconds preflight responses can be cached by the client { "Access-Control-Max-Age", "1728000" }, // { "Access-Control-Max-Age", "1" }, // the Authority header must be whitelisted; it is sent be the rainy-ui // for authentication { "Access-Control-Allow-Headers", "Content-Type, Authority, AccessToken" }, }, }; endpoint_config.AddMaxAgeForStaticMimeTypes["text/html"] = new TimeSpan (1, 0, 0); endpoint_config.AddMaxAgeForStaticMimeTypes["text/css"] = new TimeSpan (1, 0, 0); endpoint_config.AddMaxAgeForStaticMimeTypes["text/javascript"] = new TimeSpan (1, 0, 0); SetConfig (endpoint_config); }
public void SetConfig(EndpointHostConfig config) { if (config.ServiceName == null) config.ServiceName = EndpointHost.Config.ServiceName; if (config.ServiceManager == null) config.ServiceManager = EndpointHost.Config.ServiceManager; config.ServiceManager.ServiceController.EnableAccessRestrictions = config.EnableAccessRestrictions; EndpointHost.Config = config; JsonDataContractSerializer.Instance.UseBcl = config.UseBclJsonSerializers; JsonDataContractDeserializer.Instance.UseBcl = config.UseBclJsonSerializers; }
private static void InferHttpHandlerPath(EndpointHostConfig instance) { try { var config = GetAppConfig(); if (config == null) return; SetPathsFromConfiguration(instance, config, null); if (instance.MetadataRedirectPath == null) { foreach (ConfigurationLocation location in config.Locations) { SetPathsFromConfiguration(instance, location.OpenConfiguration(), (location.Path ?? "").ToLower()); if (instance.MetadataRedirectPath != null) { break; } } } } catch (Exception exc) { _log.Error("Bad Config", exc); } if (!SkipPathValidation && instance.MetadataRedirectPath == null) { throw new ConfigurationErrorsException( "Unable to infer ServiceStack's <httpHandler.Path/> from the Web.Config\n" + "Check with http://www.servicestack.net/ServiceStack.Hello/ to ensure you have configured ServiceStack properly.\n" + "Otherwise you can explicitly set your httpHandler.Path by setting: EndpointHostConfig.ServiceStackPath"); } }
private static void SetPaths(EndpointHostConfig instance, string handlerPath, string locationPath) { if (null == handlerPath) { return; } if (null == locationPath) { handlerPath = handlerPath.Replace("*", String.Empty); } instance.ServiceStackHandlerFactoryPath = locationPath ?? (String.IsNullOrEmpty(handlerPath) ? null : handlerPath); instance.MetadataRedirectPath = PathUtils.CombinePaths( null != locationPath ? instance.ServiceStackHandlerFactoryPath : handlerPath , "metadata"); }
private void ExtractExistingValues(EndpointHostConfig existing) { if (existing == null) return; this.MetadataTypesConfig = existing.MetadataTypesConfig; this.WsdlServiceNamespace = existing.WsdlServiceNamespace; this.MetadataPageBodyHtml = existing.MetadataPageBodyHtml; this.MetadataOperationPageBodyHtml = existing.MetadataOperationPageBodyHtml; this.EnableAccessRestrictions = existing.EnableAccessRestrictions; this.ServiceEndpointsMetadataConfig = existing.ServiceEndpointsMetadataConfig; this.LogFactory = existing.LogFactory; this.EnableAccessRestrictions = existing.EnableAccessRestrictions; this.WebHostUrl = existing.WebHostUrl; this.WebHostPhysicalPath = existing.WebHostPhysicalPath; this.DefaultRedirectPath = existing.DefaultRedirectPath; this.MetadataRedirectPath = existing.MetadataRedirectPath; this.ServiceStackHandlerFactoryPath = existing.ServiceStackHandlerFactoryPath; this.DefaultContentType = existing.DefaultContentType; this.AllowJsonpRequests = existing.AllowJsonpRequests; this.DebugMode = existing.DebugMode; this.DefaultDocuments = existing.DefaultDocuments; this.GlobalResponseHeaders = existing.GlobalResponseHeaders; this.IgnoreFormatsInMetadata = existing.IgnoreFormatsInMetadata; this.AllowFileExtensions = existing.AllowFileExtensions; this.EnableFeatures = existing.EnableFeatures; this.WriteErrorsToResponse = existing.WriteErrorsToResponse; this.MarkdownOptions = existing.MarkdownOptions; this.MarkdownBaseType = existing.MarkdownBaseType; this.MarkdownGlobalHelpers = existing.MarkdownGlobalHelpers; this.HtmlReplaceTokens = existing.HtmlReplaceTokens; this.AddMaxAgeForStaticMimeTypes = existing.AddMaxAgeForStaticMimeTypes; this.AppendUtf8CharsetOnContentTypes = existing.AppendUtf8CharsetOnContentTypes; this.RawHttpHandlers = existing.RawHttpHandlers; this.CustomHttpHandlers = existing.CustomHttpHandlers; this.DefaultJsonpCacheExpiration = existing.DefaultJsonpCacheExpiration; }
private static void SetPathsFromConfiguration(EndpointHostConfig instance, System.Configuration.Configuration config, string locationPath) { if (config == null) return; //standard config var handlersSection = config.GetSection("system.web/httpHandlers") as HttpHandlersSection; if (handlersSection != null) { for (var i = 0; i < handlersSection.Handlers.Count; i++) { var httpHandler = handlersSection.Handlers[i]; if (!httpHandler.Type.StartsWith("ServiceStack")) continue; SetPaths(instance, httpHandler.Path, locationPath); break; } } //IIS7+ integrated mode system.webServer/handlers if (instance.MetadataRedirectPath == null) { var webServerSection = config.GetSection("system.webServer"); if (webServerSection != null) { var rawXml = webServerSection.SectionInformation.GetRawXml(); if (!String.IsNullOrEmpty(rawXml)) { SetPaths(instance, ExtractHandlerPathFromWebServerConfigurationXml(rawXml), locationPath); } } } }