Beispiel #1
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                var form            = _factory.BuildParamsCollectionFrom(new HttpRequest(new HttpRequestWrapper(HttpContext.Current.Request)));
                var serviceInstance = _container.Get(_type);

                var authorizationResult = _securityManager.Authorize <InvokeService>(serviceInstance);

                if (!authorizationResult.IsAuthorized)
                {
                    throw new HttpStatus.HttpStatusException(404, "Forbidden");
                }

                var result = _invoker.Invoke(_url, serviceInstance, context.Request.Url, form);
                context.Response.Write(result);
            }
            catch (Exception e)
            {
                _exceptionPublisher.Publish(e);
                if (e.InnerException is HttpStatus.HttpStatusException)
                {
                    var ex = e.InnerException as HttpStatus.HttpStatusException;
                    context.Response.StatusCode        = ex.Code;
                    context.Response.StatusDescription = ex.Description;
                }
                else
                {
                    context.Response.StatusCode        = 500;
                    context.Response.StatusDescription = e.Message.Substring(0, e.Message.Length >= 512 ? 512: e.Message.Length);
                }
            }
        }
        public Task ProcessRequest(HttpContext context)
        {
            try
            {
                var request = context.Request;
                _logger.Information($"Request : {request.Path}");

                var form            = _factory.BuildParamsCollectionFrom(new HttpRequest(context.Request));
                var serviceInstance = _container.Get(_type);

                _logger.Trace("Authorize");
                var authorizationResult = _securityManager.Authorize <InvokeService>(serviceInstance);

                if (!authorizationResult.IsAuthorized)
                {
                    _logger.Trace("Not authorized");
                    throw new HttpStatus.HttpStatusException(404, "Forbidden");
                }
                _logger.Trace("Authorized");


                var url = $"{request.Scheme}://{request.Host}{request.Path}";

                _logger.Trace($"URL : {url}");
                var result = _invoker.Invoke(_url, serviceInstance, new Uri(url), form);

                _logger.Trace($"Result : {result}");
                return(context.Response.WriteAsync(result));
            }
            catch (Exception e)
            {
                _exceptionPublisher.Publish(e);
                var message = string.Empty;
                if (e.InnerException is HttpStatus.HttpStatusException)
                {
                    var ex = e.InnerException as HttpStatus.HttpStatusException;
                    context.Response.StatusCode = ex.Code;
                    message = ex.Description;
                }
                else
                {
                    context.Response.StatusCode = 500;
                    message = e.Message.Substring(0, e.Message.Length >= 512 ? 512: e.Message.Length);
                }
                context.Response.ContentType = "application/json";
                return(context.Response.WriteAsync($"{{'message':'{message}'}}"));
            }
        }