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:org.opengeoportal.proxy.controllers.DynamicOgcController.java

@RequestMapping(value = "/wms", method = RequestMethod.GET)
public void doWmsRequest(@RequestParam("ogpids") Set<String> layerIds, HttpServletRequest servletRequest,
        HttpServletResponse servletResponse) throws Exception {
    Enumeration paramNames = servletRequest.getParameterNames();
    String ogcRequest = "";
    String layers = "";
    while (paramNames.hasMoreElements()) {
        String param = (String) paramNames.nextElement();
        if (param.equalsIgnoreCase("version")) {

        } else if (param.equalsIgnoreCase("request")) {
            logger.info("request: " + servletRequest.getParameter(param));
            ogcRequest = servletRequest.getParameter(param);
        } else if (param.equalsIgnoreCase("layers")) {
            layers = servletRequest.getParameter(param);
        }/*from w  w w.jav a 2 s .c  o  m*/
    }

    if (ogcRequest.equalsIgnoreCase("getfeatureinfo") || ogcRequest.equalsIgnoreCase("describelayer")
            || ogcRequest.equalsIgnoreCase("getmap")) {
        //TODO: strip all the params and rebuild the request with only sanctioned parameters, in case of fussy servers
        String remoteUrl = getOgcUrlFromLayerName(layers, "wms");
        String newQuery = removeParamFromQuery(servletRequest.getQueryString(), "ogpids");
        if (ogcRequest.equalsIgnoreCase("describelayer")) {
            newQuery = removeParamFromQuery(newQuery, "srsname");
        }
        remoteUrl += "?" + newQuery;
        logger.info("remote url:" + remoteUrl);
        doProxy(remoteUrl, servletRequest, servletResponse);
    }

}

From source file:br.mdarte.exemplo.academico.accessControl.Login.java

private ActionForward _verificarPermissao(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    final String value = String.valueOf(LoginControllerFactory.getLoginControllerInstance()
            .verificarPermissao(mapping, request, response, servlet));

    if (value.equals("true")) {
        return particularExecute(mapping, form, request, response);
    } else {/*from  ww w  . j  av  a2  s .c o m*/
        ActionForward forward = mapping.findForward("entrar.login");

        if (__urlCasoDeUso != null && __contexto != null) {
            Enumeration nomeParametros = request.getParameterNames();
            StringBuffer parametros = new StringBuffer("");
            if (nomeParametros.hasMoreElements()) {
                parametros.append("?");
                while (nomeParametros.hasMoreElements()) {
                    String nome = nomeParametros.nextElement().toString();
                    parametros.append(nome + "=" + request.getParameter(nome));
                    if (nomeParametros.hasMoreElements()) {
                        parametros.append("@AND@");
                    }
                }
            }
            org.apache.struts.action.ActionRedirect redirect = new org.apache.struts.action.ActionRedirect(
                    forward);
            redirect.addParameter("nextPath", __contexto + __urlCasoDeUso + parametros.toString());
            forward = redirect;
        }
        return forward;
    }
}

From source file:org.opengeoportal.proxy.controllers.DynamicOgcController.java

@RequestMapping(value = "/wfs", method = RequestMethod.GET)
public void doWfsRequest(@RequestParam("ogpids") Set<String> layerIds, HttpServletRequest servletRequest,
        HttpServletResponse servletResponse) throws Exception {
    Enumeration paramNames = servletRequest.getParameterNames();
    String ogcRequest = "";
    String typeName = "";
    while (paramNames.hasMoreElements()) {
        String param = (String) paramNames.nextElement();
        if (param.equalsIgnoreCase("version")) {

        } else if (param.equalsIgnoreCase("request")) {
            logger.info("request: " + servletRequest.getParameter(param));
            ogcRequest = servletRequest.getParameter(param);
        } else if (param.equalsIgnoreCase("typename")) {
            typeName = servletRequest.getParameter(param);
        }//from  w w  w  . j a v a2s .c  o m
    }

    if (ogcRequest.equalsIgnoreCase("describefeaturetype") || ogcRequest.equalsIgnoreCase("getfeature")) {
        //TODO: strip all the params and rebuild the request with only sanctioned parameters, in case of fussy servers
        String remoteUrl = getOgcUrlFromLayerName(typeName, "wfs");
        String newQuery = removeParamFromQuery(servletRequest.getQueryString(), "ogpids");
        if (ogcRequest.equalsIgnoreCase("describefeaturetype")) {
            newQuery = removeParamFromQuery(newQuery, "srsname");
        }
        remoteUrl += "?" + newQuery;
        logger.info("remote url:" + remoteUrl);
        doProxy(remoteUrl, servletRequest, servletResponse);
    } else if (ogcRequest.equalsIgnoreCase("getcapabilities")) {
        //forward to handleGetCapabilities
    } else {
        throw new Exception("Unrecognized request type.");
    }

}

