Esempio n. 1
0
        //powinien zwracać obiekt, który zostanie sparsowany do JSONa
        public object HandleRequest(HttpListenerRequest request, ref HTTPResponse response)
        {
            try
            {
                if (request.HttpMethod == "GET")
                {
                    return(HandleGET(request, ref response));
                }
                else if (request.HttpMethod == "POST")
                {
                    return(HandlePOST(request, ref response));
                }
                else if (request.HttpMethod == "PUT")
                {
                    return(HandlePUT(request, ref response));
                }
                else if (request.HttpMethod == "DELETE")
                {
                    return(HandleDELETE(request, ref response));
                }
            }
            catch (System.Exception ex)
            {
                response = HTTPResponseFactory.GetObject().CreateCodeBadRequest();
                return(response);
            }
            string baseResponse = "Invalid method";

            return(baseResponse);
        }
Esempio n. 2
0
 //metoda dopasowuje request do odpowiednego requestHandlera
 private string MatchRequest(HttpListenerRequest request, ref HTTPResponse response)
 {
     foreach (var requestHandler in _requestHandlers)
     {
         if (requestHandler.Match(request.Url.ToString()))
         {
             return(JsonConvert.SerializeObject(requestHandler.HandleRequest(request, ref response), jsonSettings));
         }
     }
     response = HTTPResponseFactory.GetObject().CreateCodeNotFound();
     return("<HTML>Unexpected error, run for you life!</HTML>");
 }
        public override object HandlePOST(HttpListenerRequest request, ref HTTPResponse response)
        {
            try
            {
                string json = GetRequestData(request);
                Poll   poll = JsonConvert.DeserializeObject <Poll>(json);

                response = ObjectsFactories.HTTPResponseFactory.GetObject().CreateCodeCreated();
                return(TemplatePollSaver.GetObject().SaveTemplatePoll(poll));
            }
            catch (Exception e)
            {
                response = HTTPResponseFactory.GetObject().CreateCodeInternalServerError();
                return(response);
            }
        }