3 Replies Latest reply on Jan 20, 2020 5:39 AM by dvohra21

    HttpServletRequest: servlet.doGet() receives empty request

    elizabethR

      Oracle JDev 11.1.1.9.0

       

      not a jdeveloper expert so any assistance would be greatly appreciated. We are developing React front end that will replace the jspx files but still want to use the original back end code as it interfaces with OIM.

       

      I developed a servlet, to replace a managed bean,  that receives a request from a static react component. I can connect to the servlet but the request is empty. After some research, I was wondering if jdev is consuming the request somewhere before the servlet gets called. i have tried a number of things,  right now i am using request.getInputStream() to pull in the request but it is still empty. One source mentioned request.getReader() which didn't work either. Another mentioned using HttpServletRequestWrapper , another asked if JSF had already consumed the request? Yet another said to simply set the Content-Type.

       

          public void doGet(HttpServletRequest request,

                            HttpServletResponse response) throws ServletException,

                                                                 IOException {

       

       

              StringBuilder stringBuilder = new StringBuilder(1000);

              Scanner scanner = new Scanner(request.getInputStream());

              while (scanner.hasNextLine()) {

                  stringBuilder.append(scanner.nextLine());

              }

       

              String body = stringBuilder.toString();

       

              System.out.println("body: "+body);

       

      .......

       

      The below code is used in the managed beans but I'm not sure if i can actually use this in the servlet:

       

      HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();