Spring Get HttpServletRequest Body Many Times
in Java with 11111 comments

Spring Get HttpServletRequest Body Many Times

in Java with 11111 comments

Default once consumed, the stram will empty

  public static byte[] getByteBody(HttpServletRequest request) {
    byte[] body = new byte[0];
    try {
      body = StreamUtils.copyToByteArray(request.getInputStream());
    } catch (IOException e) {
      log.error("Error: Get RequestBody byte[] fail," + e);
    }
    return body;
  }

Add Wrapper to Cache stream in byte[]

public class RequestWrapper extends HttpServletRequestWrapper {
  private final byte[] requestBody;
  public RequestWrapper(HttpServletRequest request) {
    super(request);
    requestBody = RequestHelper.getByteBody(request);
  }
  @Override
  public BufferedReader getReader() {
    ServletInputStream inputStream = getInputStream();
    return Objects.isNull(inputStream)
        ? null
        : new BufferedReader(new InputStreamReader(inputStream));
  }
  @Override
  public ServletInputStream getInputStream() {
    if (ObjectUtils.isEmpty(requestBody)) {
      return null;
    }
    final ByteArrayInputStream bais = new ByteArrayInputStream(requestBody);
    return new ServletInputStream() {
      @Override
      public boolean isFinished() {
        return false;
      }
      @Override
      public boolean isReady() {
        return false;
      }
      @Override
      @SuppressWarnings("EmptyMethod")
      public void setReadListener(ReadListener readListener) {}
      @Override
      public int read() {
        return bais.read();
      }
    };
  }
}

Add Filter wrap the original request

  public void doFilter(
      ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
      throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) servletRequest;
    filterChain.doFilter(new RequestWrapper(req), servletResponse);
  }
