Example usage for javax.servlet.http HttpServletRequest getParameterValues

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

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getParameterValues.

Prototype

public String[] getParameterValues(String name);

Source Link

Document

Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.

Usage

From source file:fr.paris.lutece.plugins.workflow.modules.editrecord.service.TaskEditRecord.java

/**
 * {@inheritDoc}// ww  w.jav a2 s .  c  om
 */
@Override
public void processTask(int nIdResourceHistory, HttpServletRequest request, Locale locale) {
    String strMessage = request
            .getParameter(EditRecordConstants.PARAMETER_MESSAGE + EditRecordConstants.UNDERSCORE + getId());
    String[] listIdsEntry = request.getParameterValues(
            EditRecordConstants.PARAMETER_IDS_ENTRY + EditRecordConstants.UNDERSCORE + getId());

    boolean bCreate = false;
    List<EditRecordValue> listEditRecordValues = new ArrayList<EditRecordValue>();

    EditRecord editRecord = _editRecordService.find(nIdResourceHistory, getId());

    if (editRecord == null) {
        editRecord = new EditRecord();
        editRecord.setIdHistory(nIdResourceHistory);
        editRecord.setIdTask(getId());
        bCreate = true;
    }

    if (listIdsEntry != null) {
        for (String strIdEntry : listIdsEntry) {
            if (StringUtils.isNotBlank(strIdEntry) && StringUtils.isNumeric(strIdEntry)) {
                int nIdEntry = Integer.parseInt(strIdEntry);
                EditRecordValue editRecordValue = new EditRecordValue();
                editRecordValue.setIdEntry(nIdEntry);

                listEditRecordValues.add(editRecordValue);
            }
        }
    }

    editRecord.setMessage(StringUtils.isNotBlank(strMessage) ? strMessage : StringUtils.EMPTY);
    editRecord.setListEditRecordValues(listEditRecordValues);
    editRecord.setIsComplete(false);

    if (bCreate) {
        _editRecordService.create(editRecord);
    } else {
        _editRecordService.update(editRecord);
    }
}

From source file:org.surfnet.oaaas.consent.FormUserConsentHandler.java

private boolean processForm(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {
    if (Boolean.valueOf(request.getParameter(USER_OAUTH_APPROVAL))) {
        setAuthStateValue(request, request.getParameter(AUTH_STATE));
        String[] scopes = request.getParameterValues(GRANTED_SCOPES);
        setGrantedScopes(request, scopes);
        return true;
    } else {//ww  w  .  j a  v a2  s .com
        request.getRequestDispatcher(getUserConsentDeniedUrl()).forward(request, response);
        return false;
    }
}

From source file:com.shenit.commons.utils.HttpUtils.java

/**
 * ??SessionCookie?//  ww  w  . j  a  va  2  s.  c om
 * 
 * @param name
 *            ??
 * @param defaultVal
 *            
 * @param req
 * @return
 */
public static Object getValue(String name, Object defaultVal, HttpServletRequest req) {
    // get from request first
    Object value = collapseValue(req.getParameterValues(name));
    if (value != null)
        return value;
    // get from session
    value = getSessionAttribute(name, null, req);
    if (value != null)
        return value;
    value = getCookieValue(name, null, req);
    if (value != null)
        return value;
    // nothing found
    return defaultVal;
}

From source file:org.esgf.globusonline.GOFormView1Controller.java

@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.POST)
public ModelAndView doPost(final HttpServletRequest request) {

    //grab the dataset name, file names and urls from the query string
    String dataset_name = request.getParameter("id");
    String[] file_names = request.getParameterValues("child_id");
    String[] file_urls = request.getParameterValues("child_url");

    Map<String, Object> model = new HashMap<String, Object>();

    String myproxyServerStr = null;

    try {//from   ww  w  .  ja  va 2s .c o m
        //get the openid here from the cookie
        Cookie[] cookies = request.getCookies();
        String openId = "";
        for (int i = 0; i < cookies.length; i++) {
            if (cookies[i].getName().equals("esgf.idp.cookie")) {
                openId = cookies[i].getValue();
            }
        }

        LOG.debug("Got User OpenID: " + openId);
        myproxyServerStr = Utils.resolveMyProxyViaOpenID(openId);
        LOG.debug("Using MyProxy Server: " + myproxyServerStr);

        ESGFProperties esgfProperties = new ESGFProperties();
        UserInfoDAO uid = new UserInfoDAO(esgfProperties);
        UserInfo userInfo = uid.getUserByOpenid(openId);
        String myproxyUserName = userInfo.getUserName();

        LOG.debug("Got MyProxy Username: " + myproxyUserName);
        //System.out.println("Got MyProxy Username: " + myproxyUserName);

        if (request.getParameter(GOFORMVIEW_MODEL) != null) {
            //it should never come here...
        } else {
            //place the dataset name, file names and urls into the model
            model.put(GOFORMVIEW_MYPROXY_SERVER, myproxyServerStr);
            model.put(GOFORMVIEW_SRC_MYPROXY_USER, myproxyUserName);
            model.put(GOFORMVIEW_FILE_URLS, file_urls);
            model.put(GOFORMVIEW_FILE_NAMES, file_names);
            model.put(GOFORMVIEW_DATASET_NAME, dataset_name);
        }
    } catch (YadisException ye) {
        String eMsg = ye.toString();
        if (eMsg.indexOf("0x702") != -1) {
            model.put(GOFORMVIEW_ERROR, "error");
            model.put(GOFORMVIEW_ERROR_MSG,
                    "Please <a href=\"login\">Login</a>" + " before trying to download data!");
        } else {
            String errorMsg = "Failed to resolve OpenID: " + ye;
            LOG.error("Failed to resolve OpenID: " + ye);
            model.put(GOFORMVIEW_ERROR, "error");
            model.put(GOFORMVIEW_ERROR_MSG, errorMsg + "<br><br>Please make sure that you're"
                    + " logged in as a valid user before trying to download data!<br><br>");
        }
    } catch (Exception e) {
        String errorMsg = "Failed to resolve OpenID: " + e;
        LOG.error("Failed to resolve OpenID: " + e);
        model.put(GOFORMVIEW_ERROR, "error");
        model.put(GOFORMVIEW_ERROR_MSG, errorMsg + "<br><br>Please make sure that you're"
                + " logged in as a valid user before trying to download data!<br><br>");
    }
    return new ModelAndView("goformview1", model);
}

