Example usage for javax.servlet.http HttpServletRequest getAttributeNames

List of usage examples for javax.servlet.http HttpServletRequest getAttributeNames

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getAttributeNames.

Prototype

public Enumeration<String> getAttributeNames();

Source Link

Document

Returns an Enumeration containing the names of the attributes available to this request.

Usage

From source file:org.nuxeo.ecm.platform.web.common.exceptionhandling.service.DefaultRequestDumper.java

public String getDump(HttpServletRequest request) {
    StringBuilder builder = new StringBuilder();
    builder.append("\nRequest Attributes:\n\n");
    Enumeration<String> e = request.getAttributeNames();
    while (e.hasMoreElements()) {
        String name = e.nextElement();
        if (attributes.contains(name)) {
            continue;
        }//ww w.  j  a  va 2  s .  c  o m
        builder.append(name);
        builder.append(" : ");
        try {
            Object obj = request.getAttribute(name);
            builder.append(obj.toString());
        } catch (RuntimeException exc) {
            // avoid errors when printing the error dump
            log.error("ERROR TRYING TO GET THIS REQUEST ATTRIBUTE VALUE: " + name);
            builder.append("ERROR TRYING TO GET THIS REQUEST ATTRIBUTE VALUE");
        }
        builder.append("\n");
    }
    return builder.toString();
}

From source file:se.vgregion.portal.requestlogger.RequestLoggerController.java

private Map<String, String> getRequestAttribure(PortletRequest request) {
    Map<String, String> result = new TreeMap<String, String>();

    HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(request);
    Enumeration<String> names = httpRequest.getAttributeNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        result.put(name, httpRequest.getAttribute(name).toString());
    }/*from  w w w.ja  v a 2s  . c  o  m*/

    return result;
}

From source file:fr.mby.portal.coreimpl.action.BasicUserActionFactory.java

@SuppressWarnings("unchecked")
protected Map<String, Object> extractAttributes(final HttpServletRequest request) {
    final Map<String, Object> attributes = new HashMap<String, Object>();

    final Enumeration<String> names = request.getAttributeNames();
    if (names != null) {
        while (names.hasMoreElements()) {
            final String name = names.nextElement();
            attributes.put(name, request.getAttribute(name));
        }/*from  w  w w  . j ava2 s.  c o m*/
    }

    return attributes;
}

From source file:com.jaspersoft.jasperserver.api.metadata.user.service.impl.RequestAuthenticationProcessingFilter.java

protected Map obtainRequestParameters(HttpServletRequest request) {

    Map result = new HashMap();
    result.putAll(request.getParameterMap());

    Enumeration attrs = request.getAttributeNames();
    while (attrs.hasMoreElements()) {
        String attrName = (String) attrs.nextElement();
        result.put(attrName, request.getAttribute(attrName));
    }//  w ww. j  a  va2  s . c o  m

    return result;
}

From source file:org.debux.webmotion.server.render.RenderException.java

protected Map<String, Object> getRequestAttributes(HttpServletRequest request) {
    Map<String, Object> result = new HashMap<String, Object>();
    for (Enumeration<String> names = request.getAttributeNames(); names.hasMoreElements();) {
        String name = names.nextElement();
        Object value = request.getAttribute(name);
        result.put(name, value);// w  w  w . ja v  a2 s  . c  o m
    }
    return result;
}

From source file:testapp.CsrfTokenResponseHeaderBindingFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        javax.servlet.FilterChain filterChain) throws ServletException, IOException {
    CsrfToken token = (CsrfToken) request.getAttribute(REQUEST_ATTRIBUTE_NAME);
    Enumeration<String> e = request.getAttributeNames();

    while (e.hasMoreElements()) {
        String param = (String) e.nextElement();
        System.out.println(param);
    }/*from w  w  w .j  a  v  a  2 s . c  o m*/

    if (token != null) {
        response.setHeader(RESPONSE_HEADER_NAME, token.getHeaderName());
        response.setHeader(RESPONSE_PARAM_NAME, token.getParameterName());
        response.setHeader(RESPONSE_TOKEN_NAME, token.getToken());

        response.addCookie(new Cookie("XSRF-TOKEN", token.getToken()));
    }

    filterChain.doFilter(request, response);
}

