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:pt.webdetails.cdc.plugin.CdcContentGenerator.java

/**
 * Set up parameters to render a dashboard from the presentation layer
 *
 * @param dashboardName/*from ww w  .  ja va2  s.com*/
 * @return
 */
private Map<String, Object> getRenderRequestParameters(String dashboardName) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("solution", "system");
    params.put("path", UI_PATH);
    params.put("file", dashboardName);
    params.put("bypassCache", "true");
    params.put("absolute", "true");
    params.put("inferScheme", "true");
    params.put("root", getRoot());

    //add request parameters
    ServletRequest request = getRequest();
    @SuppressWarnings("unchecked") //should always be String
    Enumeration<String> originalParams = request.getParameterNames();
    // Iterate and put the values there
    while (originalParams.hasMoreElements()) {
        String originalParam = originalParams.nextElement();
        params.put(originalParam, request.getParameter(originalParam));
    }

    return params;
}

From source file:edu.harvard.i2b2.fhir.oauth2.ws.PublicClientFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    String url = ((HttpServletRequest) request).getRequestURL().toString();
    logger.info("url:" + url);
    //if(!url.startsWith("/token")) return;

    String msg = "";
    Enumeration<String> kl = request.getParameterNames();
    while (kl.hasMoreElements()) {
        String k = kl.nextElement();
        msg += k + "->" + request.getParameter(k) + "\n";
    }/* ww w.  java2 s.c o m*/
    logger.info(msg);

    chain.doFilter(new PublicClientWrapper((HttpServletRequest) request), response);
}

From source file:pt.webdetails.cdv.CdvContentGenerator.java

private Map<String, Object> getRenderRequestParameters(String dashboardName) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("solution", "system");
    params.put("path", UI_PATH);
    params.put("file", dashboardName);
    params.put("bypassCache", "true");
    params.put("absolute", "true");
    params.put("inferScheme", "true");
    params.put("root", getRoot());

    //add request parameters
    ServletRequest request = getRequest();
    @SuppressWarnings("unchecked") //should always be String
    Enumeration<String> originalParams = request.getParameterNames();
    // Iterate and put the values there
    while (originalParams.hasMoreElements()) {
        String originalParam = originalParams.nextElement();
        params.put(originalParam, request.getParameter(originalParam));
    }//from   www .  ja  va  2  s.co m

    return params;
}

From source file:org.nimbustools.messaging.query.security.QueryAuthenticationFilter.java

private void appendCanonicalQueryString_v2(ServletRequest request, StringBuilder buf) {
    final Set<String> sortedKeys = new TreeSet<String>();
    final Enumeration paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
        String param = (String) paramNames.nextElement();

        // don't include signature in canonical query string
        if (!param.equals(this.signatureParameter)) {
            sortedKeys.add(param);//from   www.j  ava2 s .co m
        }
    }
    boolean first = true;
    for (String key : sortedKeys) {
        String[] values = request.getParameterValues(key);

        for (String val : values) {
            if (first) {
                first = false;
            } else {
                buf.append('&');
            }

            buf.append(urlEncode(key)).append('=');
            buf.append(urlEncode(val));
        }
    }
}

From source file:no.sesat.search.http.filters.SiteLocatorFilter.java

private static void logAccessRequest(final ServletRequest request) {

    final StringBuilder url = new StringBuilder();
    final String referer;
    final String method;
    final String ip = request.getRemoteAddr();
    final String userAgent;
    final String sesamId;
    final String sesamUser;

    if (request instanceof HttpServletRequest) {

        final HttpServletRequest req = (HttpServletRequest) request;
        url.append(req.getRequestURI() + (null != req.getQueryString() ? '?' + req.getQueryString() : ""));
        referer = req.getHeader("Referer");
        method = req.getMethod();//  ww w  .ja v a2s . co  m
        userAgent = req.getHeader("User-Agent");
        sesamId = getCookieValue(req, "SesamID");
        sesamUser = getCookieValue(req, "SesamUser");

    } else {

        for (@SuppressWarnings("unchecked")
        Enumeration<String> en = request.getParameterNames(); en.hasMoreElements();) {

            final String param = en.nextElement();
            url.append(param + '=' + request.getParameter(param));
            if (en.hasMoreElements()) {
                url.append('&');
            }
        }
        referer = method = userAgent = sesamId = sesamUser = UNKNOWN;
    }

    ACCESS_LOG.info("<request>" + "<url method=\"" + method + "\">"
            + StringEscapeUtils.escapeXml(url.toString()) + "</url>"
            + (null != referer ? "<referer>" + StringEscapeUtils.escapeXml(referer) + "</referer>" : "")
            + "<browser ipaddress=\"" + ip + "\">" + StringEscapeUtils.escapeXml(userAgent) + "</browser>"
            + "<user id=\"" + sesamId + "\">" + sesamUser + "</user>" + "</request>");
}

From source file:com.xsw.utils.Servlets.java

