コード例 #1
0
        private static HttpMessageHandlerOptions CreateOptions(
            IAppBuilder builder,
            HttpServer server,
            HttpConfiguration configuration
            )
        {
            Contract.Assert(builder != null);
            Contract.Assert(server != null);
            Contract.Assert(configuration != null);

            ServicesContainer services = configuration.Services;

            Contract.Assert(services != null);

            IHostBufferPolicySelector bufferPolicySelector =
                services.GetHostBufferPolicySelector() ?? _defaultBufferPolicySelector;
            IExceptionLogger  exceptionLogger  = ExceptionServices.GetLogger(services);
            IExceptionHandler exceptionHandler = ExceptionServices.GetHandler(services);

            return(new HttpMessageHandlerOptions
            {
                MessageHandler = server,
                BufferPolicySelector = bufferPolicySelector,
                ExceptionLogger = exceptionLogger,
                ExceptionHandler = exceptionHandler,
                AppDisposing = builder.GetOnAppDisposingProperty()
            });
        }
コード例 #2
0
        private static HttpMessageHandlerOptions CreateHttpMesageHandlerOptions()
        {
            var config = new HttpConfiguration();


            config.Services.Replace(typeof(IExceptionHandler), new WebApi.V2.ApiExceptionHandler());
            config.Services.Replace(typeof(IHttpControllerSelector), new ServiceUnitApiControllerSelector(config));
            config.Services.Replace(typeof(IHttpControllerActivator), new ServiceUnitApiControllerActivator(config));
            //authorize
            config.Services.Replace(typeof(IHttpActionSelector), new ServiceUnitApiActionSelector(config));

            config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            config.Formatters.JsonFormatter.SerializerSettings.DateTimeZoneHandling  = DateTimeZoneHandling.Utc;


            HttpServer        httpServer = new HttpServer(config, new ServiceUnitRequestDispatcher(config));
            ServicesContainer services   = config.Services;

            return(new HttpMessageHandlerOptions()
            {
                MessageHandler = httpServer,
                BufferPolicySelector = services.GetHostBufferPolicySelector() ?? new OwinBufferPolicySelector(),
                ExceptionLogger = ExceptionServices.GetLogger(services),
                ExceptionHandler = ExceptionServices.GetHandler(services),
            });
        }
コード例 #3
0
 public HttpRouteExceptionHandler(ExceptionDispatchInfo exceptionInfo)
     : this(
         exceptionInfo,
         ExceptionServices.GetLogger(GlobalConfiguration.Configuration),
         ExceptionServices.GetHandler(GlobalConfiguration.Configuration)
         )
 {
 }
コード例 #4
0
        public virtual Task <HttpResponseMessage> ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)
        {
            if (_initialized)
            {
                // if user has registered a controller factory which produces the same controller instance, we should throw here
                throw Error.InvalidOperation(SRResources.CannotSupportSingletonInstance, typeof(ApiController).Name, typeof(IHttpControllerActivator).Name);
            }

            Initialize(controllerContext);

            // We can't be reused, and we know we're disposable, so make sure we go away when
            // the request has been completed.
            if (Request != null)
            {
                Request.RegisterForDispose(this);
            }

            HttpControllerDescriptor controllerDescriptor = controllerContext.ControllerDescriptor;
            ServicesContainer        controllerServices   = controllerDescriptor.Configuration.Services;

            HttpActionDescriptor actionDescriptor = controllerServices.GetActionSelector().SelectAction(controllerContext);

            ActionContext.ActionDescriptor = actionDescriptor;
            if (Request != null)
            {
                Request.SetActionDescriptor(actionDescriptor);
            }

            FilterGrouping filterGrouping = actionDescriptor.GetFilterGrouping();

            IActionFilter[]         actionFilters         = filterGrouping.ActionFilters;
            IAuthenticationFilter[] authenticationFilters = filterGrouping.AuthenticationFilters;
            IAuthorizationFilter[]  authorizationFilters  = filterGrouping.AuthorizationFilters;
            IExceptionFilter[]      exceptionFilters      = filterGrouping.ExceptionFilters;

            IHttpActionResult result = new ActionFilterResult(actionDescriptor.ActionBinding, ActionContext,
                                                              controllerServices, actionFilters);

            if (authorizationFilters.Length > 0)
            {
                result = new AuthorizationFilterResult(ActionContext, authorizationFilters, result);
            }
            if (authenticationFilters.Length > 0)
            {
                result = new AuthenticationFilterResult(ActionContext, this, authenticationFilters, result);
            }
            if (exceptionFilters.Length > 0)
            {
                IExceptionLogger  exceptionLogger  = ExceptionServices.GetLogger(controllerServices);
                IExceptionHandler exceptionHandler = ExceptionServices.GetHandler(controllerServices);
                result = new ExceptionFilterResult(ActionContext, exceptionFilters, exceptionLogger, exceptionHandler,
                                                   result);
            }

            return(result.ExecuteAsync(cancellationToken));
        }
