Example usage for javax.servlet.http HttpServletRequestWrapper getRequestURI

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

Introduction

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

Prototype

@Override
public String getRequestURI() 

Source Link

Document

The default behavior of this method is to return getRequestURI() 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;//  w  w w . j  a  v  a  2  s . co  m
        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;
}

From source file:org.exoplatform.wcm.webui.category.UICategoryNavigationTreeBase.java

public String getActionLink() throws Exception {
    PortletRequestContext porletRequestContext = (PortletRequestContext) WebuiRequestContext
            .getCurrentInstance();/*from   w  w w  . j a v  a2  s  . co  m*/
    HttpServletRequestWrapper requestWrapper = (HttpServletRequestWrapper) porletRequestContext.getRequest();
    String requestURI = requestWrapper.getRequestURI();
    PortletPreferences portletPreferences = UICategoryNavigationUtils.getPortletPreferences();
    String preferenceTreeName = portletPreferences.getValue(UICategoryNavigationConstant.PREFERENCE_TREE_NAME,
            "");
    String preferenceTargetPage = portletPreferences
            .getValue(UICategoryNavigationConstant.PREFERENCE_TARGET_PAGE, "");
    String backPath = requestURI.substring(0, requestURI.lastIndexOf("/"));
    if (backPath.endsWith(preferenceTargetPage)
            || requestURI.endsWith(Util.getUIPortal().getSelectedUserNode().getURI()))
        backPath = "javascript:void(0)";
    else if (backPath.endsWith(preferenceTreeName))
        backPath = backPath.substring(0, backPath.lastIndexOf("/"));
    return backPath;
}