public ReReadableHttpServletRequestWrapper(HttpServletRequest request) throws IOException {
//So that other request method behave just like before
super(request);
StringBuilder stringBuilder = new StringBuilder();
BufferedReader bufferedReader = null;
try {
InputStream inputStream = request.getInputStream();
// stream 이 Null 이 이나거나 사용 가능 할때만 read
if (inputStream != null && inputStream.available()) { // <- 문제가 되는 부분
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
char[] charBuffer = new char[128];
int bytesRead = -1;
while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
stringBuilder.append(charBuffer, 0, bytesRead);
}
}
} catch (IOException ex) {
throw ex;
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException ex) {
throw ex;
}
}
} //Store request pody content in 'body' variable
body = stringBuilder.toString();
}
Comments