From source file:org.openmrs.web.controller.concept.ConceptDatatypeListController.java

/**
 * The onSubmit function receives the form/command object that was modified by the input form
 * and saves it to the db/*from   w  w w  . j  a  v a 2s .  co  m*/
 *
 * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object,
 *      org.springframework.validation.BindException)
 */
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj,
        BindException errors) throws Exception {

    HttpSession httpSession = request.getSession();

    String view = getFormView();
    if (Context.isAuthenticated()) {

        String[] cdList = request.getParameterValues("conceptDatatypeId");
        ConceptService cs = Context.getConceptService();

        StringBuilder success = new StringBuilder("");
        StringBuilder error = new StringBuilder();

        MessageSourceAccessor msa = getMessageSourceAccessor();
        String deleted = msa.getMessage("general.deleted");
        String notDeleted = msa.getMessage("general.cannot.delete");
        if (cdList.length != 0) {
            log.warn("Deleting concept datatype is not supported");
            if (!"".equals(error.toString())) {
                error.append("<br/>");
            }
            error.append("ConceptDatatype").append(" ").append(notDeleted);
        }

        view = getSuccessView();
        if (!"".equals(success.toString())) {
            httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, success.toString());
        }
        if (!"".equals(error.toString())) {
            httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, error.toString());
        }
    }

    return new ModelAndView(new RedirectView(view));
}

From source file:com.dianping.lion.api.http.TakeEffectConfigsServlet.java

@Override
protected void doService(HttpServletRequest req, HttpServletResponse resp, String querystr) throws Exception {
    String projectName = getNotBlankParameter(req, PARAM_PROJECT);
    String env = getNotBlankParameter(req, PARAM_ENV);
    String task = req.getParameter(PARAM_TASK);
    String[] keys = req.getParameterValues(PARAM_KEY);
    String push2App = req.getParameter(PARAM_PUSH);
    String snapshot = req.getParameter(PARAM_SNAPSHOT);
    String setTask = req.getParameter("set");
    push2App = push2App != null ? push2App : "0";
    boolean createSnapshot = snapshot != null ? CREATE_SNAPSHOT.equals(snapshot.trim()) : false;
    boolean executeSetTask = !(setTask != null && "0".equals(setTask.trim()));

    Environment environment = getRequiredEnv(env);

    if (keys != null && keys.length > 0) {
        Project project = getRequiredProject(projectName);

        checkConfigKeys(projectName, keys);
        String logcontent = "task: " + task + ", key: " + StringUtils.join(keys, ',');
        try {//from  w  w w. ja v  a 2  s. c  om
            int snapshotId = -1;
            if (createSnapshot) {
                snapshotId = configReleaseService.createSnapshotSet(project.getId(), environment.getId(),
                        task != null ? task : "");
            }

            if (executeSetTask) {
                String[] features = getRequiredParameters(req, PARAM_FEATURE);
                configReleaseService.executeSetTask(project.getId(), environment.getId(), features, keys,
                        PUSH_TO_APP.equals(push2App));
            }

            resp.getWriter().write(SUCCESS_CODE + snapshotId);
            operationLogService.createOpLog(new OperationLog(OperationTypeEnum.API_TakeEffect, project.getId(),
                    environment.getId(), "?: " + logcontent).key(StringUtils.join(keys, ','), "true", null,
                            null, querystr));
        } catch (Exception e) {
            operationLogService.createOpLog(new OperationLog(OperationTypeEnum.API_TakeEffect, project.getId(),
                    environment.getId(), ": " + logcontent).key(StringUtils.join(keys, ','), "false",
                            null, null, querystr, ThrowableUtils.extractStackTrace(e, 30000)));
            throw e;
        }
    } else {
        resp.getWriter().write(SUCCESS_CODE);
    }

}