/**
 * ???Request Parameters, copy from spring WebUtils.
 * /*from   w ww.j a  v  a 2s .c  o m*/
 * Parameter???.
 */
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
    Validate.notNull(request, "Request must not be null");
    Map<String, Object> params = new TreeMap<String, Object>();
    if (prefix == null) {
        prefix = "";
    }
    // process Attribute
    Enumeration<String> paramNames = request.getAttributeNames();
    while (paramNames != null && paramNames.hasMoreElements()) {
        String paramName = paramNames.nextElement();
        if ("".equals(prefix) || paramName.startsWith(prefix)) {
            String unprefixed = paramName.substring(prefix.length());
            Object attobj = request.getAttribute(paramName);
            String[] values = null;
            if (attobj instanceof String[]) {
                values = (String[]) attobj;
            } else {
                values = new String[1];
                values[0] = String.valueOf(attobj);
            }
            if (values == null || values.length == 0) {
                // Do nothing, no values found at all.
            } else if (values.length > 1) {
                params.put(unprefixed, values);
            } else {
                params.put(unprefixed, values[0]);
            }
        }
    }
    // process parameter
    paramNames = request.getParameterNames();
    while (paramNames != null && paramNames.hasMoreElements()) {
        String paramName = paramNames.nextElement();
        if ("".equals(prefix) || paramName.startsWith(prefix)) {
            String unprefixed = paramName.substring(prefix.length());
            String[] values = request.getParameterValues(paramName);
            if (values == null || values.length == 0) {
                // Do nothing, no values found at all.
            } else if (values.length > 1) {
                params.put(unprefixed, values);
            } else {
                params.put(unprefixed, values[0]);
            }
        }
    }
    return params;
}

From source file:com.doculibre.constellio.filters.SetCharacterEncodingFilter.java

/**
 * Select and set (if specified) the character encoding to be used to
 * interpret request parameters for this request.
 * //from   w w w .ja  v  a  2  s.  c  om
 * @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
 */
@SuppressWarnings("unchecked")
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (false) {
        chain.doFilter(request, response);
    } else {
        String lookupCharSet = lookupCharSet(request);

        SimpleParams simpleParams = new SimpleParams();
        Enumeration<String> paramNames = request.getParameterNames();
        while (paramNames.hasMoreElements()) {
            String paramName = paramNames.nextElement();
            String convertedParamName = convertIfNeeded(paramName, lookupCharSet);
            String[] paramValues = request.getParameterValues(paramName);
            List<String> convertedParamValues = new ArrayList<String>();
            if (paramValues != null) {
                for (String paramValue : paramValues) {
                    String convertedParamValue = convertIfNeeded(paramValue, lookupCharSet);
                    if (convertedParamValue != null) {
                        convertedParamValues.add(convertedParamValue);
                    }
                }
            }
            simpleParams.add(convertedParamName, convertedParamValues.toArray(new String[0]));
        }
        HttpServletRequest requestWrapper = new SimpleParamsHttpServletRequestWrapper(
                (HttpServletRequest) request, simpleParams);

        // Conditionally select and set the character encoding to be used
        if (ignore || (request.getCharacterEncoding() == null)) {
            String encoding = selectEncoding(request);
            if (encoding != null) {
                request.setCharacterEncoding(encoding);
            }
        }

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

From source file:com.spshop.web.ShoppingController.java

@SuppressWarnings("unchecked")
private List<UserOption> retriveUserOptions(ServletRequest request) {
    List<UserOption> options = new ArrayList<UserOption>();
    Enumeration<String> params = request.getParameterNames();
    while (params.hasMoreElements()) {
        String param = params.nextElement();
        String[] ps = param.split(SPLITER_AT);
        if (ps.length > 1) {
            UserOption option = new UserOption();
            option.setCreateDate(new Date());
            option.setOptionName(ps[1]);
            if (COLOR.equals(ps[0])) {
                option.setValue(request.getParameter(param));
                option.setOptionType(SelectType.COLOR_SINGLE);
                options.add(option);/*from   w  w  w.j  a  va 2  s. c  om*/
            }

            if (TEXT.equals(ps[0])) {
                option.setValue(request.getParameter(param));
                option.setOptionType(SelectType.SINGLE_LIST);
                options.add(option);
            }

            if (TEXTS.equals(ps[0])) {

            }
        }
    }
    return options;
}

From source file:pt.webdetails.cfr.CfrContentGenerator.java

private Map<String, Object> getRenderRequestParameters(String dashboardName) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("solution", "system");
    params.put("path", UI_PATH);
    params.put("file", dashboardName);
    params.put("bypassCache", "true");
    params.put("absolute", "false");
    params.put("inferScheme", "false");
    params.put("root", getRoot());

    // add request parameters
    ServletRequest request = getRequest();
    @SuppressWarnings("unchecked")
    // should always be String
    Enumeration<String> originalParams = request.getParameterNames();
    // Iterate and put the values there
    while (originalParams.hasMoreElements()) {
        String originalParam = originalParams.nextElement();
        params.put(originalParam, request.getParameter(originalParam));
    }// w  w w . j  a  v a  2 s  . c  o  m

    return params;
}

From source file:pl.com.softproject.altkom.hibernate.forms.web.controller.FormControler.java

@RequestMapping(value = "/saveFormDate", method = RequestMethod.POST)
public String saveFormDate(ServletRequest request, @RequestParam("form_id") long formId) {

    Person person = new Person();

    person.setName(request.getParameter("person.name"));
    person.setAddress(new Address(request.getParameter("person.address.citi"),
            request.getParameter("person.address.street"), request.getParameter("person.address.postcode")));

    personDAO.save(person);//from w  w  w  . j  a v  a 2s.  c  om
    Form form = formDAO.findOne(formId);

    FormData formData = new FormData();
    formData.setForm(form);
    formData.setCreationDate(new Date());
    formData.setPerson(person);

    Enumeration<String> params = request.getParameterNames();

    while (params.hasMoreElements()) {
        String param = params.nextElement();

        if (logger.isDebugEnabled())
            logger.debug(param);

        if (param.startsWith("field_")) {
            long fieldId = Long.parseLong(param.replaceFirst("field_", ""));

            FormFieldValue value = new FormFieldValue();
            value.setFieldValue(request.getParameter(param));
            value.setFormData(formData);
            value.setFormField(new FormField(fieldId));
            formData.getAnswers().add(value);
        }
    }

    formDataDAO.save(formData);

    return "redirect:/showForms.htm";
}