israel-gs
6/26/2018 - 9:35 PM

Get payload from request

Get payload from request

import java.io.BufferedReader;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;

public class HttpHelper {

    public static JSONObject getPayloadBody(HttpServletRequest request) throws IOException {
        String line;
        StringBuffer json = new StringBuffer();
        try (BufferedReader reader = request.getReader()) {
            while ((line = reader.readLine()) != null) {
                json.append(line);
            }
        }
        return new JSONObject(json.toString());
    }

}