Example usage for javax.servlet ServletRequest getParameterNames

List of usage examples for javax.servlet ServletRequest getParameterNames

Introduction

In this page you can find the example usage for javax.servlet ServletRequest getParameterNames.

Prototype

public Enumeration<String> getParameterNames();

Source Link

Document

Returns an Enumeration of String objects containing the names of the parameters contained in this request.

Usage

From source file:org.agnitas.util.AgnUtils.java

/**
 * Getter for property parameterMap./* ww  w.ja  v a  2  s.  c  om*/
 *
 * @return Value of property parameterMap.
 */
public static Map<String, String> getRequestParameterMap(ServletRequest req) {
    Map<String, String> parameterMap = new HashMap<String, String>();
    @SuppressWarnings("unchecked")
    Enumeration<String> e = req.getParameterNames();
    while (e.hasMoreElements()) {
        String parameterName = e.nextElement();
        String paremeterValue = req.getParameter(parameterName);
        parameterMap.put(parameterName, paremeterValue);
    }

    return parameterMap;
}

From source file:org.zilverline.web.RequestDumperFilter.java

/**
 * Time the processing that is performed by all subsequent filters in the current filter stack, including the ultimately invoked
 * servlet.//from   w ww. j  ava  2  s  .c  om
 * 
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 * @param chain The filter chain we are processing
 * 
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet error occurs
 */
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
        throws IOException, ServletException {

    if (filterConfig == null) {
        return;
    }

    log.debug("Request Received at " + (new Timestamp(System.currentTimeMillis())));
    log.debug(" characterEncoding=" + request.getCharacterEncoding());
    log.debug("     contentLength=" + request.getContentLength());
    log.debug("       contentType=" + request.getContentType());
    log.debug("            locale=" + request.getLocale());
    Enumeration locales = request.getLocales();
    StringBuffer localesBuffer = new StringBuffer("           locales=");
    boolean first = true;
    while (locales.hasMoreElements()) {
        Locale locale = (Locale) locales.nextElement();
        if (first) {
            first = false;
        } else {
            localesBuffer.append(", ");
        }
        localesBuffer.append(locale.toString());
    }
    log.debug(localesBuffer);
    Enumeration names = request.getParameterNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        StringBuffer paramsBuffer = new StringBuffer();
        paramsBuffer.append("         parameter=" + name + "=");
        String[] values = request.getParameterValues(name);
        for (int i = 0; i < values.length; i++) {
            if (i > 0) {
                paramsBuffer.append(", ");
            }
            paramsBuffer.append(values[i]);
        }
        log.debug(paramsBuffer);
    }
    log.debug("          protocol=" + request.getProtocol());
    log.debug("        remoteAddr=" + request.getRemoteAddr());
    log.debug("        remoteHost=" + request.getRemoteHost());
    log.debug("            scheme=" + request.getScheme());
    log.debug("        serverName=" + request.getServerName());
    log.debug("        serverPort=" + request.getServerPort());
    log.debug("          isSecure=" + request.isSecure());

    // Render the HTTP servlet request properties
    if (request instanceof HttpServletRequest) {
        log.debug("---------------------------------------------");
        HttpServletRequest hrequest = (HttpServletRequest) request;
        log.debug("       contextPath=" + hrequest.getContextPath());
        Cookie[] cookies = hrequest.getCookies();
        if (cookies == null) {
            cookies = new Cookie[0];
        }
        for (int i = 0; i < cookies.length; i++) {
            log.debug("            cookie=" + cookies[i].getName() + "=" + cookies[i].getValue());
        }
        names = hrequest.getHeaderNames();
        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();
            String value = hrequest.getHeader(name);
            log.debug("            header=" + name + "=" + value);
        }
        log.debug("            method=" + hrequest.getMethod());
        log.debug("          pathInfo=" + hrequest.getPathInfo());
        log.debug("       queryString=" + hrequest.getQueryString());
        log.debug("        remoteUser=" + hrequest.getRemoteUser());
        log.debug("requestedSessionId=" + hrequest.getRequestedSessionId());
        log.debug("        requestURI=" + hrequest.getRequestURI());
        log.debug("       servletPath=" + hrequest.getServletPath());
    }
    log.debug("=============================================");

    // Pass control on to the next filter
    chain.doFilter(request, response);

}

From source file:com.mtgi.analytics.servlet.ServletRequestBehaviorTrackingAdapter.java