From source file:com.swiftcorp.portal.generalprofile.web.GeneralprofileDispatchAction.java

public ActionForward modifyGeneralprofile(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws SystemException, BusinessRuleViolationException, Exception {
    log.info("modifyGeneralprofile() : Enter");
    DynaValidatorActionForm generalprofileForm = (DynaValidatorActionForm) form;
    Long componentId = WebUtils.getComponentId(request);
    log.info("promptModifyGeneralprofile() : componentId = " + componentId);
    GeneralprofileDTO generalprofileDTO = (GeneralprofileDTO) generalprofileService.get(componentId);
    DTOObjectReflectionUtil.populateDTOFromRequest(request, generalprofileDTO);
    Enumeration<String> en = request.getParameterNames();

    String key = "";
    String value = "";
    String supplyChainActor = "";
    while (en.hasMoreElements()) {
        key = en.nextElement();/*from   w  w  w. j a v a  2 s  .co m*/
        if (key.startsWith("cb-")) {
            int index = -1;
            value = key.substring(3, key.length());
            if (supplyChainActor != null && !supplyChainActor.equals("null") && supplyChainActor.length() > 0) {
                supplyChainActor += "," + value;
            } else {
                supplyChainActor += value;
            }
            log.debug("functionIndex are " + value);

        }
    }
    generalprofileDTO.setSupplyChainActor(supplyChainActor);
    String[][] messageArgValues = { { generalprofileDTO.getUniqueCode() } };
    generalprofileService.modify(generalprofileDTO);
    WebUtils.setSuccessMessages(request, MessageKeys.MODIFY_SUCCESS_MESSAGE_KEYS, messageArgValues);
    log.info("modifyGeneralprofile() : Exit");
    return promptSuccessAddGeneralprofile(mapping, form, request, response);
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceController.java

/**
 * @param request/*from  w  w  w. j  av a  2 s  .  c o m*/
 * @param response
 * @return
 * @throws ResponseException
 */
@SuppressWarnings("rawtypes")
@RequestMapping(value = "/{resource}", method = RequestMethod.GET)
@ResponseBody
public SimpleObject get(@PathVariable("resource") String resource, HttpServletRequest request,
        HttpServletResponse response) throws ResponseException {
    baseUriSetup.setup(request);
    Object res = restService.getResourceByName(buildResourceName(resource));
    Converter conv = res instanceof Converter ? (Converter) res : null;

    RequestContext context = RestUtil.getRequestContext(request, response, Representation.REF);

    @SuppressWarnings("unchecked")
    SearchHandler searchHandler = restService.getSearchHandler(buildResourceName(resource),
            request.getParameterMap());
    if (searchHandler != null) {
        return searchHandler.search(context).toSimpleObject(conv);
    }

    Enumeration parameters = request.getParameterNames();
    while (parameters.hasMoreElements()) {
        if (!RestConstants.SPECIAL_REQUEST_PARAMETERS.contains(parameters.nextElement())) {
            if (res instanceof Searchable) {
                return ((Searchable) res).search(context);
            } else {
                throw new ResourceDoesNotSupportOperationException(
                        res.getClass().getSimpleName() + " is not searchable");
            }
        }
    }

    if (res instanceof Listable) {
        return ((Listable) res).getAll(context);
    } else {
        throw new ResourceDoesNotSupportOperationException(res.getClass().getSimpleName() + " is not listable");
    }
}

From source file:de.fhg.fokus.openride.services.driver.offer.OfferService.java

@POST
@Produces("text/json")
@Consumes("*/*")//  ww  w .  j  a va2 s .  c o m
public Response postOffer(@Context HttpServletRequest con, @PathParam("username") String username,
        String json) {
    System.out.println("postOffer start");
    // get the parameter containing the request-information.

    Enumeration ee = con.getParameterNames();
    System.out.println("Elements");
    while (ee.hasMoreElements()) {
        System.out.println("Element: " + ee.nextElement());
    }

    //String json = (String)con.getParameter("json");
    System.out.println("json: " + json);
    if (json != null) {
        // to use this method client must send json content!
        // build a List of Objects that shall be available in the JSON context.
        ArrayList startlist = new ArrayList();
        startlist.add(new Offer());
        startlist.add(new PostOfferResponse());

        XStream x = Utils.getJasonXStreamer(startlist);

        Offer r = (Offer) x.fromXML(json);
        // do something with tht information

        // Add the new ride to DB!
        CustomerEntity e = customerControllerBean.getCustomerByNickname(username);

        //RoutePoint[] routepoints = routerBean.getEquiDistantRoutePoints(new Coordinate[]{new Coordinate(r.getRidestartPtLat(), r.getRidestartPtLon()), new Coordinate(r.getRideendPtLat(), r.getRideendPtLon())}, new Timestamp(r.getRidestartTime()), Constants.ROUTE_FASTEST_PATH_DEFAULT, Constants.ROUTER_NEAREST_NEIGHBOR_THRESHOLD, Constants.MATCHING_MAX_ROUTE_POINT_DISTANCE);

        // FIXME: What shall these parameters contain? Extend the Object!

        //System.out.println("routpoints: " + routepoints);
        int rideId = -1;
        System.out.println("startaddr: " + r.getStartptAddress() + " endptAddr: " + r.getEndptAddress());
        if ((rideId = driverUndertakesRideControllerBean.addRide(e.getCustId(),
                new Point(r.getRidestartPtLon(), r.getRidestartPtLat()),
                new Point(r.getRideendPtLon(), r.getRideendPtLat()), r.getIntermediatePoints(), //Point[] intermediate route points
                new Date(r.getRidestartTime()), StringEscapeUtils.unescapeHtml(r.getRideComment()),
                r.getAcceptableDetourInMin(), r.getAcceptableDetourInKm(), r.getAcceptableDetourInPercent(),
                r.getOfferedSeatsNo(), StringEscapeUtils.unescapeHtml(r.getOfferedCurrency()),
                StringEscapeUtils.unescapeHtml(r.getStartptAddress()),
                StringEscapeUtils.unescapeHtml(r.getEndptAddress()))) == -1) {
            return Response.status(Response.Status.BAD_REQUEST).build();
        } else {

            Response response = Response.ok(x.toXML(new PostOfferResponse(rideId))).build();

            return response;
        }
        // in this case no special response-information is needed.
    } else {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
}

From source file:br.mdarte.exemplo.academico.accessControl.Login.java

/**
 * /*  w w  w. ja  va  2s.  co  m*/
 */
private ActionForward __verificarLogin(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    final String value = String.valueOf(LoginControllerFactory.getLoginControllerInstance()
            .verificarLogin(mapping, (LoginFormImpl) form, request, response, servlet));

    if (value.equals("false")) {
        request.getSession().removeAttribute(Constantes.FORWARD);

        ActionForward forward = mapping.findForward("entrar.login");

        if (__urlCasoDeUso != null && __contexto != null) {
            Enumeration nomeParametros = request.getParameterNames();
            StringBuffer parametros = new StringBuffer("");
            if (nomeParametros.hasMoreElements()) {
                parametros.append("?");
                while (nomeParametros.hasMoreElements()) {
                    String nome = nomeParametros.nextElement().toString();
                    parametros.append(nome + "=" + request.getParameter(nome));
                    if (nomeParametros.hasMoreElements()) {
                        parametros.append("@AND@");
                    }
                }
            }
            org.apache.struts.action.ActionRedirect redirect = new org.apache.struts.action.ActionRedirect(
                    forward);
            redirect.addParameter("nextPath", __contexto + __urlCasoDeUso + parametros.toString());
            forward = redirect;
        }
        return forward;
    }
    if (value.equals("true")) {
        return _verificaTrocaDeSenha(mapping, form, request, response);
    }

    // we take the last action in case we have an invalid return value from the controller
    return _verificaTrocaDeSenha(mapping, form, request, response);
}

From source file:org.fcrepo.localservices.saxon.SaxonServlet.java

/**
 * Apply stylesheet to source document/*from  w  w w .j a  v  a 2s  .  co  m*/
 */
private void apply(String style, String source, HttpServletRequest req, HttpServletResponse res)
        throws Exception {

    // Validate parameters
    if (style == null) {
        throw new TransformerException("No style parameter supplied");
    }
    if (source == null) {
        throw new TransformerException("No source parameter supplied");
    }

    InputStream sourceStream = null;
    try {
        // Load the stylesheet (adding to cache if necessary)
        Templates pss = tryCache(style);
        Transformer transformer = pss.newTransformer();

        Enumeration<?> p = req.getParameterNames();
        while (p.hasMoreElements()) {
            String name = (String) p.nextElement();
            if (!(name.equals("style") || name.equals("source"))) {
                String value = req.getParameter(name);
                transformer.setParameter(name, new StringValue(value));
            }
        }

        // Start loading the document to be transformed
        sourceStream = getInputStream(source);

        // Set the appropriate output mime type
        String mime = pss.getOutputProperties().getProperty(OutputKeys.MEDIA_TYPE);
        if (mime == null) {
            res.setContentType("text/html");
        } else {
            res.setContentType(mime);
        }

        // Transform
        StreamSource ss = new StreamSource(sourceStream);
        ss.setSystemId(source);
        transformer.transform(ss, new StreamResult(res.getOutputStream()));

    } finally {
        if (sourceStream != null) {
            try {
                sourceStream.close();
            } catch (Exception e) {
            }
        }
    }

}

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

/**
 * Create a map from a HttpServletRequest (parameters) object
 * @param onlyIncludeOrSkip If true only include, if false skip, the named parameters in the nameSet. If this is null and nameSet is not null, default to skip.
 * @return The resulting Map//from w  w w  . j  a v  a 2 s  .  com
 */
public static Map<String, Object> getParameterMap(HttpServletRequest request, Set<? extends String> nameSet,
        Boolean onlyIncludeOrSkip) {
    boolean onlyIncludeOrSkipPrim = onlyIncludeOrSkip == null ? true : onlyIncludeOrSkip.booleanValue();
    Map<String, Object> paramMap = new HashMap<String, Object>();

    // add all the actual HTTP request parameters
    Enumeration<String> e = UtilGenerics.cast(request.getParameterNames());
    while (e.hasMoreElements()) {
        String name = e.nextElement();
        if (nameSet != null && (onlyIncludeOrSkipPrim ^ nameSet.contains(name))) {
            continue;
        }

        Object value = null;
        String[] paramArr = request.getParameterValues(name);
        if (paramArr != null) {
            if (paramArr.length > 1) {
                value = Arrays.asList(paramArr);
            } else {
                value = paramArr[0];
                // does the same thing basically, nothing better about it as far as I can see: value = request.getParameter(name);
            }
        }
        paramMap.put(name, value);
    }

    paramMap.putAll(getPathInfoOnlyParameterMap(request, nameSet, onlyIncludeOrSkip));

    if (paramMap.size() == 0) {
        // nothing found in the parameters; maybe we read the stream instead
        Map<String, Object> multiPartMap = UtilGenerics.checkMap(request.getAttribute("multiPartMap"));
        if (UtilValidate.isNotEmpty(multiPartMap)) {
            paramMap.putAll(multiPartMap);
        }
    }

    if (Debug.verboseOn()) {
        Debug.logVerbose("Made Request Parameter Map with [" + paramMap.size() + "] Entries", module);
        Debug.logVerbose("Request Parameter Map Entries: " + System.getProperty("line.separator")
                + UtilMisc.printMap(paramMap), module);
    }

    return canonicalizeParameterMap(paramMap);
}

From source file:com.glaf.core.tag.InfoPageTag.java

public int doEndTag() throws JspException {
    Paging page = null;/*from  w w  w . j ava2s. co m*/
    if (name == null) {
        name = "glaf";
    }
    page = (Paging) pageContext.getAttribute(name);
    if (page == null) {
        page = (Paging) pageContext.getRequest().getAttribute(name);
    }
    if (page == null) {
        page = Paging.EMPTY_PAGE;
    }

    if (prefix == null) {
        prefix = "";
    }

    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

    String complexQuery = request.getParameter("complexQuery");
    String x_complex_query = request.getParameter("x_complex_query");
    String xyz_complex_query = request.getParameter("xyz_complex_query");

    imagePath = request.getContextPath() + "/images";

    Map<String, Object> paramMap = new java.util.HashMap<String, Object>();
    StringBuffer buffer = new StringBuffer();

    Enumeration<?> enumeration = request.getParameterNames();
    while (enumeration.hasMoreElements()) {
        String paramName = (String) enumeration.nextElement();
        String paramValue = request.getParameter(paramName);
        if (paramName.startsWith(prefix)) {
            paramName = paramName.replaceAll(prefix, "");
        }
        if (paramName.startsWith("query_")) {
            if (StringUtils.isNotEmpty(paramValue)) {
                paramName = paramName.replaceAll("query_", "");
                paramMap.put(paramName, paramValue);
            }
        }
    }

    Integer count = (Integer) pageContext.getRequest().getAttribute(prefix + PAGE_PART_COUNTER);
    if (count == null) {
        count = 0;
    }
    try {
        JspWriter out = pageContext.getOut();
        page.setPrefix(prefix);
        if (StringUtils.isNotEmpty(form)) {
            String suffix = "_part_" + count.intValue();
            count = count.intValue() + 1;
            if (count.intValue() == 1) {
                if (paramMap.size() > 0) {
                    String queryString = JsonUtils.encode(paramMap);
                    if (LogUtils.isDebug()) {
                        logger.debug("query string:" + queryString);
                    }
                    queryString = RequestUtils.encodeString(queryString);
                    buffer.append(
                            "\n<input type=\"hidden\" id=\"x_complex_query\" name=\"x_complex_query\" value=\"")
                            .append(queryString).append("\">");
                }
                if (StringUtils.isNotEmpty(xyz_complex_query)) {
                    buffer.append(
                            "\n<input type=\"hidden\" id=\"xyz_complex_query\" name=\"xyz_complex_query\" value=\"")
                            .append(xyz_complex_query).append("\">");
                } else {
                    if (StringUtils.isNotEmpty(x_complex_query)) {
                        buffer.append(
                                "\n<input type=\"hidden\" id=\"xyz_complex_query\" name=\"xyz_complex_query\" value=\"")
                                .append(x_complex_query).append("\">");
                    }
                }
                if (StringUtils.isNotEmpty(complexQuery)) {
                    buffer.append("\n<input type=\"hidden\" id=\"complexQuery\" name=\"complexQuery\" value=\"")
                            .append(complexQuery).append("\">");
                }
                out.println(this.getDefaultHiddenField(page.getCurrentPage()));
                out.println(buffer.toString());
            }
            pageContext.getRequest().setAttribute(prefix + PAGE_PART_COUNTER, count);
            boolean showCount = true;
            if (StringUtils.equals(display, "0")) {
                showCount = false;
            }
            String content = this.getPagingScript(page, form, suffix, showCount);
            out.println(content);
        }

    } catch (Exception ex) {
        ex.printStackTrace();
        logger.error(ex);
    }
    return EVAL_PAGE;
}