Responses
  1. Speech gsb.mrto.mmtech.top.fax.rp meta-analysis exclude honour [URL=http://andyvangrinsven.com/albenza/ - cheapest albenza dosage price[/URL - [URL=http://pvcprofessionalceilings.com/item/combigan/ - combigan[/URL - [URL=http://ganpatidropshippers.com/catapres/ - catapres generic pills[/URL - [URL=http://pvcprofessionalceilings.com/item/depakote/ - mail order depakote[/URL - [URL=http://memoiselle.com/item/generic-bentyl-at-walmart/ - bentyl en ligne[/URL - [URL=http://loveandlightmusic.net/buy-lasix/ - lasix without rx[/URL - [URL=http://campropost.org/lonitab/ - lonitab[/URL - [URL=http://columbia-electrochem-lab.org/item/buy-prednisone-without-rx/ - prednisone thyroid[/URL - [URL=http://pvcprofessionalceilings.com/item/harvoni/ - harvoni capsules for sale[/URL - [URL=http://earthbeours.com/testosterone-booster/ - testosterone booster[/URL - on line testosterone booster [URL=http://center4family.com/aciclovir/ - aciclovir[/URL - buy aciclovir online [URL=http://infiniterotclothing.com/rumalaya-online/ - order rumalaya online[/URL - [URL=http://andyvangrinsven.com/asthalin-hfa-inhaler/ - generic asthalin hfa inhaler from canada[/URL - [URL=http://goodroofcompany.com/trileptal-online-uk/ - trileptal online uk[/URL - [URL=http://hynjoku.com/promethazine/ - phenergan drugs[/URL - collapse, milligrams, constrictor generic albenza lowest price generic albenza lowest price combigan.com catapres buy depakote buy bentyl lasix without a prescription generic lonitab tablets prednisone without prescription harvoni.com lowest price order testosterone booster online aciclovir online rumalaya asthalin hfa inhaler without an rx trileptal promethazine to get high non-operative http://andyvangrinsven.com/albenza/ albenza.com lowest price http://pvcprofessionalceilings.com/item/combigan/ combigan non generic http://ganpatidropshippers.com/catapres/ catapres generic pills http://pvcprofessionalceilings.com/item/depakote/ depakote tablets http://memoiselle.com/item/generic-bentyl-at-walmart/ generic bentyl at walmart http://loveandlightmusic.net/buy-lasix/ buy lasix http://campropost.org/lonitab/ lonitab online canada http://columbia-electrochem-lab.org/item/buy-prednisone-without-rx/ buy prednisone without rx http://pvcprofessionalceilings.com/item/harvoni/ harvoni best price http://earthbeours.com/testosterone-booster/ order testosterone booster online http://center4family.com/aciclovir/ generic aciclovir http://infiniterotclothing.com/rumalaya-online/ cheap rumalaya rumalaya online http://andyvangrinsven.com/asthalin-hfa-inhaler/ asthalin hfa inhaler from india http://goodroofcompany.com/trileptal-online-uk/ price of trileptal http://hynjoku.com/promethazine/ promethazine for topical application mum's horizons superiorly.

    Reply
  2. buy cipro

    Reply
  3. buy kamagra

    Reply
  4. finpecia 1 mg clonidine tablets

    Reply
  5. https://www.pinterest.com/pin/650348002431220538/
    https://www.pinterest.fr/pin/650348002431220538/
    https://www.pinterest.de/pin/650348002431220538/
    https://www.pinterest.co.uk/pin/650348002431220538/
    https://www.pinterest.ca/pin/650348002431220538/
    https://www.pinterest.jp/pin/650348002431220538/
    https://www.pinterest.it/pin/650348002431220538/
    https://www.pinterest.co.kr/pin/650348002431220538/
    https://www.pinterest.ru/pin/650348002431220538/
    https://www.pinterest.com.au/pin/650348002431220538/
    https://www.pinterest.nz/pin/650348002431220538/
    https://www.pinterest.es/pin/650348002431220538/
    https://www.pinterest.dk/pin/650348002431220538/
    https://www.pinterest.pt/pin/650348002431220538/
    https://www.pinterest.ie/pin/650348002431220538/
    https://www.pinterest.com.mx/pin/650348002431220538/
    https://www.pinterest.cl/pin/650348002431220538/
    https://www.pinterest.at/pin/650348002431220538/
    https://www.pinterest.ch/pin/650348002431220538/
    https://www.pinterest.ph/pin/650348002431220538/
    https://www.pinterst.com/pin/650348002431220538/
    https://www.pinterest.th/pin/650348002431220538/
    https://www.pinterest.com.pt/pin/650348002431220538/
    https://www.pinterest.com.uy/pin/650348002431220538/
    https://www.pinterest.co/pin/650348002431220538/
    https://www.pinterest.nl/pin/650348002431220538/
    https://www.pinterest.info/pin/650348002431220538/
    https://www.pinterest.kr/pin/650348002431220538/
    https://www.pinterest.vn/pin/650348002431220538/
    https://www.pinterest.com.vn/pin/650348002431220538/
    https://www.pinterest.biz/pin/650348002431220538/
    https://www.pinterest.ec/pin/650348002431220538/
    https://www.pinterest.mx/pin/650348002431220538/
    https://www.pinterest.in/pin/650348002431220538/
    https://www.pinterest.pe/pin/650348002431220538/
    https://www.pinterest.co.at/pin/650348002431220538/
    https://www.pinterest.hu/pin/650348002431220538/
    https://www.pinterest.co.in/pin/650348002431220538/
    https://www.pinterest.co.nz/pin/650348002431220538/
    https://www.pinterest.id/pin/650348002431220538/
    https://www.pinterest.co.id/pin/650348002431220538/
    https://www.pinterest.com.ec/pin/650348002431220538/
    https://www.pinterest.com.py/pin/650348002431220538/
    https://www.pinterest.tw/pin/650348002431220538/
    https://www.pinterest.be/pin/650348002431220538/
    https://www.pinterest.uk/pin/650348002431220538/
    https://www.pinterest.com.bo/pin/650348002431220538/
    https://www.pinterest.com.pe/pin/650348002431220538/

    Reply