public BehaviorEvent start(ServletRequest request) {

    HttpServletRequest req = (HttpServletRequest) request;
    if (!match(req))
        return null;

    String eventName = getEventName(req);
    BehaviorEvent event = manager.createEvent(eventType, eventName);

    //log relevant request data and parameters to the event.
    EventDataElement data = event.addData();
    data.add("uri", req.getRequestURI());
    data.add("protocol", req.getProtocol());
    data.add("method", req.getMethod());
    data.add("remote-address", req.getRemoteAddr());
    data.add("remote-host", req.getRemoteHost());

    if (this.parameters != null) {
        EventDataElement parameters = data.addElement(PARAMETERS_ELEMENT);
        //include only configured parameters
        for (String name : this.parameters) {
            String[] values = request.getParameterValues(name);
            if (values != null)
                addParameter(parameters, name, values);
        }/*from w ww  . ja v  a  2s  .c o m*/
    } else {
        EventDataElement parameters = data.addElement(PARAMETERS_ELEMENT);
        //include all parameters
        for (Enumeration<?> params = request.getParameterNames(); params.hasMoreElements();) {
            String name = (String) params.nextElement();
            String[] values = request.getParameterValues(name);
            addParameter(parameters, name, values);
        }
    }

    manager.start(event);
    return event;
}

From source file:org.soaplab.clients.spinet.filters.RequestDumperFilter.java

/**
 * Time the processing that is performed by all subsequent filters in the
 * current filter stack, including the ultimately invoked servlet.
 *
 * @param request The servlet request we are processing
 * @param result The servlet response we are creating
 * @param chain The filter chain we are processing
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet error occurs
 *//*from   w w  w. ja va2 s.  com*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    if (filterConfig == null)
        return;

    // Render the generic servlet request properties
    StringWriter sw = new StringWriter();
    PrintWriter writer = new PrintWriter(sw);
    writer.println("Request Received at " + (new Timestamp(System.currentTimeMillis())));
    writer.println(" characterEncoding=" + request.getCharacterEncoding());
    writer.println("     contentLength=" + request.getContentLength());
    writer.println("       contentType=" + request.getContentType());
    writer.println("            locale=" + request.getLocale());
    writer.print("           locales=");
    Enumeration locales = request.getLocales();
    boolean first = true;
    while (locales.hasMoreElements()) {
        Locale locale = (Locale) locales.nextElement();
        if (first)
            first = false;
        else
            writer.print(", ");
        writer.print(locale.toString());
    }
    writer.println();
    Enumeration names = request.getParameterNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        writer.print("         parameter=" + name + "=");
        String values[] = request.getParameterValues(name);
        for (int i = 0; i < values.length; i++) {
            if (i > 0)
                writer.print(", ");
            writer.print(values[i]);
        }
        writer.println();
    }
    writer.println("          protocol=" + request.getProtocol());
    writer.println("        remoteAddr=" + request.getRemoteAddr());
    writer.println("        remoteHost=" + request.getRemoteHost());
    writer.println("            scheme=" + request.getScheme());
    writer.println("        serverName=" + request.getServerName());
    writer.println("        serverPort=" + request.getServerPort());
    writer.println("          isSecure=" + request.isSecure());

    // Render the HTTP servlet request properties
    if (request instanceof HttpServletRequest) {
        writer.println("---------------------------------------------");
        HttpServletRequest hrequest = (HttpServletRequest) request;
        writer.println("       contextPath=" + hrequest.getContextPath());
        Cookie cookies[] = hrequest.getCookies();
        if (cookies == null)
            cookies = new Cookie[0];
        for (int i = 0; i < cookies.length; i++) {
            writer.println("            cookie=" + cookies[i].getName() + "=" + cookies[i].getValue());
        }
        names = hrequest.getHeaderNames();
        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();
            String value = hrequest.getHeader(name);
            writer.println("            header=" + name + "=" + value);
        }
        writer.println("            method=" + hrequest.getMethod());
        writer.println("          pathInfo=" + hrequest.getPathInfo());
        writer.println("       queryString=" + hrequest.getQueryString());
        writer.println("        remoteUser=" + hrequest.getRemoteUser());
        writer.println("requestedSessionId=" + hrequest.getRequestedSessionId());
        writer.println("        requestURI=" + hrequest.getRequestURI());
        writer.println("       servletPath=" + hrequest.getServletPath());
    }
    writer.println("=============================================");

    // Log the resulting string
    writer.flush();
    filterConfig.getServletContext().log(sw.getBuffer().toString());
    log.info(sw.getBuffer().toString());

    // Pass control on to the next filter
    chain.doFilter(request, response);

}

From source file:de.appsolve.padelcampus.filter.AdminFilter.java

/**
 * @param request/*from w ww .  j  a va2  s. c  o  m*/
 * @param response
 * @param chain
 * @throws java.io.IOException
 * @throws javax.servlet.ServletException
 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse = (HttpServletResponse) response;
        Player player = sessionUtil.getUser(httpRequest);
        if (player == null) {
            sessionUtil.setLoginRedirectPath(httpRequest, httpRequest.getRequestURI());
            httpResponse.sendRedirect(httpResponse.encodeRedirectURL("/login"));
            return;
        }
        Set<Privilege> privileges = sessionUtil.getPrivileges(httpRequest);
        String pathInfo = httpRequest.getRequestURI().substring(httpRequest.getContextPath().length());
        for (Privilege privilege : privileges) {
            if (privilege.getPathPattern().matcher(pathInfo).matches()) {
                chain.doFilter(request, response);
                if (!StringUtils.isEmpty(httpRequest.getMethod())
                        && httpRequest.getMethod().equalsIgnoreCase("POST")) {
                    LOG.info(String.format("AUDIT: %s executed %s %s", player, httpRequest.getMethod(),
                            httpRequest.getRequestURI()));
                    Enumeration<String> parameterNames = request.getParameterNames();
                    while (parameterNames.hasMoreElements()) {
                        String paramName = parameterNames.nextElement();
                        String paramValue = request.getParameter(paramName);
                        LOG.info(String.format("%s: %s", paramName, paramValue));
                    }
                }
                return;
            }
        }

        httpResponse.sendError(HttpStatus.SC_FORBIDDEN);
    } else {
        chain.doFilter(request, response);
    }
}

