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.rainycape.reducer.servlets.BaseServlet.java

private Collection<String> getSortedParameterNames(HttpServletRequest req) {
    // We want a deterministic order so that dependencies can span input files.
    // We don't trust the servlet container to return query parameters in any
    // order, so we impose our own ordering. In this case, we use natural String
    // ordering./*from ww w  .  j  av  a  2s.  c  o  m*/
    @SuppressWarnings("unchecked")
    List<String> list = Lists
            .newArrayList(Iterators.forEnumeration((Enumeration<String>) req.getParameterNames()));
    // Some parameter names should be ignored.
    Iterable<String> filtered = Collections2.filter(list, new Predicate<String>() {
        @Override
        public boolean apply(@Nullable String s) {
            return !(s.contains("_") || s.contains("-"));
        }
    });
    return Ordering.natural().sortedCopy(filtered);
}

From source file:com.adito.extensions.actions.GetExtensionDescriptorAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    request.setAttribute(Constants.REQ_ATTR_COMPRESS, Boolean.FALSE);
    String ticket = request.getParameter("ticket");
    String id = request.getParameter("id");
    if (id == null) {
        throw new Exception("No id");
    }//from   ww w  .ja v a2s .  c  o m
    ExtensionDescriptor app = ExtensionStore.getInstance().getExtensionDescriptor(id);
    if (app == null) {
        throw new Exception("No extension with id of " + id);
    }
    Properties properties = new Properties();
    for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
        String name = (String) e.nextElement();
        String val = request.getParameter(name);
        if (name.equals("ticket") || name.equals("id") || name.equals("name")) {
            continue;
        } else {
            properties.put(name, val);
        }
    }
    processApplicationRequest(app, ticket, request, response, properties);
    return null;
}

From source file:com.xpandit.fusionplugin.pentaho.content.FusionApi.java

/**
  * Parameter adapter. We use it so we're able to run the ParameterParser class without the IParameterProvider map given by the old Content Generator.
  * @param request HTTP Request with header and request parameters.
  * @param jsonStr JSON string obtained through POST calls.
  * @return A map with the IParameterProviders "request", "headers", "path".
  *///  ww  w .j  a  v a2 s  .co  m
private Map<String, IParameterProvider> getParameterProviders(HttpServletRequest request, String jsonStr) {

    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    // Create request parameters
    SimpleParameterProvider requestParams = new SimpleParameterProvider();
    Enumeration paramKeys = request.getParameterNames();
    while (paramKeys.hasMoreElements()) {
        String key = (String) paramKeys.nextElement();
        String value = request.getParameter(key);
        requestParams.setParameter(key, value);
    }
    // If there's a JSON string it should be put together with the request parameters so it can be correctly parsed
    if (jsonStr != null) {
        requestParams.setParameter("json", jsonStr);
    }

    // Create header parameters
    SimpleParameterProvider headerParams = new SimpleParameterProvider();
    Enumeration names = request.getHeaderNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        String value = request.getHeader(name);
        headerParams.setParameter(name, value);
    }

    // Populate IParameterProvider map
    parameterProviders.put(IParameterProvider.SCOPE_REQUEST, requestParams);
    parameterProviders.put("headers", headerParams);
    parameterProviders.put("path", new SimpleParameterProvider());
    return parameterProviders;
}

From source file:com.enonic.cms.web.portal.services.ServicesProcessorBase.java

private ExtendedMap parseSimpleRequest(HttpServletRequest request) {

    ExtendedMap formItems = new ExtendedMap(true);
    Enumeration paramNames = request.getParameterNames();

    while (paramNames.hasMoreElements()) {
        String key = paramNames.nextElement().toString();
        String[] values = request.getParameterValues(key);

        if (values != null) {
            if (values.length == 1 && values[0] != null) {
                String value = values[0];
                if ("true".equals(value)) {
                    formItems.putBoolean(key, true);
                } else if ("false".equals(value)) {
                    formItems.putBoolean(key, false);
                } else {
                    formItems.putString(key, value);
                }//from  www  . j a  va 2  s .  com
            } else if (values.length > 1) {
                formItems.put(key, values);
            }
        } else {
            formItems.put(key, "");
        }
    }

    return formItems;
}

From source file:edu.mayo.xsltserver.controller.XsltServerController.java

/**
 * Simply selects the home view to render by returning its name.
 *
 * @param request the request//from   w  ww .  j a  va2 s. c  om
 * @param response the response
 * @param xmlurl the xmlurl
 * @param xmlname the xmlname
 * @param xslturl the xslturl
 * @param xsltname the xsltname
 * @param encoding the encoding
 * @throws IOException Signals that an I/O exception has occurred.
 */
