Example usage for javax.servlet ServletInputStream reset

List of usage examples for javax.servlet ServletInputStream reset

Introduction

In this page you can find the example usage for javax.servlet ServletInputStream reset.

Prototype

public synchronized void reset() throws IOException 

Source Link

Document

Repositions this stream to the position at the time the mark method was last called on this input stream.

Usage

From source file:org.openrepose.powerfilter.intrafilterlogging.RequestLog.java

public RequestLog(HttpServletRequest httpServletRequest, Filter filter) throws IOException {
    preamble = "Intrafilter Request Log";
    timestamp = new DateTime().toString();
    currentFilter = StringUtils.isEmpty(filter.getId()) ? filter.getName()
            : filter.getId() + "-" + filter.getName();
    httpMethod = httpServletRequest.getMethod();
    requestURI = httpServletRequest.getRequestURI();
    headers = convertRequestHeadersToMap(httpServletRequest);

    try {//www.ja v a 2 s . co  m
        ServletInputStream inputStream = httpServletRequest.getInputStream();
        if (inputStream.markSupported()) {
            inputStream.mark(Integer.MAX_VALUE);
            requestBody = IOUtils.toString(inputStream); //http://stackoverflow.com/a/309448
            inputStream.reset();
        } else {
            LOG.warn("Unable to populate request body - {} does not support mark/reset.", inputStream);
        }
    } catch (IOException e) {
        LOG.warn("Unable to populate request body.", e);
    }
}