From source file:org.openmrs.module.dataintegrityworkflow.web.controller.ManageIntegrityRecordsFormController.java

protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
        BindException errors) throws Exception {
    String action = request.getParameter("operation");
    int checkId = Integer.parseInt(request.getParameter("checkId"));
    String[] recordIdList = request.getParameterValues("recordId");
    DataIntegrityWorkflowService integrityWorkflowService = getDataIntegrityWorkflowService();
    IntegrityCheck integrityCheck = integrityWorkflowService.getIntegrityCheck(checkId);
    if ("assign".equals(action)) {
        String user = request.getParameter("assigneeId");
        String assignmentType = request.getParameter("assignmentOptions");
        if ("all".equals(assignmentType)) {
            int i = 0;
            recordIdList = new String[integrityCheck.getIntegrityCheckResults().size()];
            for (IntegrityCheckResult integrityCheckResult : integrityCheck.getIntegrityCheckResults()) {
                recordIdList[i] = integrityCheckResult.getIntegrityCheckResultId().toString();
                i++;// ww w .ja  v a2  s . com
            }
        }
        integrityWorkflowService.createWorkflowRecordsIfNotExists(recordIdList, checkId);
        integrityWorkflowService.assignRecords(recordIdList, checkId, user);
    }

    if ("Unassign".equals(action)) {
        String removeAssignmentType = request.getParameter("removeOptions");
        /*if("all".equals(removeAssignmentType)) {
        int i=0;
        recordIdList=new String[integrityCheck.getIntegrityCheckResults().size()];
        for(IntegrityCheckResult integrityCheckResult:integrityCheck.getIntegrityCheckResults())
        {
            recordIdList[i]=integrityCheckResult.getIntegrityCheckResultId().toString();
            i++;
        }
        }*/
        integrityWorkflowService.removeRecordsAssignees(recordIdList, checkId);
    }
    return new ModelAndView(new RedirectView(getSuccessView() + "?filter=all&checkId=" + checkId));
}

From source file:com.dianping.lion.api.http.RollbackConfigsServlet.java

@Override
protected void doService(HttpServletRequest req, HttpServletResponse resp, String querystr) throws Exception {
    String projectName = getNotBlankParameter(req, PARAM_PROJECT);
    String env = getNotBlankParameter(req, PARAM_ENV);
    String task = getNotBlankParameter(req, PARAM_TASK);
    String[] keys = req.getParameterValues(PARAM_KEY);

    Environment environment = getRequiredEnv(env);
    Project project = projectService.findProject(projectName);

    boolean hasRollbacked = false;
    String keysNotRemoved = "";

    if (project != null) {
        String logcontent = "task: " + task;
        try {/*from  ww w .j a v  a2 s  .com*/
            ConfigSnapshotSet snapshotSet = configReleaseService.findSnapshotSetToRollback(project.getId(),
                    environment.getId(), task);

            if (snapshotSet != null) {
                ConfigRollbackResult rollbackResult = configReleaseService.rollbackSnapshotSet(snapshotSet,
                        keys);
                Set<String> notRemovedKeys = rollbackResult.getNotRemovedKeys();
                if (CollectionUtils.isNotEmpty(notRemovedKeys)) {
                    keysNotRemoved = StringUtils.join(notRemovedKeys, ",") + " not removed.";
                }
                hasRollbacked = true;
                operationLogService
                        .createOpLog(
                                new OperationLog(OperationTypeEnum.API_Rollback, project.getId(),
                                        environment.getId(),
                                        "?: " + logcontent
                                                + (!notRemovedKeys.isEmpty() ? ", key: "
                                                        + StringUtils.join(notRemovedKeys, ",") : "")).key(null,
                                                                "true", null, null, querystr));
            } else {
                operationLogService
                        .createOpLog(new OperationLog(OperationTypeEnum.API_Rollback, project.getId(),
                                environment.getId(), "?: " + logcontent + ", ??")
                                        .key(null, "true", null, null, querystr));
            }
        } catch (Exception e) {
            operationLogService.createOpLog(new OperationLog(OperationTypeEnum.API_Rollback, project.getId(),
                    environment.getId(), ": " + logcontent).key(null, "false", null, null, querystr,
                            ThrowableUtils.extractStackTrace(e, 30000)));
            throw e;
        }
    }
    resp.getWriter().print(SUCCESS_CODE + (hasRollbacked ? "1|" + keysNotRemoved : "0"));
}