@RequestMapping(value = "/transform", method = RequestMethod.GET)
@ResponseBody
public void transform(HttpServletRequest request, HttpServletResponse response,
        @RequestParam(required = false) URL xmlurl, @RequestParam(required = false) String xmlname,
        @RequestParam(required = false) URL xslturl, @RequestParam(required = false) String xsltname,
        @RequestParam(defaultValue = "application/xml") String encoding) throws IOException {

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

    @SuppressWarnings("unchecked")
    Enumeration<String> names = request.getParameterNames();

    while (names.hasMoreElements()) {
        String name = names.nextElement();
        if (name.equals("xmlurl") || name.equals("xmlname") || name.equals("xslturl") || name.equals("xsltname")
                || name.equals("encoding")) {
            continue;
        } else {
            params.put(name, request.getParameter(name));
        }
    }

    response.setContentType(encoding);

    if (xmlurl != null && StringUtils.hasText(xmlname)) {
        throw new UserInputException("You may specify a 'xslturl' param OR a 'xsltname, but not both");
    }

    if (xslturl != null && StringUtils.hasText(xsltname)) {
        throw new UserInputException("You may specify a 'xmlurl' param OR a 'xmlname, but not both");
    }

    InputStream xsltInputStream;
    if (StringUtils.hasText(xsltname)) {
        File file = fileService.getFile(xsltname);
        if (!file.exists()) {
            throw new UserInputException("The requested XSLT file: " + xsltname + " does not exist.");
        }

        xsltInputStream = new FileInputStream(file);
    } else {
        xsltInputStream = this.createInputStreamFromUrl(xslturl);
    }

    InputStream xmlInputStream;
    if (StringUtils.hasText(xmlname)) {
        File file = fileService.getFile(xmlname);
        if (!file.exists()) {
            throw new UserInputException("The requested XML file: " + xmlname + " does not exist.");
        }

        xmlInputStream = new FileInputStream(file);
    } else {
        xmlInputStream = this.createInputStreamFromUrl(xmlurl);
    }

    transformer.transform(xmlInputStream, xsltInputStream, response.getOutputStream(), params);
}

From source file:com.alibaba.citrus.service.form.impl.FormImpl.java

/**
 * requestformrequest<code>null</code>form
 *///from   www . ja  v  a2  s.  c o  m
public void init(HttpServletRequest request) {
    valid = true;

    // group
    groups.clear();

    if (request != null) {
        Set<String> ignoredGroups = createHashSet();
        boolean logStarted = false;

        // submitformkeyformKey.groupKey.instanceKey.fieldKey
        @SuppressWarnings("unchecked")
        Enumeration<String> e = request.getParameterNames();

        while (e.hasMoreElements()) {
            String key = e.nextElement();
            String[] keyInfo = parseParameterKey(key);

            // keyInfonullform service
            if (keyInfo != null && isEquals(keyInfo[0], formKey)) {
                if (!logStarted) {
                    logStarted = true;
                    log.debug("Initializing user-submitted form for validating");
                }

                String groupKey = keyInfo[1];
                String instanceKey = keyInfo[2];
                String groupInstanceKey = getGroupInstanceKey(groupKey, instanceKey);

                // requestgroup instance
                // group instance
                if (!groups.containsKey(groupInstanceKey) && !ignoredGroups.contains(groupInstanceKey)) {
                    GroupConfig groupConfig = getFormConfig().getGroupConfigByKey(groupKey);

                    if (groupConfig == null) {
                        log.debug("No group associated with parameter: {}", key);
                        continue;
                    } else if ((forcePostOnly || groupConfig.isPostOnly())
                            && !"post".equalsIgnoreCase(request.getMethod())) {
                        log.warn("Group {} can only read from POST request: {}", groupConfig.getName(), key);
                        ignoredGroups.add(groupInstanceKey);
                        setValid(false);
                        continue;
                    } else {
                        if (log.isDebugEnabled()) {
                            if (DEFAULT_GROUP_INSTANCE_KEY.equals(instanceKey)) {
                                log.debug("Initializing form group: {}", groupConfig.getName());
                            } else {
                                log.debug("Initializing form group: {}[{}]", groupConfig.getName(),
                                        instanceKey);
                            }
                        }

                        Group group = new GroupImpl(groupConfig, this, instanceKey);

                        groups.put(groupInstanceKey, group);
                        group.init(request);
                    }
                }
            }
        }
    }
}

From source file:com.jaspersoft.jasperserver.rest.services.RESTReport.java

