0

trying to retrieve that data for HttpServeletRequest object. But it throwing Java Lang Illegal State Exception:

getInputStream() has already been called for this request

try {
        String test = null;
        if (request.getMethod().equalsIgnoreCase(request.getMethod())) {
            test = request.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
        }
    } catch (Exception ec) {
        logger.error("Exception newRemarksUpdated : " + ec.getMessage());
    }
Usman Maqbool
  • 3,351
  • 10
  • 31
  • 48

2 Answers2

0

First, you are comparing object instance with itself. The condition for this if statement will always be true.

if (request.getMethod().equalsIgnoreCase(request.getMethod()))

Second, create an instance of your reader, so it will be easier to manipulate.

BufferedReader reader = request.getReader();
String collected = reader.lines()
        .collect(Collectors.joining(System.lineSeparator()));

Third, it seems like you are calling getInputStream() method twice, which cannot be done. You can read more about it in this post.

Alan Sereb
  • 2,358
  • 2
  • 17
  • 31
0

According the documentation you're not able to use both character-oriented and byte-oriented streams to read a request. I bet you called getInputStream() somewhere else. You should use similar approach everywhere.

Vladimir Pligin
  • 1,547
  • 11
  • 18