From source file:com.netspective.sparx.form.DialogContext.java

public String getUrlParamsToRecreateDialog(String prefix) {
    StringBuffer sb = new StringBuffer();

    ServletRequest request = getRequest();
    sb.append(prefix);//from  w w  w .j a  va 2  s  .  c  om
    sb.append(fieldStates.getAsUrlParams());

    Set retainedParams = null;
    if (retainReqParams != null) {
        retainedParams = new HashSet();
        for (int i = 0; i < retainReqParams.length; i++) {
            String paramName = retainReqParams[i];
            String[] paramValues = request.getParameterValues(paramName);
            if (paramValues != null)
                exportParamAsUrlParam(sb, paramName, paramValues);
            retainedParams.add(paramName);
        }
    }
    boolean retainedAnyParams = retainedParams != null;

    if (dialog.retainRequestParams()) {
        if (dialog.getDialogFlags().flagIsSet(DialogFlags.RETAIN_ALL_REQUEST_PARAMS)) {
            for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
                String paramName = (String) e.nextElement();
                if (paramName.startsWith(Dialog.PARAMNAME_DIALOGPREFIX)
                        || paramName.startsWith(Dialog.PARAMNAME_CONTROLPREFIX)
                        || (retainedAnyParams && retainedParams.contains(paramName)))
                    continue;

                exportParamAsUrlParam(sb, paramName, request.getParameterValues(paramName));
            }
        } else {
            String[] retainParams = dialog.getRetainParams();
            int retainParamsCount = retainParams.length;

            for (int i = 0; i < retainParamsCount; i++) {
                String paramName = retainParams[i];
                if (retainedAnyParams && retainedParams.contains(paramName))
                    continue;

                exportParamAsUrlParam(sb, paramName, request.getParameterValues(paramName));
            }
        }
    }

    return sb.toString();
}

From source file:edu.vt.middleware.servlet.filter.RequestDumperFilter.java