/**
 * The get method get resources of a produced report
 * Urls in this case look like /reports/samples/myreport;uniqueidentifier?file=filename
 *//*ww  w. j  ava 2 s. com*/
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServiceException {
    // Get the uri of the resource
    String uuid = restUtils.extractRepositoryUri(req.getPathInfo());

    if (uuid.startsWith("/"))
        uuid = uuid.substring(1);

    // Add all the options...
    Map<String, String> options = new HashMap<String, String>();
    // Add as option all the GET parameters...
    Enumeration en = req.getParameterNames();
    while (en.hasMoreElements()) {
        String key = (String) en.nextElement();
        options.put(key, req.getParameter(key));
    }

    // Find the report in session...
    HttpSession session = req.getSession();
    Report report = (Report) session.getAttribute(uuid);

    if (report == null) {
        restUtils.setStatusAndBody(HttpServletResponse.SC_NOT_FOUND, resp,
                "Report not found (uuid not found in session)");
        return;
    }

    JasperPrint jp = report.getJasperPrint();

    // highcharts report for REST v1 is by default noninteractive.
    if (!options.containsKey(Argument.PARAM_INTERACTIVE)) {
        options.put(Argument.PARAM_INTERACTIVE, Boolean.FALSE.toString());
    }

    OperationResult or = runReportService.exportReport(report.getOriginalUri(), jp, options,
            report.getAttachments());

    if (or.getReturnCode() != 0) {
        restUtils.setStatusAndBody(HttpServletResponse.SC_BAD_REQUEST, resp, or.getMessage());
        return;
    } else {
        // If the jasperprint is present as attribute, it means it has been modified
        // in some way (i.e. using a RUN_TRANSFORMER_KEY).
        if (runReportService.getAttributes().get("jasperPrint") != null) {
            jp = (JasperPrint) runReportService.getAttributes().get("jasperPrint");
            report.setJasperPrint(jp);
        }

        // Send out the xml...
        resp.setContentType("text/xml; charset=UTF-8");
        restUtils.setStatusAndBody(HttpServletResponse.SC_CREATED, resp, report.toXml());
    }
}

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

/**
 * handles the case, if the user clicks on one of the buttons.
 * /* w  ww .j a v a  2s. c o m*/
 * @param myCase
 *            the my case
 * @param errors
 *            the errors
 * @param request
 *            the request
 * @param response
 *            the response
 * @return success
 * @throws Exception
 *             the exception
 */
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.POST)
public String onSubmit(final AlphaCase myCase, final BindingResult errors, final HttpServletRequest request,
        final HttpServletResponse response) throws Exception {

    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:/caseform?caseId=" + myCase.getCaseId();
}

From source file:com.alfaariss.oa.profile.aselect.binding.protocol.cgi.CGIRequest.java

/**
 * Creates the CGI request object.//ww  w  .jav  a 2  s. c o m
 * 
 * Reads the request parameters and puts them in a <code>Hashtable</code>
 * @param oRequest the servlet request 
 * @throws BindingException if the request object can't be created
 */
public CGIRequest(HttpServletRequest oRequest) throws BindingException {
    try {
        _logger = LogFactory.getLog(CGIRequest.class);
        _htRequest = new Hashtable<String, Object>();
        _sRequestedURL = oRequest.getRequestURL().toString();

        if (_logger.isDebugEnabled()) {
            String sQueryString = oRequest.getQueryString();
            if (sQueryString == null)
                sQueryString = "";
            _logger.debug("QueryString: " + sQueryString);
        }

        Hashtable<String, Vector<String>> htVectorItems = new Hashtable<String, Vector<String>>();
        Enumeration enumNames = oRequest.getParameterNames();
        while (enumNames.hasMoreElements()) {
            String sName = (String) enumNames.nextElement();
            String sValue = oRequest.getParameter(sName);
            if (sName.endsWith(CGIBinding.ENCODED_BRACES)
                    || sName.endsWith(CGIBinding.ENCODED_BRACES.toLowerCase()) || sName.endsWith("[]")) {
                Vector<String> vValues = htVectorItems.get(sName);
                if (vValues == null)
                    vValues = new Vector<String>();
                vValues.add(sValue);
                htVectorItems.put(sName, vValues);
            } else
                _htRequest.put(sName, sValue);
        }

        _htRequest.putAll(htVectorItems);
    } catch (Exception e) {
        _logger.fatal("Internal error during CGI Request creation", e);
        throw new BindingException(SystemErrors.ERROR_INTERNAL);
    }
}

From source file:org.apache.ofbiz.base.util.UtilHttp.java

public static List<Object> makeParamListWithSuffix(HttpServletRequest request,
        Map<String, ? extends Object> additionalFields, String suffix, String prefix) {
    List<Object> paramList = new ArrayList<Object>();
    Enumeration<String> parameterNames = UtilGenerics.cast(request.getParameterNames());
    while (parameterNames.hasMoreElements()) {
        String parameterName = parameterNames.nextElement();
        if (parameterName.endsWith(suffix)) {
            if (UtilValidate.isNotEmpty(prefix)) {
                if (parameterName.startsWith(prefix)) {
                    String value = request.getParameter(parameterName);
                    paramList.add(value);
                }//from w  w w .  java  2s.  c  o m
            } else {
                String value = request.getParameter(parameterName);
                paramList.add(value);
            }
        }
    }
    if (additionalFields != null) {
        for (Map.Entry<String, ? extends Object> entry : additionalFields.entrySet()) {
            String fieldName = entry.getKey();
            if (fieldName.endsWith(suffix)) {
                if (UtilValidate.isNotEmpty(prefix)) {
                    if (fieldName.startsWith(prefix)) {
                        paramList.add(entry.getValue());
                    }
                } else {
                    paramList.add(entry.getValue());
                }
            }
        }
    }
    return paramList;
}