Example usage for javax.servlet.http HttpServletRequestWrapper getMethod

List of usage examples for javax.servlet.http HttpServletRequestWrapper getMethod

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequestWrapper getMethod.

Prototype

@Override
public String getMethod() 

Source Link

Document

The default behavior of this method is to return getMethod() on the wrapped request object.

Usage

From source file:org.bessle.neo4j.proxy.HttpRequestLoggingFilter.java

protected Map<String, Object> getTrace(HttpServletRequestWrapper wrappedRequest) {

    Map<String, Object> headers = new LinkedHashMap<String, Object>();
    Enumeration<String> names = wrappedRequest.getHeaderNames();

    while (names.hasMoreElements()) {
        String name = names.nextElement();
        List<String> values = Collections.list(wrappedRequest.getHeaders(name));
        Object value = values;/*from w w  w.j a va2s . c  om*/
        if (values.size() == 1) {
            value = values.get(0);
        } else if (values.isEmpty()) {
            value = "";
        }
        headers.put(name, value);

    }
    Map<String, Object> trace = new LinkedHashMap<String, Object>();
    Map<String, Object> allHeaders = new LinkedHashMap<String, Object>();
    allHeaders.put("request", headers);
    trace.put("method", wrappedRequest.getMethod());
    trace.put("path", wrappedRequest.getRequestURI());
    trace.put("headers", allHeaders);
    Throwable exception = (Throwable) wrappedRequest.getAttribute("javax.servlet.error.exception");
    if (exception != null && this.errorAttributes != null) {
        RequestAttributes requestAttributes = new ServletRequestAttributes(wrappedRequest);
        Map<String, Object> error = this.errorAttributes.getErrorAttributes(requestAttributes, true);
        trace.put("error", error);
    }
    String body = "unknown";
    try {
        //body = IOUtils.toString(wrappedRequest.getInputStream(), "UTF-8");
        trace.put("body", body);
        InputStream wrappedInputStream = IOUtils.toInputStream(body, "UTF-8");
        //wrappedRequest.
    } catch (IOException ioe) {
        trace.put("body", "untraceable");
    }
    return trace;
}