/** {@inheritDoc} */
@SuppressWarnings(value = "unchecked")
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
        throws IOException, ServletException {
    if (this.config == null) {
        return;/*w  w  w  .j a v  a 2 s .c  om*/
    }

    // Just pass through to next filter if we're not at TRACE level
    if (!logger.isTraceEnabled()) {
        chain.doFilter(request, response);
        return;
    }

    // Create a variable to hold the (possibly different) request
    // passed to downstream filters
    ServletRequest downstreamRequest = request;

    // Render the generic servlet request properties
    final StringWriter sw = new StringWriter();
    final PrintWriter writer = new PrintWriter(sw);
    writer.println("Dumping request...");
    writer.println("-----------------------------------------------------");
    writer.println("REQUEST received " + Calendar.getInstance().getTime());
    writer.println(" characterEncoding=" + request.getCharacterEncoding());
    writer.println("     contentLength=" + request.getContentLength());
    writer.println("       contentType=" + request.getContentType());
    writer.println("            locale=" + request.getLocale());
    writer.print("           locales=");

    final Enumeration<Locale> locales = request.getLocales();
    for (int i = 0; locales.hasMoreElements(); i++) {
        if (i > 0) {
            writer.print(", ");
        }
        writer.print(locales.nextElement());
    }
    writer.println();

    final Enumeration<String> paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
        final String name = paramNames.nextElement();
        writer.print("         parameter=" + name + "=");

        final String[] values = request.getParameterValues(name);
        for (int i = 0; i < values.length; i++) {
            if (i > 0) {
                writer.print(", ");
            }
            writer.print(values[i]);
        }
        writer.println();
    }
    writer.println("          protocol=" + request.getProtocol());
    writer.println("        remoteAddr=" + request.getRemoteAddr());
    writer.println("        remoteHost=" + request.getRemoteHost());
    writer.println("            scheme=" + request.getScheme());
    writer.println("        serverName=" + request.getServerName());
    writer.println("        serverPort=" + request.getServerPort());
    writer.println("          isSecure=" + request.isSecure());

    // Render the HTTP servlet request properties
    if (request instanceof HttpServletRequest) {
        final HttpServletRequest hrequest = (HttpServletRequest) request;
        writer.println("       contextPath=" + hrequest.getContextPath());

        Cookie[] cookies = hrequest.getCookies();
        if (cookies == null) {
            cookies = new Cookie[0];
        }
        for (int i = 0; i < cookies.length; i++) {
            writer.println("            cookie=" + cookies[i].getName() + "=" + cookies[i].getValue());
        }

        final Enumeration<String> headerNames = hrequest.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            final String name = headerNames.nextElement();
            final String value = hrequest.getHeader(name);
            writer.println("            header=" + name + "=" + value);
        }
        writer.println("            method=" + hrequest.getMethod());
        writer.println("          pathInfo=" + hrequest.getPathInfo());
        writer.println("       queryString=" + hrequest.getQueryString());
        writer.println("        remoteUser=" + hrequest.getRemoteUser());
        writer.println("requestedSessionId=" + hrequest.getRequestedSessionId());
        writer.println("        requestURI=" + hrequest.getRequestURI());
        writer.println("       servletPath=" + hrequest.getServletPath());

        // Create a wrapped request that contains the request body
        // and that we will pass to downstream filters
        final ByteArrayRequestWrapper wrappedRequest = new ByteArrayRequestWrapper(hrequest);
        downstreamRequest = wrappedRequest;
        writer.println(wrappedRequest.getRequestBodyAsString());
    }
    writer.println("-----------------------------------------------------");

    // Log the resulting string
    writer.flush();
    logger.trace(sw.getBuffer().toString());

    // Pass control on to the next filter
    chain.doFilter(downstreamRequest, response);
}

From source file:com.netspective.sparx.form.DialogContext.java

public void exportToXml(Element parent) {
    ServletRequest request = getRequest();
    Element dcElem = parent.getOwnerDocument().createElement("dialog-context");
    dcElem.setAttribute("name", dialog.getName());
    dcElem.setAttribute("transaction", state.getIdentifier());
    fieldStates.exportToXml(dcElem);/*  ww  w . j a v a  2  s . c o m*/

    Set retainedParams = null;
    if (retainReqParams != null) {
        retainedParams = new HashSet();
        for (int i = 0; i < retainReqParams.length; i++) {
            String paramName = retainReqParams[i];
            String[] paramValues = request.getParameterValues(paramName);
            if (paramValues != null)
                exportParamToXml(dcElem, paramName, paramValues);
            retainedParams.add(paramName);
        }
    }
    boolean retainedAnyParams = retainedParams != null;

    if (dialog.retainRequestParams()) {
        if (dialog.getDialogFlags().flagIsSet(DialogFlags.RETAIN_ALL_REQUEST_PARAMS)) {
            for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
                String paramName = (String) e.nextElement();
                if (paramName.startsWith(Dialog.PARAMNAME_DIALOGPREFIX)
                        || paramName.startsWith(Dialog.PARAMNAME_CONTROLPREFIX)
                        || (retainedAnyParams && retainedParams.contains(paramName)))
                    continue;

                exportParamToXml(dcElem, paramName, request.getParameterValues(paramName));
            }
        } else {
            String[] retainParams = dialog.getRetainParams();
            int retainParamsCount = retainParams.length;

            for (int i = 0; i < retainParamsCount; i++) {
                String paramName = retainParams[i];
                if (retainedAnyParams && retainedParams.contains(paramName))
                    continue;

                exportParamToXml(dcElem, paramName, request.getParameterValues(paramName));
            }
        }
    }

    parent.appendChild(dcElem);
}

