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:util.servlet.PaypalListenerServlet.java

@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(Constants.IPN_SANDBOX_ENDPOINT);
    List<NameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("cmd", "_notify-validate")); //You need to add this parameter to tell PayPal to verify
    for (Enumeration<String> e = request.getParameterNames(); e.hasMoreElements();) {
        String name = e.nextElement();
        String value = request.getParameter(name);
        params.add(new BasicNameValuePair(name, value));
    }/*w  w w.  java 2s .  c om*/
    post.setEntity(new UrlEncodedFormEntity(params));
    String rc = getRC(client.execute(post)).trim();
    if ("VERIFIED".equals(rc)) {
        //Your business code comes here
    }
}

From source file:de.iteratec.turm.servlets.TurmServlet.java

/**
 * Parameters that are contained in the current request are used to fill
 * a given Java Bean. This is similar to the way Struts fills its ActionForms.
 * //  www  . j a v  a2 s . co m
 * @param request The current Serlvet Request
 * @param bean A JavaBean that is to be populated.
 * @throws TurmException If the JavaBean could not be populated.
 */
@SuppressWarnings("unchecked")
protected final void populate(HttpServletRequest request, Object bean) throws TurmException {
    HashMap<String, String[]> map = new HashMap<String, String[]>();
    Enumeration<String> names = request.getParameterNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        map.put(name, request.getParameterValues(name));
    }
    try {
        BeanUtils.populate(bean, map);
    } catch (IllegalAccessException e) {
        throw new TurmException("error.internal", e);
    } catch (InvocationTargetException e) {
        throw new TurmException("error.internal", e);
    }
}

From source file:com.duroty.controller.actions.GoogieSpellAction.java

protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    ActionMessages errors = new ActionMessages();

    PostMethod post = null;//  www.ja  v  a2s  . c  om

    try {
        Enumeration enumeration = request.getParameterNames();
        while (enumeration.hasMoreElements()) {
            String name = (String) enumeration.nextElement();
            String value = (String) request.getParameter(name);
            DLog.log(DLog.WARN, this.getClass(), name + " >> " + value);
        }

        String text = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><spellrequest textalreadyclipped=\"0\" ignoredups=\"0\" ignoredigits=\"1\" ignoreallcaps=\"1\"><text>"
                + request.getParameter("check") + "</text></spellrequest>";

        String lang = request.getParameter("lang");

        String id = request.getParameter("id");
        String cmd = request.getParameter("cmd");

        String url = "https://" + googleUrl + "/tbproxy/spell?lang=" + lang + "&hl=" + lang;

        post = new PostMethod(url);
        post.setRequestBody(text);
        post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");

        HttpClient client = new HttpClient();
        int result = client.executeMethod(post);

        // Display status code
        System.out.println("Response status code: " + result);

        // Display response
        System.out.println("Response body: ");

        String resp = post.getResponseBodyAsString();

        System.out.println(resp);

        String goodieSpell = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";

        Vector matches = getMatches(resp);

        if (matches.size() <= 0) {
            goodieSpell = goodieSpell + "<res id=\"" + id + "\" cmd=\"" + cmd + "\" />";
        } else {
            goodieSpell = goodieSpell + "<res id=\"" + id + "\" cmd=\"" + cmd + "\">";

            StringBuffer buffer = new StringBuffer();

            for (int i = 0; i < matches.size(); i++) {
                if (buffer.length() > 0) {
                    buffer.append("+");
                }

                String aux = (String) matches.get(i);
                aux = aux.substring(aux.indexOf(">") + 1, aux.length());
                aux = aux.substring(0, aux.indexOf("<"));
                aux = aux.trim().replaceAll("\\s+", "\\+");

                buffer.append(aux);
            }

            goodieSpell = goodieSpell + buffer.toString() + "</res>";

        }

        request.setAttribute("googieSpell", goodieSpell);
    } catch (Exception ex) {
        String errorMessage = ExceptionUtilities.parseMessage(ex);

        if (errorMessage == null) {
            errorMessage = "NullPointerException";
        }

        errors.add("general", new ActionMessage(ExceptionCode.ERROR_MESSAGES_PREFIX + "general", errorMessage));
        request.setAttribute("exception", errorMessage);
        doTrace(request, DLog.ERROR, getClass(), errorMessage);
    } finally {
        try {
            post.releaseConnection();
        } catch (Exception e) {
        }
    }

    if (errors.isEmpty()) {
        doTrace(request, DLog.INFO, getClass(), "OK");

        return mapping.findForward(Constants.ACTION_SUCCESS_FORWARD);
    } else {
        saveErrors(request, errors);

        return mapping.findForward(Constants.ACTION_FAIL_FORWARD);
    }
}

