Example usage for javax.servlet.http HttpServletRequest getParameterNames

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

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest 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:com.company.project.core.connector.JSONHelper.java

/**
 * This method would create a string consisting of a JSON document with all
 * the necessary elements set from the HttpServletRequest request.
 * /*from   www .  j av a  2s .  c  o  m*/
 * @param request
 *            The HttpServletRequest
 * @return the string containing the JSON document.
 * @throws Exception
 *             If there is any error processing the request.
 */
public static String createJSONString(HttpServletRequest request, String controller) throws Exception {
    JSONObject obj = new JSONObject();
    try {
        Field[] allFields = Class
                .forName("com.microsoft.windowsazure.activedirectory.sdk.graph.models." + controller)
                .getDeclaredFields();
        String[] allFieldStr = new String[allFields.length];
        for (int i = 0; i < allFields.length; i++) {
            allFieldStr[i] = allFields[i].getName();
        }
        List<String> allFieldStringList = Arrays.asList(allFieldStr);
        Enumeration<String> fields = request.getParameterNames();

        while (fields.hasMoreElements()) {

            String fieldName = fields.nextElement();
            String param = request.getParameter(fieldName);
            if (allFieldStringList.contains(fieldName)) {
                if (param == null || param.length() == 0) {
                    if (!fieldName.equalsIgnoreCase("password")) {
                        obj.put(fieldName, JSONObject.NULL);
                    }
                } else {
                    if (fieldName.equalsIgnoreCase("password")) {
                        obj.put("passwordProfile", new JSONObject("{\"password\": \"" + param + "\"}"));
                    } else {
                        obj.put(fieldName, param);

                    }
                }
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    return obj.toString();
}

From source file:org.mitre.openid.connect.client.AbstractOIDCAuthenticationFilter.java

/**
 * Builds the redirect_uri that will be sent to the Authorization Endpoint.
 * By default returns the URL of the current request minus zero or more
 * fields of the URL's query string./*from w ww  .j a  v a  2 s  . c  om*/
 * 
 * @param request
 *            the current request which is being processed by this filter
 * @param ignoreFields
 *            an array of field names to ignore.
 * @return a URL built from the messaged parameters.
 */
public static String buildRedirectURI(HttpServletRequest request, String[] ignoreFields) {

    List<String> ignore = (ignoreFields != null) ? Arrays.asList(ignoreFields) : null;

    boolean isFirst = true;

    StringBuffer sb = request.getRequestURL();

    for (Enumeration<?> e = request.getParameterNames(); e.hasMoreElements();) {

        String name = (String) e.nextElement();

        if ((ignore == null) || (!ignore.contains(name))) {

            // Assume for simplicity that there is only one value

            String value = request.getParameter(name);

            if (value == null) {
                continue;
            }

            if (isFirst) {
                sb.append("?");
                isFirst = false;
            }

            sb.append(name).append("=").append(value);

            if (e.hasMoreElements()) {
                sb.append("&");
            }
        }
    }

    return sb.toString();
}

From source file:com.feilong.servlet.http.RequestUtil.java

/**
 * ?????? (?:???,???)./*from   w ww.  j av a2 s . c om*/
 *
 * @param request
 *            
 * @param paramName
 *            ???
 * @return ??true,??false <br>
 *          <code>paramName</code> null, {@link NullPointerException}<br>
 *          <code>paramName</code> blank, {@link IllegalArgumentException}<br>
 * @see com.feilong.core.util.EnumerationUtil#contains(Enumeration, Object)
 * @since 1.4.0
 */
public static boolean containsParam(HttpServletRequest request, String paramName) {
    Validate.notBlank(paramName, "paramName can't be null/empty!");
    return EnumerationUtil.contains(request.getParameterNames(), paramName);
}

From source file:fr.paris.lutece.portal.service.util.AppPathService.java

/**
 * Retrieve the url to redirect to after login. It is given by the
 * redirectUrl parameter if found. The request parameters are copied (except
 * the login and acces code). This is to be used by the doLogin method of
 * AdminLoginJspBean.//from   w w w .  ja  va 2  s  .  com
 *
 * @param request the http request
 * @param strDefaultRedirectUrl the default url to go to after login
 * @return an UrlItem corresponding to the url to redirect to after login.
 */
public static UrlItem resolveRedirectUrl(HttpServletRequest request, String strDefaultRedirectUrl) {
    String strUrl = strDefaultRedirectUrl;

    String strUrlKey = request.getParameter(Parameters.REDIRECT_URL);
    String strRedirectUrl = null;

    if (strUrlKey != null) {
        strRedirectUrl = AppPropertiesService.getProperty(PROPERTY_PREFIX_URL + strUrlKey);
    }

    if (strRedirectUrl != null) {
        strUrl = strRedirectUrl;
    }

    Enumeration enumParams = request.getParameterNames();
    UrlItem url = new UrlItem(getBaseUrl(request) + strUrl);

    String strParamName;

    while (enumParams.hasMoreElements()) {
        strParamName = (String) enumParams.nextElement();

        if (!strParamName.equals(Parameters.REDIRECT_URL) && !strParamName.equals(Parameters.ACCESS_CODE)
                && !strParamName.equals(Parameters.PASSWORD)) {
            url.addParameter(strParamName, request.getParameter(strParamName));
        }
    }

    return url;
}

From source file:org.openmrs.web.attribute.WebAttributeUtil.java

/**
 * Handles attributes submitted on a form that uses the "attributesForType" tag
 *
 * @param owner the object that the attributes will be applied to
 * @param errors Spring binding object for owner
 * @param attributeClass the actual class of the attribute we need to instantiate, e.g. LocationAttribute
 * @param request the user's submission/*from   w w  w .  j  ava2 s  .co  m*/
 * @param attributeTypes all available attribute types for owner's class
 */
public static <AttributeClass extends BaseAttribute, CustomizableClass extends Customizable<AttributeClass>, AttributeTypeClass extends AttributeType<CustomizableClass>> void handleSubmittedAttributesForType(
        CustomizableClass owner, BindingResult errors, Class<AttributeClass> attributeClass,
        HttpServletRequest request, List<AttributeTypeClass> attributeTypes) {
    // TODO figure out if this toVoid thing is still relevant
    List<AttributeClass> toVoid = new ArrayList<AttributeClass>(); // a bit of a hack to avoid voiding things if there are errors
    for (AttributeType<?> attrType : attributeTypes) {
        CustomDatatype dt = CustomDatatypeUtil.getDatatype(attrType);
        CustomDatatypeHandler handler = CustomDatatypeUtil.getHandler(attrType);
        // Look for parameters starting with "attribute.${ attrType.id }". They may be either of: 
        // * attribute.${ attrType.id }.new[${ meaningless int }]
        // * attribute.${ attrType.id }.existing[${ existingAttribute.id }]
        for (@SuppressWarnings("unchecked")
        Enumeration<String> iter = request.getParameterNames(); iter.hasMoreElements();) {
            String paramName = iter.nextElement();
            if (paramName.startsWith("attribute." + attrType.getId())) {
                String afterPrefix = paramName.substring(("attribute." + attrType.getId()).length());
                Object valueAsObject;
                try {
                    valueAsObject = getValue(request, dt, handler, paramName);
                } catch (Exception ex) {
                    errors.rejectValue("activeAttributes", "attribute.error.invalid",
                            new Object[] { attrType.getName() }, "Illegal value for " + attrType.getName());
                    continue;
                }
                if (afterPrefix.startsWith(".new[")) {
                    // if not empty, we create a new one
                    if (valueAsObject != null && !"".equals(valueAsObject)) {
                        AttributeClass attr;
                        try {
                            attr = attributeClass.newInstance();
                        } catch (Exception ex) {
                            throw new RuntimeException(ex);
                        }
                        attr.setAttributeType(attrType);
                        attr.setValue(valueAsObject);
                        owner.addAttribute(attr);
                    }

                } else if (afterPrefix.startsWith(".existing[")) {
                    // if it has changed, we edit the existing one
                    Integer existingAttributeId = getFromSquareBrackets(afterPrefix);
                    AttributeClass existing = findAttributeById(owner, existingAttributeId);
                    if (existing == null) {
                        throw new RuntimeException(
                                "Visit was modified between page load and submit. Try again.");
                    }
                    if (valueAsObject == null) {
                        // they changed an existing value to "", so we void that attribute
                        toVoid.add(existing);
                    } else if (!existing.getValue().equals(valueAsObject)) {
                        // they changed an existing value to a new value
                        toVoid.add(existing);
                        AttributeClass newVal;
                        try {
                            newVal = attributeClass.newInstance();
                        } catch (Exception ex) {
                            throw new RuntimeException(ex);
                        }
                        newVal.setAttributeType(attrType);
                        newVal.setValue(valueAsObject);
                        owner.addAttribute(newVal);
                    }
                }
            }
        }
    }

    for (Attribute<?, ?> attr : toVoid) {
        voidAttribute(attr);
    }
}

From source file:com.jigsforjava.web.controller.JigsMethodNameResolver.java

@SuppressWarnings("unchecked")
private String findActionName(HttpServletRequest request) {
    for (Enumeration<String> i = request.getParameterNames(); i.hasMoreElements();) {
        String name = i.nextElement();

        if (name.startsWith(ACTION_PARAMETER_PREFIX)) {
            return name.substring(ACTION_PARAMETER_PREFIX.length());
        }//from w  w w  .  j a  v  a 2s. c om
    }

    return null;
}

From source file:com.jquery.web.Request.java

private void from(HttpServletRequest servletRequest) {
    Enumeration<?> names = servletRequest.getParameterNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        request.put(name, servletRequest.getParameterValues(name));
    }/*from   w  w  w. ja  v a 2 s .c om*/
}

From source file:com.metadot.book.connectr.server.servlets.LoginFacebookServlet.java

private String getParams(HttpServletRequest request) {
    Enumeration<?> all = request.getParameterNames();
    String msg = "";
    while (all.hasMoreElements()) {
        String key = (String) all.nextElement();
        msg += key + " = " + request.getParameter(key) + "<br/>\n";
    }//from w w w. j  a v  a2  s . co  m
    return msg;
}

From source file:org.impalaframework.extension.mvc.util.RequestModelHelperTest.java

public void testImplicitParams() throws Exception {
    HttpServletRequest request = createMock(HttpServletRequest.class);
    expect(request.getParameterNames()).andReturn(new Enumeration<String>() {

        private String[] list = { "one", "two" };
        int index;

        public boolean hasMoreElements() {
            return (index < list.length);
        }/* w w w.j a  v  a2 s .  co m*/

        public String nextElement() {
            final String string = list[index];
            index++;
            return string;
        }

    });

    expect(request.getParameter("one")).andReturn("v1");
    expect(request.getParameter("two")).andReturn("v2");

    replay(request);
    final ModelMap modelMap = new ModelMap();
    RequestModelHelper.setParameters(request, modelMap);
    assertEquals(2, modelMap.size());
    verify(request);
}

From source file:com.redhat.rhn.frontend.servlets.DumpFilter.java

private void logParameters(HttpServletRequest req) {
    Enumeration items = req.getParameterNames();
    while (items.hasMoreElements()) {
        String name = (String) items.nextElement();
        String[] values = req.getParameterValues(name);
        for (int i = 0; i < values.length; i++) {
            log.debug("Parameter: name [" + name + "] value [" + values[i] + "]");
        }/*from   www . j  av  a 2 s .  c o m*/
    }
}