Ejemplo n.º 1
0
        public IServiceStackHttpHandler GetCustomErrorHandler(HttpStatusCode errorStatus)
        {
            IServiceStackHttpHandler httpHandler = null;

            if (CustomHttpHandlers != null)
            {
                CustomHttpHandlers.TryGetValue(errorStatus, out httpHandler);
            }
            return(httpHandler ?? GlobalHtmlErrorHttpHandler);
        }
 public ServiceStackHttpHandler(IServiceStackHttpHandler servicestackHandler)
 {
     this.servicestackHandler = servicestackHandler;
 }
 public ServiceStackHttpHandler(IServiceStackHttpHandler servicestackHandler)
 {
     this.servicestackHandler = servicestackHandler;
 }
Ejemplo n.º 4
0
        private void ProcessRequest(MessageContext context)
        {
            //NOTE: This method is called on a background thread and must be protected by an outer big-try catch

            var httpReq = new RequestWrapper(context.Request);
            var httpRes = new ResponseWrapper();

            IServiceStackHttpHandler handler = null;
            string operationName, contentType;

            //var handler = ServiceStackHttpHandlerFactory.GetHandler(httpReq);

            var restPath = RestHandler.FindMatchingRestPath(httpReq.HttpMethod, httpReq.PathInfo, out contentType);

            if (restPath != null)
            {
                handler = new RestHandler {
                    RestPath = restPath, RequestName = restPath.RequestType.Name
                };
                httpReq.OperationName = operationName = ((RestHandler)handler).RestPath.RequestType.Name;
            }
            else
            {
                handler = new NotFoundHttpHandler();
                var stream = httpRes.OutputStream; //Bug fix: reading the OutputStream property will cause it to be created if it's null
                httpReq.OperationName = operationName = null;
            }

            HttpResponsePacket resPacket = null;

            try
            {
                handler.ProcessRequest(httpReq, httpRes, operationName);
                resPacket = CreateResponsePacketFromWrapper(httpRes, subscriber);
            }
            catch (Exception exception)
            {
                //Send Exception details back to Queue
                resPacket = CreateResponsePacketFromException(exception);
            }
            finally
            {
                httpReq.InputStream.Close();
                httpRes.Close();
            }


            if (resPacket == null)
            {
                //TODO: Not good, Log this
                //TODO: derive exception from RestBus.Exceptions class
                resPacket = CreateResponsePacketFromException(new ApplicationException("Unable to get response"));
            }

            try
            {
                //TODO: Why can't the subscriber append the subscriber id itself from within sendresponse
                subscriber.SendResponse(context, resPacket);
            }
            catch
            {
                //TODO: Log SendResponse error
            }
        }