Error: HTTP Status 500 - org.json.JSONObject can not be cast to jdk.nashorn.api.scripting.JSObject

0

In my java system this error appeared:

I'msweatingthePOSTMANtooltostudythecase.

  

HTTPStatus500-org.json.JSONObjectcannotbecastto  jdk.nashorn.api.scripting.JSObject

Code:

importjava.io.BufferedReader;importjava.io.IOException;importjava.io.PrintWriter;importjavax.servlet.ServletException;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importorg.json.JSONObject;importjdk.nashorn.api.scripting.JSObject;/***Servletimplementationclassteste1*/@WebServlet("/teste1")
public class teste1 extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public teste1() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        String nome = request.getParameter("nome");

        PrintWriter saida = response.getWriter();
        saida.println("teste1: "+nome);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        JSONObject json = (JSONObject) formatJson(request.getReader());

        System.out.println(json.toString());

        doGet(request, response);

        formatJson(request.getReader());

        String body =  request.getReader().lines().reduce("",(acc, actual)->acc+actual );
        System.out.println(body);

    }

    private JSObject formatJson(BufferedReader reader){

        StringBuffer bs = new StringBuffer();
        String line = null;

        try{
            while((line = reader.readLine()) != null){
                bs.append(line);
            }
        }catch(Exception e){
            e.getStackTrace();
        }

        JSONObject json = new JSONObject(bs.toString());
        return (JSObject) json;
    }

}

How do I proceed to find the solution to this error?

    
asked by anonymous 25.03.2017 / 00:50

0 answers