コード例 #1
0
 private void OnPostShutdown(HttpEntity entity, UriTemplateMatch match)
 {
     Publish(new ClientMessage.RequestShutdown());
     entity.Manager.Reply(HttpStatusCode.OK,
                          "OK",
                          e => Log.ErrorException(e, "Error while closing http connection (admin controller)"));
 }
コード例 #2
0
ファイル: Configure.cs プロジェクト: vishal-h/EventStore-1
        public static ResponseConfiguration ReadEventCompleted(HttpEntity entity, Message message)
        {
            Debug.Assert(message.GetType() == typeof(ClientMessage.ReadEventCompleted));

            var completed = message as ClientMessage.ReadEventCompleted;
            if (completed == null)
                return InternalServerEror(entity, message);

            switch (completed.Result)
            {
                case SingleReadResult.Success:
                    return new ResponseConfiguration(HttpStatusCode.OK, 
                                                     "OK",
                                                     entity.ResponseCodec.ContentType,
                                                     new KeyValuePair<string, string>(
                                                         "Cache-Control",
                                                         string.Format("max-age={0}", MaxPossibleAge)));
                case SingleReadResult.NotFound:
                case SingleReadResult.NoStream:
                    return NotFound(entity, completed);
                case SingleReadResult.StreamDeleted:
                    return Gone(entity, completed);
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
コード例 #3
0
        private void OnGetFreshStats(HttpEntity entity, UriTemplateMatch match)
        {
            var envelope = new SendToHttpEnvelope(_networkSendQueue,
                                                  entity,
                                                  Format.GetFreshStatsCompleted,
                                                  Configure.GetFreshStatsCompleted);

            var statPath = match.BoundVariables["statPath"];
            var statSelector = GetStatSelector(statPath);

            bool useMetadata;
            if (!bool.TryParse(match.QueryParameters["metadata"], out useMetadata))
                useMetadata = false;

            bool useGrouping;
            if (!bool.TryParse(match.QueryParameters["group"], out useGrouping))
                useGrouping = true;

            if (!useGrouping && !string.IsNullOrEmpty(statPath))
            {
                SendBadRequest(entity, "Dynamic stats selection works only with grouping enabled");
                return;
            }
             
            Publish(new MonitoringMessage.GetFreshStats(envelope, statSelector, useMetadata, useGrouping));
        }
コード例 #4
0
        internal HttpEntityManager(
            HttpEntity httpEntity, string[] allowedMethods, Action <HttpEntity> onRequestSatisfied, ICodec requestCodec,
            ICodec responseCodec, bool logHttpRequests)
        {
            Ensure.NotNull(httpEntity, "httpEntity");
            Ensure.NotNull(allowedMethods, "allowedMethods");
            Ensure.NotNull(onRequestSatisfied, "onRequestSatisfied");

            HttpEntity = httpEntity;
            TimeStamp  = DateTime.UtcNow;

            _allowedMethods          = allowedMethods;
            _onRequestSatisfied      = onRequestSatisfied;
            _requestCodec            = requestCodec;
            _responseCodec           = responseCodec;
            _responseUrl             = httpEntity.ResponseUrl;
            _requestedUrl            = httpEntity.RequestedUrl;
            _responseContentEncoding = GetRequestedContentEncoding(httpEntity);
            _logHttpRequests         = logHttpRequests;

            if (HttpEntity.Request != null && HttpEntity.Request.ContentLength64 == 0)
            {
                LogRequest(new byte[0]);
            }
        }
コード例 #5
0
ファイル: Configure.cs プロジェクト: slavah/EventStore
        public static ResponseConfiguration CreateStreamCompleted(HttpEntity entity, Message message)
        {
            Debug.Assert(message.GetType() == typeof(ClientMessage.CreateStreamCompleted));

            var completed = message as ClientMessage.CreateStreamCompleted;
            if (completed == null)
                return InternalServerEror(entity, message);

            switch (completed.ErrorCode)
            {
                case OperationErrorCode.Success:
                    return new ResponseConfiguration(HttpStatusCode.Created,
                                                     "Stream created",
                                                     null,
                                                     new KeyValuePair<string, string>("Location",
                                                                                      HostName.Combine(entity.UserHostName,
                                                                                                  "/streams/{0}",
                                                                                                  completed.EventStreamId)));
                case OperationErrorCode.PrepareTimeout:
                case OperationErrorCode.CommitTimeout:
                case OperationErrorCode.ForwardTimeout:
                    return new ResponseConfiguration(HttpStatusCode.InternalServerError, "Create timeout", null);
                case OperationErrorCode.WrongExpectedVersion:
                case OperationErrorCode.StreamDeleted:
                case OperationErrorCode.InvalidTransaction:
                    return new ResponseConfiguration(HttpStatusCode.BadRequest,
                                                     string.Format("Error code : {0}. Reason : {1}", completed.ErrorCode, completed.Error),
                                                     null);
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
コード例 #6
0
ファイル: Format.cs プロジェクト: alistair/EventStore
        public static string TextMessage(HttpEntity entity, Message message)
        {
            Debug.Assert(message.GetType() == typeof(HttpMessage.TextMessage));

            var textMessage = message as HttpMessage.TextMessage;
            return textMessage != null ? entity.ResponseCodec.To(textMessage) : string.Empty;
        }
コード例 #7
0
        private string GetRequestedContentEncoding(HttpEntity httpEntity)
        {
            if (httpEntity == null || httpEntity.Request == null)
            {
                return(null);
            }

            var    httpEntityRequest = httpEntity.Request;
            string contentEncoding   = null;
            var    values            = httpEntityRequest.Headers.GetValues("Accept-Encoding");

            if (values != null)
            {
                foreach (string value in values)
                {
                    if (SupportedCompressionAlgorithms.Contains(value))
                    {
                        contentEncoding = value;
                        break;
                    }
                }
            }

            return(contentEncoding);
        }
コード例 #8
0
ファイル: Format.cs プロジェクト: vishal-h/EventStore-1
            public static string ReadEventsBackwardsCompletedFeed(HttpEntity entity, Message message, int start, int count)
            {
                Debug.Assert(message.GetType() == typeof(ClientMessage.ReadEventsBackwardsCompleted));

                var completed = message as ClientMessage.ReadEventsBackwardsCompleted;
                if (completed != null)
                {
                    switch (completed.Result)
                    {
                        case RangeReadResult.Success:
                            var updateTime = completed.Events.Length != 0
                                                 ? completed.Events[0].TimeStamp
                                                 : DateTime.MinValue.ToUniversalTime();
                            return entity.ResponseCodec.To(Convert.ToFeed(completed.EventStreamId,
                                                                          start,
                                                                          count,
                                                                          updateTime,
                                                                          completed.Events,
                                                                          Convert.ToEntry,
                                                                          entity.ServerHttpEndPoint));
                        case RangeReadResult.NoStream:
                        case RangeReadResult.StreamDeleted:
                            return string.Empty;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                }
                return string.Empty;
            }
コード例 #9
0
        private HttpEntity(HttpEntity httpEntity, IPrincipal user)
        {
            RequestedUrl = httpEntity.RequestedUrl;

            Request  = httpEntity.Request;
            Response = httpEntity.Response;
            User     = user;
        }
コード例 #10
0
ファイル: HttpEntity.cs プロジェクト: adbrowne/EventStore
        private HttpEntity(HttpEntity httpEntity, IPrincipal user)
        {
            RequestedUrl = httpEntity.RequestedUrl;

            Request = httpEntity.Request;
            Response = httpEntity.Response;
            User = user;
        }
コード例 #11
0
 private void OnPostShutdown(HttpEntity entity, UriTemplateMatch match)
 {
     Log.Info("Request shut down of node because shutdown command has been received.");
     Publish(new ClientMessage.RequestShutdown(exitProcessOnShutdown: true));
     entity.Manager.ReplyStatus(HttpStatusCode.OK,
                          "OK",
                          e => Log.ErrorException(e, "Error while closing http connection (admin controller)"));
 }
コード例 #12
0
ファイル: HttpEntity.cs プロジェクト: jeryhu/EventStore
        private HttpEntity(HttpEntity httpEntity, IPrincipal user, bool logHttpRequests)
        {
            RequestedUrl = httpEntity.RequestedUrl;

            Request          = httpEntity.Request;
            Response         = httpEntity.Response;
            User             = user;
            _logHttpRequests = logHttpRequests;
        }
コード例 #13
0
        public ManagerOperationState(HttpEntity entity, Action<HttpEntityManager, string> onSuccess, Action<Exception> onError)
        {
            Ensure.NotNull(entity, "entity");
            Ensure.NotNull(onSuccess, "onSuccess");
            Ensure.NotNull(onError, "onError");

            Entity = entity;
            OnSuccess = onSuccess;
            OnError = onError;
        }
コード例 #14
0
 private void OnGetPing(HttpEntity entity, UriTemplateMatch match)
 {
     var response = new HttpMessage.TextMessage("Ping request successfully handled");
     entity.Manager.Reply(Format.TextMessage(entity, response),
                          HttpStatusCode.OK,
                          "OK",
                          entity.ResponseCodec.ContentType,
                          null,
                          e => Log.ErrorException(e, "Error while writing http response (ping)"));
 }
コード例 #15
0
ファイル: Format.cs プロジェクト: alistair/EventStore
        public static string GetFreshStatsCompleted(HttpEntity entity, Message message)
        {
            Debug.Assert(message.GetType() == typeof(MonitoringMessage.GetFreshStatsCompleted));

            var completed = message as MonitoringMessage.GetFreshStatsCompleted;
            if (completed == null || !completed.Success)
                return string.Empty;

            return entity.ResponseCodec.To(completed.Stats);
        }
コード例 #16
0
        public ManagerOperationState(HttpEntity entity, Action <HttpEntityManager, byte[]> onSuccess, Action <Exception> onError)
        {
            Ensure.NotNull(entity, "entity");
            Ensure.NotNull(onSuccess, "onSuccess");
            Ensure.NotNull(onError, "onError");

            Entity    = entity;
            OnSuccess = onSuccess;
            OnError   = onError;
        }
コード例 #17
0
        internal HttpEntityManager(HttpEntity httpEntity, string[] allowedMethods, Action <HttpEntity> onRequestSatisfied)
        {
            Ensure.NotNull(httpEntity, "httpEntity");
            Ensure.NotNull(allowedMethods, "allowedMethods");
            Ensure.NotNull(onRequestSatisfied, "onRequestSatisfied");

            HttpEntity = httpEntity;

            _allowedMethods     = allowedMethods;
            _onRequestSatisfied = onRequestSatisfied;
        }
コード例 #18
0
ファイル: HttpEntity.cs プロジェクト: zerox981/EventStore
        private HttpEntity(HttpEntity httpEntity, ClaimsPrincipal user, bool logHttpRequests)
        {
            RequestedUrl = httpEntity.RequestedUrl;
            ResponseUrl  = httpEntity.ResponseUrl;

            Request          = httpEntity.Request;
            Response         = httpEntity.Response;
            User             = user;
            _logHttpRequests = logHttpRequests;
            OnComplete       = httpEntity.OnComplete;
        }
コード例 #19
0
        internal HttpEntityManager(HttpEntity httpEntity, string[] allowedMethods, Action<HttpEntity> onRequestSatisfied)
        {
            Ensure.NotNull(httpEntity, "httpEntity");
            Ensure.NotNull(allowedMethods, "allowedMethods");
            Ensure.NotNull(onRequestSatisfied, "onRequestSatisfied");

            HttpEntity = httpEntity;

            _allowedMethods = allowedMethods;
            _onRequestSatisfied = onRequestSatisfied;
        }
コード例 #20
0
ファイル: Format.cs プロジェクト: vishal-h/EventStore-1
            public static string ListStreamsCompletedServiceDoc(HttpEntity entity, Message message)
            {
                Debug.Assert(message.GetType() == typeof(ClientMessage.ListStreamsCompleted));

                var streams = message as ClientMessage.ListStreamsCompleted;
                return streams != null
                           ? entity.ResponseCodec.To(Convert.ToServiceDocument(streams.Streams,
                                                                               new string[0],
                                                                               entity.ServerHttpEndPoint))
                           : string.Empty;
            }
コード例 #21
0
        private void ReplyWithContent(HttpEntity http, string contentLocalPath)
        {
            //NOTE: this is fix for Mono incompatibility in UriTemplate behavior for /a/b{*C}
            if (("/" + contentLocalPath).StartsWith(_localWebRootPath))
            {
                contentLocalPath = contentLocalPath.Substring(_localWebRootPath.Length);
            }
            //_logger.Trace("{0} requested from mini web", contentLocalPath);
            try
            {
                var extensionToContentType = new Dictionary<string, string>
                {
                    { ".png",  "image/png"} ,
                    { ".jpg",  "image/jpeg"} ,
                    { ".jpeg", "image/jpeg"} ,
                    { ".css",  "text/css"} ,
                    { ".htm",  "text/html"} ,
                    { ".html", "text/html"} ,
                    { ".js",   "application/javascript"} ,
                    { ".ico",  "image/vnd.microsoft.icon"}
                };

                var extension = Path.GetExtension(contentLocalPath);
                var fullPath = Path.Combine(_fileSystemRoot, contentLocalPath);

                string contentType;
                if (string.IsNullOrEmpty(extension)
                    || !extensionToContentType.TryGetValue(extension, out contentType)
                    || !File.Exists(fullPath))
                {
                    _logger.Info("Replying 404 for {0} ==> {1}", contentLocalPath, fullPath);
                    http.Manager.ReplyTextContent(
                        "Not Found", 404, "Not Found", "text/plain", null, 
                        ex => _logger.InfoException(ex, "Error while replying from MiniWeb"));
                }
                else
                {
                    var config = GetWebPageConfig(contentType);
                    var content = File.ReadAllBytes(fullPath);

                    http.Manager.Reply(content,
                                       config.Code,
                                       config.Description,
                                       config.ContentType,
                                       config.Headers,
                                       ex => _logger.InfoException(ex, "Error while replying from MiniWeb"));
                }
            }
            catch (Exception ex)
            {
                http.Manager.ReplyTextContent(ex.ToString(), 500, "Internal Server Error", "text/plain", null, Console.WriteLine);
            }
        }
コード例 #22
0
 public void GetAllBefore(HttpEntity entity, TFPos position, int count)
 {
     var envelope = new SendToHttpEnvelope(entity,
                                           Format.Atom.ReadAllEventsBackwardCompleted,
                                           Configure.ReadAllEventsBackwardCompleted);
     Publish(new ClientMessage.ReadAllEventsBackward(Guid.NewGuid(),
                                                     envelope,
                                                     position.CommitPosition,
                                                     position.PreparePosition,
                                                     count,
                                                     true));
 }
コード例 #23
0
ファイル: StatController.cs プロジェクト: jpierson/EventStore
        private void OnGetFreshStats(HttpEntity entity, UriTemplateMatch match)
        {
            var envelope = new SendToHttpEnvelope(
                    entity,
                    Format.GetFreshStatsCompleted,
                    Configure.GetFreshStatsCompleted);

            var statPath = match.BoundVariables["statPath"];
            var statSelector = GetStatSelector(statPath);

            Publish(new MonitoringMessage.GetFreshStats(envelope, statSelector));
        }
コード例 #24
0
        internal HttpEntityManager(
            HttpEntity httpEntity, string[] allowedMethods, Action <HttpEntity> onRequestSatisfied, ICodec requestCodec,
            ICodec responseCodec)
        {
            Ensure.NotNull(httpEntity, "httpEntity");
            Ensure.NotNull(allowedMethods, "allowedMethods");
            Ensure.NotNull(onRequestSatisfied, "onRequestSatisfied");

            HttpEntity = httpEntity;
            TimeStamp  = DateTime.UtcNow;

            _allowedMethods     = allowedMethods;
            _onRequestSatisfied = onRequestSatisfied;
            _requestCodec       = requestCodec;
            _responseCodec      = responseCodec;
            _requestedUrl       = httpEntity.RequestedUrl;
        }
コード例 #25
0
        internal HttpEntityManager(
            HttpEntity httpEntity, string[] allowedMethods, Action<HttpEntity> onRequestSatisfied, ICodec requestCodec,
            ICodec responseCodec)
        {
            Ensure.NotNull(httpEntity, "httpEntity");
            Ensure.NotNull(allowedMethods, "allowedMethods");
            Ensure.NotNull(onRequestSatisfied, "onRequestSatisfied");

            HttpEntity = httpEntity;
            TimeStamp = DateTime.UtcNow;

            _allowedMethods = allowedMethods;
            _onRequestSatisfied = onRequestSatisfied;
            _requestCodec = requestCodec;
            _responseCodec = responseCodec;
            _requestedUrl = httpEntity.RequestedUrl;
        }
コード例 #26
0
        private void OnGetRead(HttpEntity entity, UriTemplateMatch match)
        {
            var stream = match.BoundVariables["stream"];
            var versionString = match.BoundVariables["version"];
            var resolve = match.BoundVariables["resolve"] ?? "yes";
            //TODO: reply invalid ??? if neither NO nor YES
            int version;

            if (string.IsNullOrEmpty(stream) || !Int32.TryParse(versionString, out version))
            {
                SendBadRequest(entity, "Stream must bu non-empty string and id must be integer value");
                return;
            }

            var envelope = new SendToHttpEnvelope(entity, Format.ReadEventCompleted, Configure.ReadEventCompleted);
            Publish(
                new ClientMessage.ReadEvent(
                    Guid.NewGuid(), envelope, stream, version, resolve.Equals("yes", StringComparison.OrdinalIgnoreCase)));
        }
コード例 #27
0
ファイル: Format.cs プロジェクト: vishal-h/EventStore-1
            public static string ReadEventCompletedEntry(HttpEntity entity, Message message)
            {
                Debug.Assert(message.GetType() == typeof(ClientMessage.ReadEventCompleted));

                var completed = message as ClientMessage.ReadEventCompleted;
                if (completed != null)
                {
                    switch (completed.Result)
                    {
                        case SingleReadResult.Success:
                            return entity.ResponseCodec.To(Convert.ToEntry(completed.Record, entity.ServerHttpEndPoint));
                        case SingleReadResult.NotFound:
                        case SingleReadResult.NoStream:
                        case SingleReadResult.StreamDeleted:
                            return string.Empty;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                }
                return string.Empty;
            }
コード例 #28
0
        internal HttpEntityManager(
            HttpEntity httpEntity, string[] allowedMethods, Action<HttpEntity> onRequestSatisfied, ICodec requestCodec,
            ICodec responseCodec, bool logHttpRequests)
        {
            Ensure.NotNull(httpEntity, "httpEntity");
            Ensure.NotNull(allowedMethods, "allowedMethods");
            Ensure.NotNull(onRequestSatisfied, "onRequestSatisfied");

            HttpEntity = httpEntity;
            TimeStamp = DateTime.UtcNow;

            _allowedMethods = allowedMethods;
            _onRequestSatisfied = onRequestSatisfied;
            _requestCodec = requestCodec;
            _responseCodec = responseCodec;
            _requestedUrl = httpEntity.RequestedUrl;
            _logHttpRequests = logHttpRequests;

            if (HttpEntity.Request != null && HttpEntity.Request.ContentLength64 == 0)
            {
                LogRequest(new byte[0]);
            }
        }
コード例 #29
0
ファイル: Format.cs プロジェクト: vishal-h/EventStore-1
 public static string WriteEventsCompleted(HttpEntity entity, Message message)
 {
     Debug.Assert(message.GetType() == typeof(ClientMessage.WriteEventsCompleted));
     return string.Empty;
 }
コード例 #30
0
ファイル: Format.cs プロジェクト: vishal-h/EventStore-1
 public static string DeleteStreamCompleted(HttpEntity entity, Message message)
 {
     Debug.Assert(message.GetType() == typeof(ClientMessage.DeleteStreamCompleted));
     return string.Empty;
 }
コード例 #31
0
 public static void ReplyNotYetAvailable(HttpEntity entity)
 {
     var manager = entity.CreateManager();
     manager.ReplyStatus(HttpStatusCode.ServiceUnavailable, "Not yet ready.", exception => { }, new [] {new KeyValuePair<string, string>("Retry-After", "5") });
 }
コード例 #32
0
 public AuthenticatedHttpRequestMessage(HttpService httpService, HttpEntity entity)
 {
     HttpService = httpService;
     Entity = entity;
 }
コード例 #33
0
 public IncomingHttpRequestMessage(HttpService httpService, HttpEntity entity, IPublisher nextStagePublisher)
 {
     HttpService = httpService;
     Entity = entity;
     NextStagePublisher = nextStagePublisher;
 }
コード例 #34
0
ファイル: Configure.cs プロジェクト: slavah/EventStore
 public static ResponseConfiguration Ok(HttpEntity entity, Message message)
 {
     return new ResponseConfiguration(HttpStatusCode.OK, "OK", entity.ResponseCodec.ContentType);
 }
コード例 #35
0
ファイル: Configure.cs プロジェクト: slavah/EventStore
        public static ResponseConfiguration ReadEventsFromEndCompleted(HttpEntity entity, Message message)
        {
            Debug.Assert(message.GetType() == typeof(ClientMessage.ReadEventsBackwardsCompleted));

            var completed = message as ClientMessage.ReadEventsBackwardsCompleted;
            if (completed == null)
                return InternalServerEror(entity, message);

            var startIdx = (int)entity.Manager.AsyncState;
            var age = startIdx < AtomSpecs.FeedPageSize ? MinPossibleAge : MaxPossibleAge;

            switch (completed.Result)
            {
                case RangeReadResult.Success:
                    return new ResponseConfiguration(HttpStatusCode.OK,
                                                     "OK",
                                                     entity.ResponseCodec.ContentType,
                                                     new KeyValuePair<string, string>(
                                                         "Cache-Control",
                                                         string.Format("max-age={0}", age)));
                case RangeReadResult.NoStream:
                    return NotFound(entity, completed);
                case RangeReadResult.StreamDeleted:
                    return Gone(entity, completed);
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
コード例 #36
0
 internal static HttpEntityManager Create(HttpEntity httpEntity,
                                          string[] allowedMethods,
                                          Action <HttpEntity> onRequestSatisfied)
 {
     return(new HttpEntityManager(httpEntity, allowedMethods, onRequestSatisfied));
 }
コード例 #37
0
 public static void ReplyUnauthorized(HttpEntity entity)
 {
     var manager = entity.CreateManager();
     manager.ReplyStatus(HttpStatusCode.Unauthorized, "Unauthorized", exception => { });
 }
コード例 #38
0
 public static void ReplyInternalServerError(HttpEntity entity)
 {
     var manager = entity.CreateManager();
     manager.ReplyStatus(HttpStatusCode.InternalServerError, "Internal Server Error", exception => { });
 }
コード例 #39
0
ファイル: MiniWeb.cs プロジェクト: robashton/EventStore
 private void OnStaticContent(HttpEntity http, UriTemplateMatch match)
 {
     var contentLocalPath = match.BoundVariables["remaining_path"];
     ReplyWithContent(http, contentLocalPath);
 }