From source file:de.hybris.platform.acceleratorservices.web.payment.controllers.HostedOrderPageMockController.java

protected String serializeRequestParameters(final HttpServletRequest request) {
    final StringBuilder result = new StringBuilder();

    final Enumeration myEnum = request.getParameterNames();
    while (myEnum.hasMoreElements()) {
        final String paramName = (String) myEnum.nextElement();
        result.append(paramName).append(SEPARATOR_STR).append(request.getParameter(paramName));
        if (myEnum.hasMoreElements()) {
            result.append(SEPARATOR_STR);
        }/*  www .ja  va 2 s .  com*/
    }

    return result.toString();
}

From source file:com.eviware.soapui.impl.wsdl.monitor.JProxyServletWsdlMonitorMessageExchange.java

public void setHttpRequestParameters(HttpServletRequest httpRequest) {
    Enumeration<String> parameterNames = httpRequest.getParameterNames();
    Map<String, String> parameterMap = new HashMap<String, String>();
    while (parameterNames.hasMoreElements()) {
        String name = parameterNames.nextElement();
        parameterMap.put(name, httpRequest.getParameter(name));
    }//w  w  w .j  a  va  2 s  .com

    this.httpRequestParameters = parameterMap;
}

From source file:fr.paris.lutece.portal.service.admin.AdminAuthenticationService.java

/**
 * Set the admin login next url/*from   w  ww  .ja  v a 2  s .c om*/
 * @param request the HTTP request
 */
public void setLoginNextUrl(HttpServletRequest request) {
    String strNextUrl = request.getRequestURI();
    UrlItem url = new UrlItem(strNextUrl);
    Enumeration enumParams = request.getParameterNames();

    while (enumParams.hasMoreElements()) {
        String strParamName = (String) enumParams.nextElement();
        url.addParameter(strParamName, request.getParameter(strParamName));
    }

    HttpSession session = request.getSession(true);
    session.setAttribute(ATTRIBUTE_ADMIN_LOGIN_NEXT_URL, url.getUrl());
}

From source file:dk.clarin.tools.rest.register.java

public String getargs(HttpServletRequest request, List<FileItem> items) {
    String arg = "";
    /*//from w w w .ja v  a 2s. c o  m
    * Parse the request
    */

    @SuppressWarnings("unchecked")
    Enumeration<String> parmNames = (Enumeration<String>) request.getParameterNames();
    boolean is_multipart_formData = ServletFileUpload.isMultipartContent(request);

    logger.debug("is_multipart_formData:" + (is_multipart_formData ? "ja" : "nej"));

    if (is_multipart_formData) {
        try {
            Iterator<FileItem> itr = items.iterator();
            while (itr.hasNext()) {
                FileItem item = (FileItem) itr.next();
                if (item.isFormField()) {
                    arg = arg + " (" + workflow.quote(item.getFieldName()) + "."
                            + workflow.quote(item.getString("UTF-8").trim()) + ")";
                }
            }
        } catch (Exception ex) {
            logger.error("uploadHandler.parseRequest Exception");
        }
    }

    for (Enumeration<String> e = parmNames; e.hasMoreElements();) {
        String parmName = e.nextElement();
        arg = arg + " (" + workflow.quote(parmName) + ".";
        String vals[] = request.getParameterValues(parmName);
        for (int j = 0; j < vals.length; ++j) {
            arg += " " + workflow.quote(vals[j]) + "";
        }
        arg += ")";
    }
    logger.debug("arg = [" + arg + "]");
    return arg;
}

From source file:com.ctb.prism.report.api.CustomViewerServlet.java

