Example usage for javax.servlet.http HttpServletRequest getParameter

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

Introduction

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

Prototype

public String getParameter(String name);

Source Link

Document

Returns the value of a request parameter as a String, or null if the parameter does not exist.

Usage

From source file:org.wuspba.ctams.ui.server.DataUtils.java

protected static CTAMSDocument getRoster(HttpServletRequest request) {

    Roster roster = null;/*from   ww w  . ja v  a2 s. c om*/

    URIBuilder builder;

    if (request.getParameter("id") != null) {

        LOG.info("Updating roster " + request.getParameter("id"));

        builder = new URIBuilder().setScheme(ServerUtils.PROTOCOL).setHost(ServerUtils.HOST)
                .setPort(ServerUtils.PORT).setParameter("id", request.getParameter("id"))
                .setPath(ServerUtils.URI + "/roster");

        try {
            String xml = ServerUtils.get(builder.build());
            CTAMSDocument doc = XMLUtils.unmarshal(xml);
            if (!doc.getRosters().isEmpty()) {
                roster = doc.getRosters().get(0);
            }
        } catch (IOException ex) {
            LOG.error("Error finding roster", ex);
        } catch (URISyntaxException uex) {
            LOG.error("Invalid URI", uex);
        }
    } else if (request.getParameter("bandId") != null) {
        builder = new URIBuilder().setScheme(ServerUtils.PROTOCOL).setHost(ServerUtils.HOST)
                .setPort(ServerUtils.PORT).setParameter("band", request.getParameter("bandId"))
                .setParameter("season", request.getParameter("season"))
                .setParameter("version", request.getParameter("version")).setPath(ServerUtils.URI + "/roster");

        try {
            String xml = ServerUtils.get(builder.build());
            CTAMSDocument doc = XMLUtils.unmarshal(xml);
            if (!doc.getRosters().isEmpty()) {
                roster = doc.getRosters().get(0);
            }
        } catch (IOException ex) {
            LOG.error("Error finding roster", ex);
        } catch (URISyntaxException uex) {
            LOG.error("Invalid URI", uex);
        }

        if (roster == null) {

            LOG.info("Adding new roster");

            BandRegistration reg = null;

            builder = new URIBuilder().setScheme(ServerUtils.PROTOCOL).setHost(ServerUtils.HOST)
                    .setPort(ServerUtils.PORT).setParameter("band", request.getParameter("bandId"))
                    .setParameter("season", request.getParameter("season"))
                    .setPath(ServerUtils.URI + "/bandregistration");

            try {
                String xml = ServerUtils.get(builder.build());
                CTAMSDocument doc = XMLUtils.unmarshal(xml);
                if (!doc.getBandRegistrations().isEmpty()) {
                    reg = doc.getBandRegistrations().get(0);
                }
            } catch (IOException ex) {
                LOG.error("Error finding registration", ex);
            } catch (URISyntaxException uex) {
                LOG.error("Invalid URI", uex);
            }

            if (reg != null) {
                roster = new Roster();
                roster.setRegistration(reg);
                roster.setVersion(Integer.parseInt(request.getParameter("version")));
                roster.setSeason(Integer.parseInt(request.getParameter("season")));
                CTAMSDocument cd = new CTAMSDocument();
                cd.getRosters().add(roster);
                String rosterXML = XMLUtils.marshal(cd);
                builder = new URIBuilder().setScheme(ServerUtils.PROTOCOL).setHost(ServerUtils.HOST)
                        .setPort(ServerUtils.PORT).setPath(ServerUtils.URI + "/roster");
                try {
                    rosterXML = ServerUtils.post(builder.build(), rosterXML);
                } catch (IOException ex) {
                    LOG.error("Error adding roster", ex);
                } catch (URISyntaxException uex) {
                    LOG.error("Invalid URI", uex);
                }
                roster = XMLUtils.unmarshal(rosterXML).getRosters().get(0);
            }
        }
    }

    if (request.getParameter("memberID") != null) {

        if (request.getParameter("remove") != null) {
            LOG.info("Removing member from an existing roster");

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

            BandMember toRemove = null;

            for (BandMember member : roster.getMembers()) {
                if (member.getPerson().getId().equals(id)) {
                    toRemove = member;
                    break;
                }
            }

            if (toRemove != null) {
                LOG.info("Removing " + toRemove.getId());
                roster.getMembers().remove(toRemove);
            }

        } else {

            LOG.info("Adding a member to an existing roster");

            builder = new URIBuilder().setScheme(ServerUtils.PROTOCOL).setHost(ServerUtils.HOST)
                    .setPort(ServerUtils.PORT).setParameter("id", request.getParameter("memberID"))
                    .setPath(ServerUtils.URI + "/person");

            try {
                String xml = ServerUtils.get(builder.build());
                CTAMSDocument person = XMLUtils.unmarshal(xml);

                BandMember member = new BandMember();
                member.setPerson(person.getPeople().get(0));
                member.setType(BandMemberType.valueOf(request.getParameter("memberPosition")));
                CTAMSDocument memberDoc = new CTAMSDocument();
                memberDoc.getBandMembers().add(member);
                String memberXML = XMLUtils.marshal(memberDoc);

                builder = new URIBuilder().setScheme(ServerUtils.PROTOCOL).setHost(ServerUtils.HOST)
                        .setPort(ServerUtils.PORT).setPath(ServerUtils.URI + "/bandmember");
                memberXML = ServerUtils.post(builder.build(), memberXML);

                member = XMLUtils.unmarshal(memberXML).getBandMembers().get(0);

                roster.getMembers().add(member);
            } catch (IOException ex) {
                LOG.error("Error finding band registration", ex);
            } catch (URISyntaxException uex) {
                LOG.error("Invalid URI", uex);
            }
        }
    }

    CTAMSDocument doc = new CTAMSDocument();
    doc.getRosters().add(roster);

    return doc;
}

