protected override void RequestHandler(HttpConnectionHandler request) { Log.Add(LogLevel.Debug, "TriggerReceiver", String.Format("Received request on /{0}", request.RequestUriParts[0])); if (request.Method == HttpMethod.Post) { /*switch (request.RequestUriParts[0]) * { * case RequestUri: * ProcessRequest(request); * break; * default: * request.ResultCode = HttpResult.NotFound; * break; * }*/ if (request.RequestUriParts[0].Equals(RequestUri)) { ProcessRequest(request); } else { request.ResultCode = HttpResult.NotFound; } } else { request.ResultCode = HttpResult.MethodNotAllowed; } }
protected override void RequestHandler(HttpConnectionHandler request) { Log.Add(LogLevel.Debug, "TriggerReceiver", String.Format("Received request on /{0}", request.RequestUriParts[0])); if (request.Method == HttpMethod.Post) { /*switch (request.RequestUriParts[0]) { case RequestUri: ProcessRequest(request); break; default: request.ResultCode = HttpResult.NotFound; break; }*/ if (request.RequestUriParts[0].Equals(RequestUri)) { ProcessRequest(request); } else { request.ResultCode = HttpResult.NotFound; } } else { request.ResultCode = HttpResult.MethodNotAllowed; } }
private void ProcessRequest(HttpConnectionHandler handler) { try { int length = int.Parse(handler.GetRequestHeader("Content-Length")); byte[] requestBytes = new byte[length]; handler.RequestStream.Read(requestBytes, 0, length); string xml = Encoding.UTF8.GetString(requestBytes); var result = ProcessRequestString(xml); switch (result) { case RequestProcessingResult.Success: handler.ResultCode = HttpResult.Ok; break; case RequestProcessingResult.Error: handler.ResultCode = HttpResult.InternalServerError; break; case RequestProcessingResult.XmlError: handler.ResultCode = HttpResult.BadRequest; break; case RequestProcessingResult.ApiKeyError: handler.ResultCode = HttpResult.Forbidden; break; case RequestProcessingResult.UnknownRequest: handler.ResultCode = HttpResult.NotImplemented; break; } } catch (FormatException ex) { Log.AddException("TriggerReceiver", ex); handler.ResultCode = HttpResult.BadRequest; } catch (UnauthorizedAccessException ex) { Log.AddException("TriggerReceiver", ex); handler.ResultCode = HttpResult.Forbidden; } catch (Exception ex) { Log.AddException("TriggerReceiver", ex); handler.ResultCode = HttpResult.InternalServerError; } }
private void AsyncAcceptClient(IAsyncResult asyncResult) { if (!_runThread) return; TcpClient newClient = _listener.EndAcceptTcpClient(asyncResult); HttpConnectionHandler newHandler = new HttpConnectionHandler(newClient, CheckCredentials); newHandler.RequestHandler = RequestHandler; newHandler.StartProcessing(); _listener.BeginAcceptTcpClient(new AsyncCallback(AsyncAcceptClient), null); }
private void AsyncAcceptClient(IAsyncResult asyncResult) { if (!_runThread) { return; } TcpClient newClient = _listener.EndAcceptTcpClient(asyncResult); HttpConnectionHandler newHandler = new HttpConnectionHandler(newClient, CheckCredentials); newHandler.RequestHandler = RequestHandler; newHandler.StartProcessing(); _listener.BeginAcceptTcpClient(new AsyncCallback(AsyncAcceptClient), null); }
protected abstract void RequestHandler(HttpConnectionHandler request);