From source file:com.redhat.rhn.frontend.action.systems.monitoring.ProbeGraphAction.java

/** {@inheritDoc} */
public ActionForward execute(ActionMapping mapping, ActionForm formIn, HttpServletRequest req,
        HttpServletResponse resp) throws Exception {

    RequestContext rctx = new RequestContext(req);
    Probe probe = rctx.lookupProbe();/*from ww w  .  ja  va  2 s . c om*/
    String[] metrics = req.getParameterValues(METRICS);

    Long start = rctx.getParamAsLong(STARTTS);
    Long end = rctx.getParamAsLong(ENDTS);

    if (start == null || end == null) {
        log.debug("No start or end date passed into execute()");
        return null;
    }

    Timestamp startts = new Timestamp(start.longValue());
    Timestamp endts = new Timestamp(end.longValue());

    List tsdList = MonitoringManager.getInstance().getProbeDataList(probe, metrics, startts, endts);

    if (rctx.isRequestedExport()) {
        writeExport(tsdList, resp, metrics, rctx.getCurrentUser().getCsvSeparator());
    } else {
        writeGraph(tsdList, resp, req, metrics, startts, endts);
    }
    return null;
}

From source file:de.appsolve.padelcampus.admin.controller.bookings.AdminBookingsVoucherController.java

@RequestMapping(value = { "send" }, method = POST)
public ModelAndView postSendView(@ModelAttribute("Model") Voucher model, HttpServletRequest request,
        BindingResult result) {// w  w w . jav a 2 s  . c o  m
    validator.validate(model, result);
    String[] eventIds = request.getParameterValues("events");
    if (eventIds == null) {
        result.addError(new ObjectError("events", msg.get("NotEmpty.events")));
        return getSendView(model);
    }
    if (!result.hasErrors()) {
        for (String eventId : eventIds) {
            Long id = Long.parseLong(eventId);
            Event event = eventDAO.findByIdFetchWithParticipantsAndPlayers(id);

            Map<Player, List<Game>> playerGameMap = new HashMap<>();

            List<Game> eventGames = gameDAO.findByEvent(event);

            for (Game game : eventGames) {
                Voucher voucher = VoucherUtil.createNewVoucher(model);
                voucher.setComment(event.getName());
                voucher.setGame(game);
                voucherDAO.saveOrUpdate(voucher);

                game.setVoucherUUID(voucher.getUUID());
                gameDAO.saveOrUpdate(game);

                Set<Participant> participants = game.getParticipants();
                for (Participant participant : participants) {
                    if (participant instanceof Team) {
                        Team team = (Team) participant;
                        Set<Player> players = team.getPlayers();
                        for (Player player : players) {
                            addGame(playerGameMap, player, game);
                        }
                    } else if (participant instanceof Player) {
                        Player player = (Player) participant;
                        addGame(playerGameMap, player, game);
                    }
                }
            }

            for (Entry<Player, List<Game>> entry : playerGameMap.entrySet()) {
                Player player = entry.getKey();
                List<Game> games = entry.getValue();

                StringBuilder sb = new StringBuilder();
                sb.append(msg.get("NewVoucherListEmailBodyStart",
                        new Object[] { player.toString(), event.toString() }));
                for (Game game : games) {
                    sb.append(game);
                    sb.append(": ");
                    sb.append(game.getVoucherUUID());
                    sb.append("\n");
                }
                sb.append("\n\n");
                sb.append(msg.get("NewVoucherListEmailBodyEnd",
                        new Object[] { RequestUtil.getBaseURL(request) }));

                Mail mail = new Mail();
                mail.addRecipient(player);
                mail.setSubject(event.getName());
                mail.setBody(sb.toString());
                try {
                    mailUtils.send(mail, request);
                } catch (MailException | IOException ex) {
                    LOG.error("Error while sending voucher list to " + player.getEmail(), ex);
                }
            }
        }
    }
    return redirectToIndex(request);
}