protected static void processPostRequest(InputStream in, CommandRequest request)
        throws RequestException, IOException {
        Map<String, String> headerMap = parsePostHeaders(in);

        if (headerMap == null) {
            // illegal request
            CommandCenterLog.warn("Illegal request read: null headerMap");
            throw new RequestException(StatusCode.BAD_REQUEST, "");
        }

        if (headerMap.containsKey("content-type") && !checkContentTypeSupported(headerMap.get("content-type"))) {
            // not supported Content-type
            CommandCenterLog.warn("Request not supported: unsupported Content-Type: " + headerMap.get("content-type"));
            throw new RequestException(StatusCode.UNSUPPORTED_MEDIA_TYPE,
                "Only form-encoded post request is supported");
        }

        int bodyLength = 0;
        try {
            bodyLength = Integer.parseInt(headerMap.get("content-length"));
        } catch (Exception e) {
        }
        if (bodyLength < 1) {
            // illegal request without Content-length header
            CommandCenterLog.warn("Request not supported: no available Content-Length in headers");
            throw new RequestException(StatusCode.LENGTH_REQUIRED, "No legal Content-Length");
        }

        parseParams(readBody(in, bodyLength), request);
    }
@Test
    public void processPostRequest() throws IOException {
        CommandRequest request;
        
        request = new CommandRequest();
        request.addParam("a", "1");
        
        // illegal(empty) request
        try {
            HttpEventTask.processPostRequest(new ByteArrayInputStream("".getBytes()), request);
            assertFalse(true); // should not reach here
        } catch (Exception e) {
            assertTrue(e instanceof RequestException);
        }
        assertEquals("1", request.getParam("a"));
        
        // normal request
        try {
            HttpEventTask.processPostRequest(new ByteArrayInputStream(("Host: demo.com\r\n" + 
                    "Accept: */*\r\n" + 
                    "Accept-Language: en-us\r\n" + 
                    "Accept-Encoding: gzip, deflate\r\n" + 
                    "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" + 
                    "Connection: keep-alive\r\n" + 
                    "Content-Length: 10\r\n" + 
                    "\r\n" + 
                    "a=3&b=5的").getBytes()), request);
            assertEquals("3", request.getParam("a"));
            assertEquals("5的", request.getParam("b"));
        } catch (Exception e) {
            assertTrue(false); // should not reach here
        }
        
        // not supported request
        try {
            HttpEventTask.processPostRequest(new ByteArrayInputStream(("Host: demo.com\r\n" + 
                    "Accept: */*\r\n" + 
                    "Accept-Language: en-us\r\n" + 
                    "Accept-Encoding: gzip, deflate\r\n" + 
                    "Content-Type: application/json\r\n" + 
                    "Connection: keep-alive\r\n" + 
                    "Content-Length: 7\r\n" + 
                    "\r\n" + 
                    "a=1&b=2").getBytes()), request);
            assertTrue(false); // should not reach here
        } catch (RequestException e) {
            assertTrue(e.getStatusCode() == StatusCode.UNSUPPORTED_MEDIA_TYPE);
        }
        
        // Capacity test
        char[] buf = new char[1024 * 1024];
        Arrays.fill(buf, '&');
        String padding = new String(buf);
        try {
            request = new CommandRequest();
            HttpEventTask.processPostRequest(new ByteArrayInputStream(("Host: demo.com\r\n" + 
                    "Accept: */*\r\n" + 
                    "Accept-Language: en-us\r\n" + 
                    "Accept-Encoding: gzip, deflate\r\n" + 
                    "Content-Type: application/x-www-form-urlencoded\r\n" + 
                    "Connection: keep-alive\r\n" + 
                    "Content-Length: 7\r\n" + 
                    "\r\n" + 
                    padding +
                    "a=1&b=2").getBytes()), request);
            assertEquals(0, request.getParameters().size());
        } catch (Exception e) {
            assertTrue(false);
        }
        try {
            String querystring = "a+=+&b=%E7%9A%84的";
            request = new CommandRequest();
            HttpEventTask.processPostRequest(new ByteArrayInputStream(("Host: demo.com\r\n" + 
                    "Accept: */*\r\n" + 
                    "Accept-Language: en-us\r\n" + 
                    "Accept-Encoding: gzip, deflate\r\n" + 
                    "Content-Type: application/x-www-form-urlencoded\r\n" + 
                    "Connection: keep-alive\r\n" + 
                    "Content-Length: " + (padding.length() + querystring.getBytes().length) + "\r\n" + 
                    "\r\n" + 
                    padding +
                    querystring).getBytes()), request);
            assertEquals(2, request.getParameters().size());
            assertEquals(" ", request.getParam("a "));
            assertEquals("的的", request.getParam("b"));
        } catch (Exception e) {
            assertTrue(false);
        }
    }