From source file:com.ofbizcn.securityext.login.LoginEvents.java

/** Show the password hint for the userLoginId specified in the request object.
 *@param request The HTTPRequest object for the current request
 *@param response The HTTPResponse object for the current request
 *@return String specifying the exit status of this event
 *///from   w  w  w .  j  ava 2  s .co m
public static String showPasswordHint(HttpServletRequest request, HttpServletResponse response) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");

    String userLoginId = request.getParameter("USERNAME");
    String errMsg = null;

    if ((userLoginId != null) && ("true".equals(
            EntityUtilProperties.getPropertyValue("security.properties", "username.lowercase", delegator)))) {
        userLoginId = userLoginId.toLowerCase();
    }

    if (!UtilValidate.isNotEmpty(userLoginId)) {
        // the password was incomplete
        errMsg = UtilProperties.getMessage(resource, "loginevents.username_was_empty_reenter",
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }

    GenericValue supposedUserLogin = null;

    try {
        supposedUserLogin = EntityQuery.use(delegator).from("UserLogin").where("userLoginId", userLoginId)
                .queryOne();
    } catch (GenericEntityException gee) {
        Debug.logWarning(gee, "", module);
    }
    if (supposedUserLogin == null) {
        // the Username was not found
        errMsg = UtilProperties.getMessage(resource, "loginevents.username_not_found_reenter",
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }

    String passwordHint = supposedUserLogin.getString("passwordHint");

    if (!UtilValidate.isNotEmpty(passwordHint)) {
        // the Username was not found
        errMsg = UtilProperties.getMessage(resource,
                "loginevents.no_password_hint_specified_try_password_emailed", UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }

    Map<String, String> messageMap = UtilMisc.toMap("passwordHint", passwordHint);
    errMsg = UtilProperties.getMessage(resource, "loginevents.password_hint_is", messageMap,
            UtilHttp.getLocale(request));
    request.setAttribute("_EVENT_MESSAGE_", errMsg);
    return "success";
}

From source file:com.stratelia.silverpeas.pdcPeas.servlets.PdcSearchRequestRouterHelper.java

public static QueryParameters saveFavoriteRequestAndSetPdcInfo(PdcSearchSessionController pdcSC,
        HttpServletRequest request, String favoriteRequestId) throws Exception {
    // this parameter is for Back Button on result page
    String urlToRedirect = request.getParameter("urlToRedirect");
    request.setAttribute("urlToRedirect", urlToRedirect);
    // load settings of selected Interest center
    InterestCenter ic = pdcSC.loadICenter(favoriteRequestId);
    QueryParameters queryParameters = saveFavoriteRequest(pdcSC, ic);
    setUserChoices(request, pdcSC);//from   www. j  a  v a  2s  . c om
    setAttributesAdvancedSearch(pdcSC, request, true);
    setPertinentAxis(pdcSC, request);
    setContext(pdcSC, request);

    return queryParameters;
}

From source file:com.redhat.rhn.common.util.RecurringEventPicker.java

/**
 * Prepopulate the request with the picker
 * @param request the http request//from  w  ww  .jav  a2s. co  m
 * @param name the name of the picker
 * @param cronEntry if non-null, will set the picker to this.
 * @return The created picker
 */
public static RecurringEventPicker prepopulatePicker(HttpServletRequest request, String name,
        String cronEntry) {

    RecurringEventPicker p = new RecurringEventPicker(name);
    request.setAttribute(name, p);

    String tmpStatus = request.getParameter(name + "_status");
    if (tmpStatus != null) {
        p.setStatus(tmpStatus);
        if (tmpStatus.equals(STATUS_DAILY)) {
            DatePicker timePicker = p.getDailyTimePicker();
            timePicker.readMap(request.getParameterMap());
            String hour = String.valueOf(timePicker.getHourOfDay());
            String minute = String.valueOf(timePicker.getMinute());
            p.setCronEntry(buildCron(minute, hour, null, null, STATUS_DAILY));

        } else if (tmpStatus.equals(STATUS_WEEKLY)) {
            DatePicker timePicker = p.getWeeklyTimePicker();
            timePicker.readMap(request.getParameterMap());
            String hour = String.valueOf(timePicker.getHourOfDay());
            String minute = String.valueOf(timePicker.getMinute());
            String day = request.getParameter(name + WEEKLY_DAY_OF_WEEK);
            p.setCronEntry(buildCron(minute, hour, null, day, STATUS_WEEKLY));
        } else if (tmpStatus.equals(STATUS_MONTHLY)) {
            DatePicker timePicker = p.getMonthlyTimePicker();
            timePicker.readMap(request.getParameterMap());
            String hour = String.valueOf(timePicker.getHourOfDay());
            String minute = String.valueOf(timePicker.getMinute());
            String day = request.getParameter(name + MONTHLY_DAY_OF_MONTH);
            p.setCronEntry(buildCron(minute, hour, day, null, STATUS_MONTHLY));
        } else if (tmpStatus.equals(STATUS_CRON)) {
            p.setCronEntry(request.getParameter(name + CRON_ENTRY));
        } else if (tmpStatus.equals(STATUS_DISABLED)) {
            p.setStatus(STATUS_DISABLED);
        }
    } else if (cronEntry != null) {
        if (cronEntry.split(WHITE_SPACE).length < 6) {
            //The Cron Entry is too short
            return null;
        }

        // here do it the other way around, set the time pickers from
        // the cron time
        if (matches(cronEntry, DAILY_REGEX)) {
            p.setStatus(STATUS_DAILY);
            p.setCronEntry(cronEntry);
            DatePicker timePicker = p.getDailyTimePicker();
            timePicker.setHourOfDay(p.getHourLong().intValue());
            timePicker.setMinute(p.getMinuteLong().intValue());
        } else if (matches(cronEntry, WEEKLY_REGEX)) {
            p.setStatus(STATUS_WEEKLY);
            p.setCronEntry(cronEntry);
            DatePicker timePicker = p.getWeeklyTimePicker();
            timePicker.setHourOfDay(p.getHourLong().intValue());
            timePicker.setMinute(p.getMinuteLong().intValue());
        } else if (matches(cronEntry, MONTHLY_REGEX)) {
            p.setStatus(STATUS_MONTHLY);
            p.setCronEntry(cronEntry);
            DatePicker timePicker = p.getMonthlyTimePicker();
            timePicker.setHourOfDay(p.getHourLong().intValue());
            timePicker.setMinute(p.getMinuteLong().intValue());
        } else {
            p.setStatus(STATUS_CRON);
            p.setCronEntry(cronEntry);
        }
    }

    return p;
}

From source file:com.jaspersoft.jasperserver.rest.RESTUtils.java

public static String getDetinationUri(HttpServletRequest req) { // for action that specify the destination of the action in the request
    if (req.getParameterMap().containsKey(REQUEST_PARAMENTER_MOVE_TO))
        return req.getParameter(REQUEST_PARAMENTER_MOVE_TO);

    if (req.getParameterMap().containsKey(REQUEST_PARAMENTER_COPY_TO))
        return req.getParameter(REQUEST_PARAMENTER_COPY_TO);

    return null;//from ww  w.ja  v  a 2  s.co m
}

From source file:edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils.java

public static String getRequestParam(HttpServletRequest req) {
    String val = "<table>";
    Enumeration names = req.getParameterNames();
    while (names.hasMoreElements()) {

        String name = (String) names.nextElement();
        val += "\n\t<tr><td><h3>" + name + "</h3><td><pre>";
        String value = null;//from  www  .  j  a  va2s.  c  om
        try {
            Object obj = req.getParameter(name);
            value = (obj == null) ? "[null]" : StringEscapeUtils.escapeHtml(obj.toString());
        } catch (Exception ex) {
            value = "unable to get value";
        } catch (Error er) {
            value = "unable to get value";
        } catch (Throwable th) {
            value = "unable to get value";
        }
        val += value + "</pre><td></tr>\n";
    }
    return val + "</table>";
}

From source file:info.magnolia.cms.security.Authenticator.java

/**
 * Authenticate authorization request using JAAS login module as configured
 * @param request as received by the servlet engine
 * @return boolean/*from ww  w  . j  av a2 s  . c om*/
 */
public static boolean authenticate(HttpServletRequest request) {
    String credentials = request.getHeader("Authorization");
    String userid;
    String pswd;
    CredentialsCallbackHandler callbackHandler;
    String loginModuleToInitialize = "magnolia"; // default login module

    if (StringUtils.isEmpty(credentials) || credentials.length() <= 6) {
        // check for form based login request
        if (StringUtils.isNotEmpty(request.getParameter(PARAMETER_USER_ID))) {
            userid = request.getParameter(PARAMETER_USER_ID);
            pswd = StringUtils.defaultString(request.getParameter(PARAMETER_PSWD));
            callbackHandler = new PlainTextCallbackHandler(userid, pswd.toCharArray());
        } else {
            // select login module to use if user is authenticated against the container
            if (request.getUserPrincipal() != null) {
                loginModuleToInitialize = "magnolia_authorization";
                callbackHandler = new PlainTextCallbackHandler(request.getUserPrincipal().getName(),
                        "".toCharArray());
            } else {
                // invalid auth request
                return false;
            }
        }
    } else {
        // its a basic authentication request
        callbackHandler = new Base64CallbackHandler(credentials);
    }

    Subject subject;
    try {
        LoginContext loginContext = new LoginContext(loginModuleToInitialize, callbackHandler);
        loginContext.login();
        subject = loginContext.getSubject();
        // ok, we NEED a session here since the user has been authenticated
        HttpSession httpsession = request.getSession(true);
        httpsession.setAttribute(ATTRIBUTE_JAAS_SUBJECT, subject);
    } catch (LoginException le) {
        if (log.isDebugEnabled())
            log.debug("Exception caught", le);

        HttpSession httpsession = request.getSession(false);
        if (httpsession != null) {
            httpsession.invalidate();
        }
        return false;
    }

    return true;
}

From source file:net.naijatek.myalumni.util.utilities.ParamUtil.java

public static String getParameterPassword(final HttpServletRequest request, final String param, int minLength,
        final int option) throws BadInputException {

    if (minLength < 1) {
        minLength = 1;/* w w w . j a  v  a2 s  .  co m*/
    }
    String ret = request.getParameter(param);
    if (ret == null) {
        ret = "";
    }
    ret = ret.trim();

    if (ret.length() < minLength) {
        throw new BadInputException("Your password is not allowed to be lesser than " + minLength
                + " characters! Please try again.");
    }

    /* @todo implement this feature */
    if (option == 1) {//char and number

    } else if (option == 2) {// lower char, upper char and number

    }
    return ret;
}

From source file:com.mobileman.projecth.web.util.UserUtils.java

/**
 * @param request/*  w ww. jav a2  s .  com*/
 * @param doctor
 */
public static void saveDiseases(HttpServletRequest request, User doctor, UserService userService,
        DiseaseService diseaseService) {
    List<Long> diseaseIds = new ArrayList<Long>();
    for (@SuppressWarnings("unchecked")
    Enumeration<String> e = request.getParameterNames(); e.hasMoreElements();) {
        String nameStr = e.nextElement();
        if (nameStr.startsWith("disease")) {
            String value = request.getParameter(nameStr);
            Long diseaseId = NumUtils.convert2long(value);
            diseaseIds.add(diseaseId);
        }
    }
    List<Disease> addDiseases = new ArrayList<Disease>();
    List<Disease> removeDiseases = new ArrayList<Disease>();
    //add new diseases
    for (Long diseaseId : diseaseIds) {
        if (!UserUtils.containsDisease(diseaseId, doctor.getDiseases())) {
            addDiseases.add(diseaseService.findById(diseaseId));
        }
    }
    //remove old diseases
    for (Disease disease : doctor.getDiseases()) {
        if (!diseaseIds.contains(disease.getId())) {
            removeDiseases.add(disease);
        }
    }

    if (addDiseases.size() > 0) {
        userService.addDiseasesToUser(doctor.getId(), addDiseases);
    }
    if (removeDiseases.size() > 0) {
        userService.removeDiseasesFromUser(doctor.getId(), removeDiseases);
    }
}

From source file:com.painiu.webapp.upload.UploadProcessor.java

private static Integer getCreative(HttpServletRequest request) {
    int creative = Painiu.CREATIVE_AUTHOR;
    String string = request.getParameter("creative");
    if (String.valueOf(Painiu.CREATIVE_REFERENCED).equals(string)) {
        creative = Painiu.CREATIVE_REFERENCED;
    }/*from w w  w.java  2s  .  c  om*/
    return new Integer(creative);
}