protected String getBody(HttpServletRequest request, WebReportContext webReportContext) {
    Map<String, Object> contextMap = new HashMap<String, Object>();
    String reportUri = request.getParameter(WebUtil.REQUEST_PARAMETER_REPORT_URI);
    /** added by PRISM **/
    @SuppressWarnings("unchecked")
    Enumeration<String> paramsEnum = request.getParameterNames();

    Map<String, String> paramsMap = new HashMap<String, String>();

    while (paramsEnum.hasMoreElements()) {
        String param = paramsEnum.nextElement();
        paramsMap.put(param, request.getParameter(param));
    }//from w ww  .  ja v  a  2s .  c o m
    paramsMap.put(WebReportContext.REQUEST_PARAMETER_REPORT_CONTEXT_ID,
            String.valueOf(webReportContext.getId()));
    String reportUrl = WebUtil.getInstance(getJasperReportsContext()).getReportInteractionPath();
    /** end added by PRISM **/
    contextMap.put("reportUri", reportUri);
    contextMap.put("async", Boolean.valueOf(request.getParameter(WebUtil.REQUEST_PARAMETER_ASYNC_REPORT)));

    String reportPage = request.getParameter(WebUtil.REQUEST_PARAMETER_PAGE);
    int pageIdx = reportPage == null ? 0 : Integer.parseInt(reportPage);
    contextMap.put("page", pageIdx);
    contextMap.put("contextPath", request.getContextPath());

    return VelocityUtil.processTemplate(getBodyTemplate(), contextMap);
}

From source file:net.oauth.signature.GoogleCodeCompatibilityTests.java

/**
 * tests compatibility of calculating the signature base string.
 *//*from w w w.j  a  v a  2  s . c  om*/
@Test
public void testCalculateSignatureBaseString() throws Exception {
    final String baseUrl = "http://www.springframework.org/schema/security/";
    CoreOAuthProviderSupport support = new CoreOAuthProviderSupport() {
        @Override
        protected String getBaseUrl(HttpServletRequest request) {
            return baseUrl;
        }
    };

    Map<String, String[]> parameterMap = new HashMap<String, String[]>();
    parameterMap.put("a", new String[] { "value-a" });
    parameterMap.put("b", new String[] { "value-b" });
    parameterMap.put("c", new String[] { "value-c" });
    parameterMap.put("param[1]", new String[] { "aaa", "bbb" });

    when(request.getParameterNames()).thenReturn(Collections.enumeration(parameterMap.keySet()));
    for (Map.Entry<String, String[]> param : parameterMap.entrySet()) {
        when(request.getParameterValues(param.getKey())).thenReturn(param.getValue());
    }

    String header = "OAuth realm=\"http://sp.example.com/\","
            + "                oauth_consumer_key=\"0685bd9184jfhq22\","
            + "                oauth_token=\"ad180jjd733klru7\","
            + "                oauth_signature_method=\"HMAC-SHA1\","
            + "                oauth_signature=\"wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D\","
            + "                oauth_timestamp=\"137131200\"," + "                oauth_callback=\""
            + OAuthCodec.oauthEncode("http://myhost.com/callback") + "\","
            + "                oauth_nonce=\"4572616e48616d6d65724c61686176\","
            + "                oauth_version=\"1.0\"";
    when(request.getHeaders("Authorization")).thenReturn(Collections.enumeration(Arrays.asList(header)));
    when(request.getMethod()).thenReturn("GET");
    String ours = support.getSignatureBaseString(request);

    when(request.getHeaders("Authorization")).thenReturn(Collections.enumeration(Arrays.asList(header)));
    when(request.getParameterMap()).thenReturn(parameterMap);
    when(request.getHeaderNames()).thenReturn(null);
    OAuthMessage message = OAuthServlet.getMessage(request, baseUrl);

    String theirs = OAuthSignatureMethod.getBaseString(message);
    assertEquals(theirs, ours);
}

From source file:alpha.portal.webapp.controller.CardFormController.java

/**
 * shows the card form./*from   w  ww  .  ja  va 2s.com*/
 * 
 * @param request
 *            the request
 * @return ModelView
 * @see cardform.jsp
 */
@SuppressWarnings("unchecked")
@ModelAttribute("alphacard")
@RequestMapping(method = RequestMethod.GET)
protected String showForm(final HttpServletRequest request) {

    this.log.fatal("This fallback Method should not be called");

    final Enumeration params = request.getParameterNames();
    while (params.hasMoreElements()) {
        this.log.error(params.nextElement().toString());
    }

    return "redirect:/caseMenu";
}