{"record":{"id":"d113538b5277d4da","repo":"alibaba/arthas","slug":"parse-request-failed-request-body-is-empty","errorCode":null,"errorMessage":"parse request failed: request body is empty","messagePattern":"parse request failed: request body is empty","errorType":"http","errorClass":"ApiException","httpStatus":200,"severity":"error","filePath":"core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java","lineNumber":105,"sourceCode":"            logger.error(\"arthas process http api request error: \" + request.uri() + \", request body: \" + requestBody, e);\n        }\n        if (result == null) {\n            result = createResponse(ApiState.FAILED, \"The request was not processed\");\n        }\n        result.setRequestId(requestId);\n\n        byte[] jsonBytes = JSON.toJSONBytes(result, JSON_FILTERS);\n\n        // create http response\n        DefaultFullHttpResponse response = new DefaultFullHttpResponse(request.protocolVersion(),\n                HttpResponseStatus.OK, Unpooled.wrappedBuffer(jsonBytes));\n        response.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json; charset=utf-8\");\n        return response;\n    }\n\n    private ApiRequest parseRequest(String requestBody) throws ApiException {\n        if (StringUtils.isBlank(requestBody)) {\n            throw new ApiException(\"parse request failed: request body is empty\");\n        }\n        try {\n            //ObjectMapper objectMapper = new ObjectMapper();\n            //return objectMapper.readValue(requestBody, ApiRequest.class);\n            return JSON.parseObject(requestBody, ApiRequest.class);\n        } catch (Exception e) {\n            throw new ApiException(\"parse request failed: \" + e.getMessage(), e);\n        }\n    }\n\n    private ApiResponse processRequest(ChannelHandlerContext ctx, ApiRequest apiRequest) {\n\n        String actionStr = apiRequest.getAction();\n        try {\n            if (StringUtils.isBlank(actionStr)) {\n                throw new ApiException(\"'action' is required\");\n            }\n            ApiAction action;","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java#L87-L123","documentation":"Thrown by HttpApiHandler.parseRequest when the HTTP request body is blank (null, empty, or whitespace only). The Arthas HTTP API expects a JSON body containing at minimum an 'action' field; an empty body cannot be parsed into an ApiRequest.","triggerScenarios":"POSTing to the Arthas HTTP API endpoint (default :8563) with an empty request body, or sending a request with Content-Length: 0.","commonSituations":"Misconfigured REST client that omits the body. Curl invocation missing the -d flag. Proxy or load balancer stripping the body.","solutions":["Send a valid JSON body: curl -X POST http://localhost:8563/api -d '{\"action\":\"init_session\"}'.","Ensure the client sets Content-Type: application/json and includes a non-empty body.","Check that no intermediary proxy strips POST bodies."],"exampleFix":"# before\ncurl -X POST http://localhost:8563/api\n# -> parse request failed: request body is empty\n\n# after\ncurl -X POST http://localhost:8563/api \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"action\":\"init_session\"}'","handlingStrategy":"validation","validationCode":"// Client-side: ensure non-empty body before sending\nString body = buildRequestBody(apiRequest);\nif (body == null || body.trim().isEmpty()) {\n    throw new IllegalArgumentException(\"Request body must not be empty\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include a -d/--data flag with valid JSON when POSTing to the API.","Set Content-Type: application/json on all API requests."],"tags":["http-api","request-validation","json"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}