在从AWS API Gateway接收输入时在json中更改密钥名称时出错

时间:2017-07-15 07:42:40

标签: aws-lambda

以下是AWS lamdba java代码,它接收来自AWS API Gateway的输入。我在下面的java代码: -

public class LambdaFunctionHandler implements RequestStreamHandler {
    JSONParser parser = new JSONParser();


    public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {

        LambdaLogger logger = context.getLogger();
        logger.log("Loading Java Lambda handler of ProxyWithStream");


        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        JSONObject response = new JSONObject();
        String name = "World";
        String responseCode = "200";

        try {
            JSONObject event = (JSONObject)parser.parse(reader);
            if (event.get("queryStringParameters") != null) {
                JSONObject qps = (JSONObject)event.get("queryStringParameters");
                if ( qps.get("name") != null) {
                    name = (String)qps.get("name");
                }
                if (qps.get("httpStatus") != null) {
                    responseCode = qps.get("httpStatus)").toString();
                }
            }
            //response.put("statusCode", responseCode);
            response.put("rohit", event.toJSONString());  

        } catch(ParseException pex) {
            response.put("statusCode", "400");
            response.put("exception", pex);
        }

        logger.log(response.toJSONString());
        OutputStreamWriter writer = new OutputStreamWriter(outputStream, "UTF-8");
        writer.write(response.toJSONString());  
        writer.close();
    }
}

当我改变

response.put("body", event.toJSONString());  

response.put("rohit", event.toJSONString());  

显示错误: -

{
    "message": "Internal server error"
}

先谢谢你的帮助......

0 个答案:

没有答案