Exemple #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override protected void doDelete(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
        protected internal override void doDelete(HttpServletRequest req, HttpServletResponse resp)
        {
            LOG.debug("Resource DELETE REQUEST ========= " + req.ToString());
            string uri  = sanitise(req.RequestURI);
            string type = getType(uri);

            echoHeader(req, resp);
            string   id       = getId(uri);
            Resource resource = resources.get(type, id);

            if (resource != null)
            {
                // resource.setDeleted(true);
                resources.remove(type, id);
                resp.OutputStream.write("".GetBytes());
                resp.Status = HttpServletResponse.SC_OK;
            }
            else
            {
                notFound(resp);
            }
            resp.OutputStream.write("".GetBytes());
            resp.Status = HttpServletResponse.SC_NO_CONTENT;
            LOG.debug("Resource DELETE RESPONSE ========= " + req.ToString());
        }
Exemple #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override protected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
        protected internal override void doPost(HttpServletRequest req, HttpServletResponse resp)
        {
            LOG.debug("Resource POST REQUEST ========= " + req.ToString());
            echoHeader(req, resp);
            string uri  = sanitise(req.RequestURI);
            string type = getType(uri);

            try
            {
                string contentType = req.ContentType;
                if (contentType.Equals("application/octet-stream"))
                {
                    LOG.debug("Resource POST REQUEST is a file upload");
                    processFileUpload(req, resp);
                }
                else if (contentType.StartsWith("multipart", StringComparison.Ordinal))
                {
                    LOG.debug("Resource POST REQUEST is a multipart file upload");
                    processMultiPart(req, resp);
                }
                else
                {
                    string content = getContent(req.InputStream);
                    if (contentType.Contains("application/x-www-form-urlencoded"))
                    {
                        try
                        {
                            generateResponse(resp, type, noddyKvpToXml(content, "UTF-8"));
                        }
                        catch (Exception)
                        {
                            LOG.warn("the content passed in isn't encoded as application/x-www-form-urlencoded: " + content);
                            resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
                        }
                    }
                    else if (content.Trim().StartsWith("<", StringComparison.Ordinal) || content.Trim().EndsWith("}", StringComparison.Ordinal))
                    {
                        generateResponse(resp, type, content);
                    }
                    else
                    {
                        resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
                    }
                }
            }
            catch (Exception)
            {
                resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            }
            LOG.debug("Resource POST RESPONSE ========= " + req.ToString());
        }
Exemple #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override protected void doPut(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
        protected internal override void doPut(HttpServletRequest req, HttpServletResponse resp)
        {
            LOG.debug("Resource PUT REQUEST ========= " + req.ToString());
            echoHeader(req, resp);
            string   uri      = sanitise(req.RequestURI);
            string   id       = getId(uri);
            string   type     = getType(uri);
            string   content  = getContent(req.InputStream);
            Resource resource = resources.get(type, id);

            if (resource != null)
            {
                resource.Payload = content;
                resp.OutputStream.write("".GetBytes());
                resp.Status = HttpServletResponse.SC_OK;
            }
            else
            {
                notFound(resp);
            }
            LOG.debug("Resource PUT RESPONSE ========= " + req.ToString());
        }
Exemple #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
        protected internal override void doGet(HttpServletRequest req, HttpServletResponse resp)
        {
            LOG.debug("Resource GET REQUEST ========= " + req.ToString());
            string uri       = sanitise(req.RequestURI);
            string id        = getId(uri);
            string type      = getType(uri);
            string extension = getExtension(uri);

            echoHeader(req, resp);
            echoQString(req, resp);
            try
            {
                if (string.ReferenceEquals(id, null))
                {
                    list(resp, type, extension);
                    headers(resp, extension, DEF_CHARSET);
                }
                else if (resources.get(type, id) == null)
                {
                    notFound(resp);
                }
                else
                {
                    if (resources.get(type, id).Deleted)
                    {
                        notFound(resp);
                    }
                    else
                    {
                        found(resp, type, id);
                        headers(resp, extension, DEF_CHARSET);
                    }
                }
            }
            catch (Exception)
            {
                resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
            }
            finally
            {
                LOG.debug("Resource GET RESPONSE ========= " + resp.ToString());
            }
        }