×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Karthick Bala
Added: Jul 25, 2014 10:14 AM
Views: 3
Tags: no tags
  1.     public static String getRequestBody(HttpServletRequest request) throws Exception {
  2.  
  3.         SecurityRequestWrapper request111 = SecurityRequestWrapper.getInstance(request);
  4.         String retData = request111.getFilteredStreamContent();
  5.         if(retData != null && !retData.equals("")){
  6.             return retData;
  7.         }else{
  8.         StringBuilder stringBuilder = new StringBuilder();
  9.         BufferedReader bufferedReader = null;
  10.         try {
  11.             InputStream inputStream = request.getInputStream();
  12.             if (inputStream != null) {
  13.                 bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
  14.                 char[] charBuffer = new char[128];
  15.                 int bytesRead = -1;
  16.                 while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
  17.                     stringBuilder.append(charBuffer, 0, bytesRead);
  18.                 }
  19.             } else {
  20.                 stringBuilder.append("");
  21.             }
  22.         } catch (IOException ex) {
  23.             throw ex;
  24.         } finally {
  25.             if (bufferedReader != null) {
  26.                 try {
  27.                     bufferedReader.close();
  28.                 } catch (IOException ex) {
  29.                     throw ex;
  30.                 }
  31.             }
  32.         }
  33.         return stringBuilder.toString();
  34.         }
  35.     }