From source file:org.mule.transport.servlet.ServletMuleMessageFactory.java

protected void copyAttributes(HttpServletRequest request, Map<String, Object> messageProperties) {
    for (Enumeration<?> e = request.getAttributeNames(); e.hasMoreElements();) {
        String key = (String) e.nextElement();
        messageProperties.put(key, request.getAttribute(key));
    }/*from  www  .j ava2s  . c om*/
}

From source file:de.micromata.genome.logging.LogRequestDumpAttribute.java

/**
 * Gen http request dump.//from  w  w w.  j  a  va 2 s .c o m
 *
 * @param req the req
 * @return the string
 */
@SuppressWarnings("unchecked")
public static String genHttpRequestDump(HttpServletRequest req) {
    StringBuilder sb = new StringBuilder();

    sb.append("method: ").append(req.getMethod()).append('\n')//
            .append("requestURL: ").append(req.getRequestURL()).append('\n')//
            .append("servletPath: ").append(req.getServletPath()).append('\n')//
            .append("requestURI: ").append(req.getRequestURI()).append('\n') //
            .append("queryString: ").append(req.getQueryString()).append('\n') //
            .append("pathInfo: ").append(req.getPathInfo()).append('\n')//
            .append("contextPath: ").append(req.getContextPath()).append('\n') //
            .append("characterEncoding: ").append(req.getCharacterEncoding()).append('\n') //
            .append("localName: ").append(req.getLocalName()).append('\n') //
            .append("contentLength: ").append(req.getContentLength()).append('\n') //
    ;
    sb.append("Header:\n");
    for (Enumeration<String> en = req.getHeaderNames(); en.hasMoreElements();) {
        String hn = en.nextElement();
        sb.append("  ").append(hn).append(": ").append(req.getHeader(hn)).append("\n");
    }
    sb.append("Attr: \n");
    Enumeration en = req.getAttributeNames();
    for (; en.hasMoreElements();) {
        String k = (String) en.nextElement();
        Object v = req.getAttribute(k);
        sb.append("  ").append(k).append(": ").append(Objects.toString(v, StringUtils.EMPTY)).append('\n');
    }

    return sb.toString();
}

From source file:com.revolsys.ui.web.config.HttpServletRequestJexlContext.java

@Override
public Map getVars() {
    return new AbstractMap<String, Object>() {
        @Override// w w  w .  j  a v a  2s.  c o  m
        @SuppressWarnings("unchecked")
        public Set<Entry<String, Object>> entrySet() {
            final HttpServletRequest request = getRequest();
            final Map<String, Object> map = new HashMap<>();
            map.putAll(request.getParameterMap());
            for (final Enumeration<String> names = request.getAttributeNames(); names.hasMoreElements();) {
                final String name = names.nextElement();
                map.put(name, request.getAttribute(name));
            }
            if (HttpServletRequestJexlContext.this.servletContext != null) {
                for (final Enumeration<String> names = HttpServletRequestJexlContext.this.servletContext
                        .getAttributeNames(); names.hasMoreElements();) {
                    final String name = names.nextElement();
                    map.put(name, HttpServletRequestJexlContext.this.servletContext.getAttribute(name));
                }
            }
            final Map<String, Object> attributes = HttpServletRequestJexlContext.this.localAttributes.get();
            if (attributes != null) {
                map.putAll(attributes);
            }
            map.put("request", request);
            map.put("requestURI",
                    HttpServletRequestJexlContext.this.urlPathHelper.getOriginatingRequestUri(request));
            return map.entrySet();
        }
    };
}

From source file:org.kuali.coeus.sys.framework.controller.interceptor.RequestLoggingFilter.java

/**
 * Constructs a log message that displays attribute information belonging to the given
 * {@link HttpServletRequest} instance. 
 *
 * @return Log message/*  w w w.j  a va 2  s.c  o m*/
 */
private String getRequestAttributesMessage(HttpServletRequest request) {
    StringBuilder retval = new StringBuilder();
    for (Enumeration<String> attributeNames = request.getAttributeNames(); attributeNames.hasMoreElements();) {
        String attributeName = attributeNames.nextElement();
        retval.append(attributeName).append(": ").append(request.getAttribute(attributeName)).append("\n");
    }

    return retval.toString();
}