From source file:com.netspective.sparx.form.DialogContext.java

/**
 * Returns a HTML string which contains hidden  form fields representing the dialog's information
 *//* w ww.j  a  v  a  2s. c o m*/
public String getStateHiddens() {
    final TextUtils textUtils = TextUtils.getInstance();
    ServletRequest request = getRequest();

    StringBuffer hiddens = new StringBuffer();
    hiddens.append("<input type='hidden' name='" + dialog.getDialogStateIdentifierParamName() + "' value='"
            + textUtils.escapeHTML(state.getIdentifier()) + "'>\n");

    String pageCmd = request.getParameter(AbstractHttpServletCommand.PAGE_COMMAND_REQUEST_PARAM_NAME);
    if (pageCmd != null)
        hiddens.append(
                "<input type='hidden' name='" + AbstractHttpServletCommand.PAGE_COMMAND_REQUEST_PARAM_NAME
                        + "' value='" + textUtils.escapeHTML(pageCmd) + "'>\n");

    // this hidden field should be filled in by the 'triggering' form field before submission of the form
    hiddens.append("<input type=\"hidden\" name=\"" + dialog.getDialogValidateTriggerFieldParamName()
            + "\" value=\"\"/>");

    String redirectUrlParamValue = (state.isInitialEntry()
            ? request.getParameter(dialog.getPostExecuteRedirectUrlParamName())
            : request.getParameter(DialogContext.DEFAULT_REDIRECT_PARAM_NAME));
    if (redirectUrlParamValue != null)
        hiddens.append("<input type='hidden' name='" + dialog.getPostExecuteRedirectUrlParamName() + "' value='"
                + textUtils.escapeHTML(redirectUrlParamValue) + "'>\n");

    Set retainedParams = null;
    if (retainReqParams != null) {
        retainedParams = new HashSet();
        for (int i = 0; i < retainReqParams.length; i++) {
            String paramName = retainReqParams[i];
            Object paramValue = request.getParameter(paramName);
            if (paramValue == null)
                continue;

            hiddens.append("<input type='hidden' name='");
            hiddens.append(paramName);
            hiddens.append("' value='");
            hiddens.append(textUtils.escapeHTML(paramValue.toString()));
            hiddens.append("'>\n");
            retainedParams.add(paramName);
        }
    }
    boolean retainedAnyParams = retainedParams != null;

    if (dialog.retainRequestParams()) {
        if (dialog.getDialogFlags().flagIsSet(DialogFlags.RETAIN_ALL_REQUEST_PARAMS)) {
            for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
                String paramName = (String) e.nextElement();
                if (paramName.startsWith(Dialog.PARAMNAME_DIALOGPREFIX)
                        || paramName.startsWith(Dialog.PARAMNAME_CONTROLPREFIX)
                        || (retainedAnyParams && retainedParams.contains(paramName)))
                    continue;

                hiddens.append("<input type='hidden' name='");
                hiddens.append(paramName);
                hiddens.append("' value='");
                hiddens.append(request.getParameter(paramName) != null
                        ? textUtils.escapeHTML(request.getParameter(paramName))
                        : "");
                hiddens.append("'>\n");
            }
        } else {
            String[] retainParams = dialog.getRetainParams();
            int retainParamsCount = retainParams.length;

            for (int i = 0; i < retainParamsCount; i++) {
                String paramName = retainParams[i];
                if (retainedAnyParams && retainedParams.contains(paramName))
                    continue;

                hiddens.append("<input type='hidden' name='");
                hiddens.append(paramName);
                hiddens.append("' value='");
                hiddens.append(request.getParameter(paramName) != null
                        ? textUtils.escapeHTML(request.getParameter(paramName))
                        : "");
                hiddens.append("'>\n");
            }
        }
    }

    return hiddens.toString();
}