private object ExecuteAnonymousMethod(RestControllerMethodInfo info, HttpRequest request)
        {
            var instantiator = InstanceCreatorCache.Default.GetCreator(info.MethodInfo.DeclaringType);

            object bodyObj = null;
            try
            {
                bodyObj = _bodySerializer.FromBody(request.Content, request.RequestContentType, info.BodyParameterType);
            }
            catch (JsonReaderException)
            {
                return _responseFactory.CreateBadRequest();
            }
            catch (InvalidOperationException)
            {
                return _responseFactory.CreateBadRequest();
            }

            object[] parameters = null;
            try
            {
                parameters = info.GetParametersFromUri(request.Uri).Concat(new[] { bodyObj }).ToArray();
            }
            catch (FormatException)
            {
                return _responseFactory.CreateBadRequest();
            }

            return info.MethodInfo.Invoke(
                    instantiator.Create(info.MethodInfo.DeclaringType, info.ControllerConstructorArgs()),
                    parameters);
        }
예제 #2
0
        public async Task<IRestResponse> ExecuteMethodAsync(RestControllerMethodInfo info, HttpRequest request)
        {
            var methodInvokeResult = ExecuteAnonymousMethod(info, request);

            if (!info.IsAsync)
                return (IRestResponse)methodInvokeResult;

            return await (dynamic)methodInvokeResult;
        }
예제 #3
0
        internal string ToBody(object bodyObject, HttpRequest req)
        {
            if (bodyObject == null)
            {
                return null;
            }

            if (req.ResponseContentType == MediaType.JSON)
            {
                return JsonConvert.SerializeObject(bodyObject);
            }
            else if (req.ResponseContentType == MediaType.XML)
            {
                return XmlSerializeObject(bodyObject);
            }

            return null;
        }
예제 #4
0
        private object ExecuteAnonymousMethod(RestControllerMethodInfo info, HttpRequest request)
        {
            var instantiator = InstanceCreatorCache.Default.GetCreator(info.MethodInfo.DeclaringType);

            object[] parameters = null;
            try
            {
                parameters = info.GetParametersFromUri(request.Uri).ToArray();
            }
            catch (FormatException)
            {
                return _responseFactory.CreateBadRequest();
            }

            return info.MethodInfo.Invoke(
                    instantiator.Create(info.MethodInfo.DeclaringType, info.ControllerConstructorArgs()),
                    parameters);
        }
예제 #5
0
파일: HttpServer.cs 프로젝트: Ferho/restup
 internal abstract Task<IHttpResponse> HandleRequest(HttpRequest request);