コード例 #5
0
        public void ExceptionHandler_IfUsingExceptionInfoConstructor_ReturnsExceptionServicesInstance()
        {
            // Arrange
            ExceptionDispatchInfo     exceptionInfo = CreateExceptionInfo();
            HttpRouteExceptionHandler product       = CreateProductUnderTest(exceptionInfo);

            // Act
            IExceptionHandler handler = product.ExceptionHandler;

            // Assert
            IExceptionHandler expectedHandler = ExceptionServices.GetHandler(GlobalConfiguration.Configuration);

            Assert.Same(expectedHandler, handler);
        }
コード例 #6
0
ファイル: DefaultCommandWorker.cs プロジェクト: ctguxp/Waffle
        /// <summary>
        /// Execute the request via the worker.
        /// </summary>
        /// <param name="request">The <see cref="HandlerRequest"/> to execute.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> to cancel the execution.</param>
        /// <returns>The result of the command, if any.</returns>
        public Task <HandlerResponse> ExecuteAsync(CommandHandlerRequest request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            cancellationToken.ThrowIfCancellationRequested();
            ServicesContainer        servicesContainer = request.Configuration.Services;
            ICommandHandlerSelector  handlerSelector   = servicesContainer.GetHandlerSelector();
            CommandHandlerDescriptor descriptor        = handlerSelector.SelectHandler(request);

            ICommandHandler commandHandler = descriptor.CreateHandler(request);

            if (commandHandler == null)
            {
                throw CreateHandlerNotFoundException(descriptor);
            }

            request.RegisterForDispose(commandHandler, true);
            CommandHandlerContext context = new CommandHandlerContext(request, descriptor);

            context.Handler = commandHandler;
            commandHandler.CommandContext = context;

            CommandFilterGrouping commandFilterGrouping = descriptor.GetFilterGrouping();

            ICommandHandlerResult result = new CommandHandlerFilterResult(context, servicesContainer, commandFilterGrouping.CommandHandlerFilters);

            if (descriptor.RetryPolicy != RetryPolicy.NoRetry)
            {
                result = new RetryHandlerResult(descriptor.RetryPolicy, result);
            }

            if (commandFilterGrouping.ExceptionFilters.Length > 0)
            {
                IExceptionLogger  exceptionLogger  = ExceptionServices.GetLogger(servicesContainer);
                IExceptionHandler exceptionHandler = ExceptionServices.GetHandler(servicesContainer);
                result = new ExceptionFilterResult(context, commandFilterGrouping.ExceptionFilters, exceptionLogger, exceptionHandler, result);
            }

            return(result.ExecuteAsync(cancellationToken));
        }
コード例 #7
0
        private static HttpMessageHandlerOptions CreateOptions(IApplicationBuilder builder, HttpServer server,
                                                               HttpConfiguration configuration, bool bufferRequests)
        {
            Contract.Assert(builder != null);
            Contract.Assert(server != null);
            Contract.Assert(configuration != null);

            ServicesContainer services = configuration.Services;

            Contract.Assert(services != null);

            IHostBufferPolicySelector bufferPolicySelector = services.GetHostBufferPolicySelector()
                                                             ?? new AspNetCoreBufferPolicySelector(bufferRequests);
            IExceptionLogger  exceptionLogger  = ExceptionServices.GetLogger(services);
            IExceptionHandler exceptionHandler = ExceptionServices.GetHandler(services);

            return(new HttpMessageHandlerOptions
            {
                MessageHandler = server,
                BufferPolicySelector = bufferPolicySelector,
                ExceptionLogger = exceptionLogger,
                ExceptionHandler = exceptionHandler,
            });
        }
コード例 #8
0
 private IExceptionHandler CreateExceptionServicesHandler()
 {
     return(ExceptionServices.CreateHandler(this));
 }
コード例 #9
0
 private IExceptionLogger CreateExceptionServicesLogger()
 {
     return(ExceptionServices.CreateLogger(this));
 }