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:org.jahia.modules.newsletter.action.SubscribeAction.java

public ActionResult doExecute(final HttpServletRequest req, final RenderContext renderContext,
        final Resource resource, JCRSessionWrapper session, final Map<String, List<String>> parameters,
        URLResolver urlResolver) throws Exception {

    return JCRTemplate.getInstance().doExecuteWithSystemSession(null, "live", new JCRCallback<ActionResult>() {
        public ActionResult doInJCR(JCRSessionWrapper session) throws RepositoryException {
            try {
                String email = getParameter(parameters, "email");
                final JCRNodeWrapper node = resource.getNode();
                if (email != null) {
                    // consider as non-registered user
                    if (email.length() == 0 || !MailService.isValidEmailAddress(email, false)) {
                        // provided e-mail is empty
                        logger.warn("Invalid e-mail address '{}' provided for subscription to {}."
                                + " Ignoring subscription request.", email, node.getPath());
                        return new ActionResult(SC_OK, null, new JSONObject("{\"status\":\"invalid-email\"}"));
                    }//from   w  w w .  j  a v  a2 s .  co m
                    Map<String, Object> props = new HashMap<String, Object>();
                    String[] extraProperties = req.getParameterValues("j:fields");
                    if (extraProperties != null) {
                        for (String extraProperty : extraProperties) {
                            if (req.getParameter(extraProperty) != null) {
                                props.put(extraProperty, req.getParameter(extraProperty));
                            }
                        }
                    }

                    final JCRNodeWrapper subscription = subscriptionService.getSubscription(node, email,
                            session);
                    if (subscription != null) {
                        if (!subscription.getProperty(SubscriptionService.J_CONFIRMED).getBoolean()) {
                            if (sendConfirmationMail(session, email, node, subscription, resource.getLocale(),
                                    req)) {
                                return new ActionResult(SC_OK, null,
                                        new JSONObject("{\"status\":\"mail-sent\"}"));
                            }
                        }
                        return new ActionResult(SC_OK, null,
                                new JSONObject("{\"status\":\"already-subscribed\"}"));
                    } else {
                        JCRNodeWrapper newSubscriptionNode = subscriptionService.subscribe(node.getIdentifier(),
                                email, props, session);

                        if (sendConfirmationMail(session, email, node, newSubscriptionNode,
                                resource.getLocale(), req)) {
                            return new ActionResult(SC_OK, null, new JSONObject("{\"status\":\"mail-sent\"}"));
                        }
                    }
                } else {
                    JahiaUser user = renderContext.getUser();
                    JCRUserNode userNode = userManagerService.lookupUserByPath(user.getLocalPath());
                    if (JahiaUserManagerService.isGuest(user) || userNode == null) {
                        // anonymous users are not allowed (and no email was provided)
                        return new ActionResult(SC_OK, null, new JSONObject("{\"status\":\"invalid-email\"}"));
                    }
                    if (!allowRegistrationWithoutEmail) {
                        // checking if the user has a valid e-mail address
                        String userEmail = userNode.getPropertyAsString("j:email");
                        if (userEmail == null || !MailService.isValidEmailAddress(userEmail, false)) {
                            // no valid e-mail provided -> refuse
                            return new ActionResult(SC_OK, null,
                                    new JSONObject("{\"status\":\"no-valid-email\"}"));
                        }
                    }
                    if (subscriptionService.getSubscription(node.getIdentifier(), user.getUserKey(),
                            session) != null) {
                        return new ActionResult(SC_OK, null,
                                new JSONObject("{\"status\":\"already-subscribed\"}"));
                    } else {
                        JCRNodeWrapper newSubscriptionNode = subscriptionService.subscribe(node.getIdentifier(),
                                user.getUserKey(), forceConfirmationForRegisteredUsers, session);

                        if (forceConfirmationForRegisteredUsers) {
                            if (sendConfirmationMail(session, userNode.getPropertyAsString("j:email"), node,
                                    newSubscriptionNode, resource.getLocale(), req)) {
                                return new ActionResult(SC_OK, null,
                                        new JSONObject("{\"status\":\"mail-sent\"}"));
                            }
                        } else {
                            return new ActionResult(SC_OK, null, new JSONObject("{\"status\":\"ok\"}"));
                        }

                    }
                }
                return new ActionResult(SC_OK, null, new JSONObject("{\"status\":\"ok\"}"));
            } catch (JSONException e) {
                logger.error("Error", e);
                return new ActionResult(SC_INTERNAL_SERVER_ERROR, null, null);
            }
        }
    });
}

From source file:edu.fullerton.ldvservlet.SrcList.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 *
 * @param request servlet request/*from   w  ww .ja  va  2s.  c om*/
 * @param response servlet response
        
* @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 * @throws edu.fullerton.jspWebUtils.WebUtilException
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, WebUtilException {
    response.setContentType("text/html;charset=UTF-8");

    ServletSupport servletSupport;

    servletSupport = new ServletSupport();
    servletSupport.init(request, viewerConfig, false);

    Page vpage = servletSupport.getVpage();
    vpage.includeJS("showByClass.js");
    vpage.setTitle("Channel source list");
    servletSupport.addStandardHeader("");
    servletSupport.addNavBar();
    String contextPath = request.getContextPath();

    try {
        ChannelTable ctbl = new ChannelTable(servletSupport.getDb());
        ChannelIndex cindx = new ChannelIndex(servletSupport.getDb());
        ChanPointerTable cptrs = new ChanPointerTable(servletSupport.getDb());
        ArrayList<ChanSourceData> csdList = new ArrayList<>();

        String[] baseIds = request.getParameterValues("baseid");
        int tblNum = 1;
        PageItemList tables = new PageItemList();
        boolean zoom = request.getParameter("replot") != null;
        TimeInterval searchRange = new TimeInterval(0, 1800000000);
        String menuChoice = "";
        if (zoom) {
            searchRange = getSearchRange(request.getParameterMap());
            String[] timrng = (String[]) request.getParameterMap().get("timerange");
            if (timrng != null) {
                menuChoice = timrng[0];
            }

        }

        if (baseIds != null) {
            List<Integer> chanList = new ArrayList<>();

            for (String baseId : baseIds) {
                ChanIndexInfo cii;

                if (baseId.trim().matches("^\\d+$")) {
                    int bid = Integer.parseInt(baseId);
                    cii = cindx.getInfo(bid);

                    String[] trtype = { "mean" };
                    if (cii.hasRaw()) {
                        chanList.addAll(cptrs.getChanList(bid, "raw"));
                    }
                    if (cii.hasRds()) {
                        chanList.addAll(cptrs.getChanList(bid, "rds"));
                    }
                    if (cii.hasMtrends()) {
                        chanList.addAll(cptrs.getChanList(bid, "minute-trend", trtype));
                    }
                    if (cii.hasStrends()) {
                        chanList.addAll(cptrs.getChanList(bid, "second-trend", trtype));
                    }
                    if (cii.hasStatic()) {
                        chanList.addAll(cptrs.getChanList(bid, "static"));
                    }
                    tblNum = addChanSource(tables, chanList, ctbl, tblNum, csdList, searchRange);
                    PageItem plots = makePlots(csdList, cii.getName(), servletSupport.getDb(),
                            servletSupport.getVpage(), servletSupport.getVuser(), contextPath);
                    PageItem plotForm = getImgForm(servletSupport, plots, bid, 0, zoom, searchRange,
                            menuChoice);
                    vpage.add(plotForm);
                    vpage.add(tables);

                }
            }

        }
        String[] chanIds = request.getParameterValues("chanid");
        if (chanIds != null) {
            ChanInfo ci;

            for (String chanId : chanIds) {
                if (chanId.trim().matches("^\\d+$")) {
                    int id = Integer.parseInt(chanId);
                    ci = ctbl.getChanInfo(id);
                    List<Integer> chanList = new ArrayList<>();
                    chanList.add(id);
                    tblNum = addChanSource(tables, chanList, ctbl, tblNum, csdList, searchRange);
                    PageItem plots = makePlots(csdList, ci.getChanName(), servletSupport.getDb(),
                            servletSupport.getVpage(), servletSupport.getVuser(), contextPath);
                    PageItem plotForm = getImgForm(servletSupport, plots, 0, id, zoom, searchRange, menuChoice);
                    vpage.add(plotForm);
                    vpage.add(tables);
                }
            }
        }

        servletSupport.showPage(response);
    } catch (LdvTableException | SQLException ex) {
        String ermsg = String.format("Error showing channel source data. %1$s - %2$s",
                ex.getClass().getSimpleName(), ex.getLocalizedMessage());
        vpage.add(ermsg);
        servletSupport.showPage(response);
    } finally {
        servletSupport.close();
    }

}

From source file:fr.paris.lutece.plugins.sponsoredlinks.web.SponsoredLinksJspBean.java

/**
 * Process the data capture form of a new sponsoredlinks set
 *
 * @param request The Http Request//from  ww  w.j  a  va  2 s  .c  om
 * @return The Jsp URL of the process result
 */
public String doCreateSet(HttpServletRequest request) {
    if ((request.getParameter(PARAMETER_CANCEL) != null)
            || !RBACService.isAuthorized(SponsoredLinkSet.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
                    SponsoredLinksSetResourceIdService.PERMISSION_CREATE_SET, getUser())) {
        return JSP_REDIRECT_TO_MANAGE_SET;
    }

    String strTitle = request.getParameter(PARAMETER_SET_TITLE);
    String strGroupId = request.getParameter(PARAMETER_GROUP_ID);
    String[] strArrayLinks = request.getParameterValues(PARAMETER_SET_LINK_LIST);

    // Mandatory fields
    if (StringUtils.isBlank(strTitle) || StringUtils.isBlank(strGroupId) || (strArrayLinks == null)
            || (strArrayLinks.length == 0)) {
        return AdminMessageService.getMessageUrl(request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP);
    }

    int nGroupId = Integer.parseInt(strGroupId);

    SponsoredLinkSet set = new SponsoredLinkSet();
    List<SponsoredLink> linkList = new ArrayList<SponsoredLink>();
    SponsoredLink currentLink;

    for (int i = strArrayLinks.length - 1; i >= 0; --i) {
        if (!strArrayLinks[i].trim().equals("\u00A0")) {
            currentLink = new SponsoredLink();
            currentLink.setOrder(i + 1);
            currentLink.setLink(strArrayLinks[i]);

            if (currentLink.isValidLink()) {
                linkList.add(currentLink);
            } else {
                AppLogService.error(new InvalidParameterException("In SponsoredLinkSet \"" + strTitle + "\" : "
                        + " SponsoredLink[" + currentLink.getOrder() + "] - " + currentLink.getLink()
                        + "> : is not a valid html link"));
            }
        }
    }

    set.setTitle(strTitle);
    set.setGroupId(nGroupId);
    set.setSponsoredLinkList(linkList);

    SponsoredLinkSetHome.create(set, getPlugin());

    // if the operation occurred well, redirects towards the list of sets
    return JSP_REDIRECT_TO_MANAGE_SET;
}

From source file:net.naijatek.myalumni.modules.admin.presentation.action.MaintainPrivateMessageAction.java

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

    ActionMessages errors = new ActionMessages();

    if (isCancelled(request)) {
        return mapping.findForward(BaseConstants.FWD_CANCEL);
    }//from  www . j a v  a  2  s.c  o  m

    MemberVO token = getCurrentLoggedInUser(request);

    // check to see if the user logged on is a member
    if (!memberSecurityCheck(request, token)) {
        return mapping.findForward(BaseConstants.FWD_LOGIN);
    }

    String[] mailArray = new String[0];

    PrivateMessageForm pmForm = (PrivateMessageForm) form;
    String memberId = token.getMemberId();
    String privMsgsAction = pmForm.getPrivMsgsAction();

    //String privAdminDelete =  StringUtil.safeString(pmForm.getPrivAdminDelete());
    //String privAdminMove = StringUtil.safeString(pmForm.getPrivAdminMove());

    //if ( privAdminDelete.equalsIgnoreCase("yes") || privAdminMove.equalsIgnoreCase("yes")){
    // check to see if the user logged on is a member
    if (!adminSecurityCheck(request, token)) {
        return mapping.findForward(BaseConstants.FWD_ADMIN_LOGIN);
    }

    memberId = BaseConstants.ADMIN_USERNAME_ID;
    //}

    mailArray = request.getParameterValues("messageId");

    if (mailArray == null) {
        errors.add(BaseConstants.WARN_KEY, new ActionMessage("error.selectOne"));
        saveMessages(request, errors);
        return mapping.getInputForward();
    }

    /**
    * DELETE MAIL
    */
    if (privMsgsAction.equalsIgnoreCase("delete")) {
        pmService.deleteMail(mailArray, memberId, getLastModifiedBy(request));
        doMailDuties(token, request);
    }

    /**
    * MOVE MAIL
    */
    else if (privMsgsAction.equalsIgnoreCase("move")) {
        String toFolder = pmForm.getFolderName();
        pmService.moveMail(mailArray, memberId, toFolder, getLastModifiedBy(request));
        doMailDuties(token, request);
    }

    /**
    * EMPTY TRASH
    */
    else if (privMsgsAction.equalsIgnoreCase("empty")) {
        pmService.deleteMail(mailArray, memberId, getLastModifiedBy(request));
        doMailDuties(token, request);
    }

    else {
        errors.add(BaseConstants.FATAL_KEY, new ActionMessage("errors.technical.difficulty"));
        saveMessages(request, errors);
        return mapping.getInputForward();
    }

    return mapping.findForward(BaseConstants.FWD_SUCCESS);
}

From source file:byps.http.HHttpServlet.java

private String makeLogRequest(HttpServletRequest request, int status) {
    StringBuilder sbuf = new StringBuilder();
    sbuf.append("Request: ").append(request.getMethod()).append(" ").append(" ").append(request.getRequestURI())
            .append(" (");
    for (Enumeration<String> en = request.getParameterNames(); en.hasMoreElements();) {
        String paramName = en.nextElement();
        String[] paramValues = request.getParameterValues(paramName);
        sbuf.append(paramName).append("=").append(Arrays.toString(paramValues));
        if (en.hasMoreElements())
            sbuf.append(", ");
    }//  w w  w  .  j  a  va  2s.c  om
    sbuf.append(") = ").append(status);
    return sbuf.toString();
}

From source file:com.globalsight.connector.mindtouch.MindTouchCreateJobHandler.java

@ActionHandler(action = "createMindTouchJob", formClass = "com.globalsight.connector.mindtouch.form.CreateMindTouchJobForm")
public void createMindTouchJob(HttpServletRequest request, HttpServletResponse response, Object form)
        throws Exception {
    CreateMindTouchJobForm mtForm = (CreateMindTouchJobForm) form;
    SessionManager sessionMgr = (SessionManager) request.getSession().getAttribute(SESSION_MANAGER);
    String currentCompanyId = CompanyThreadLocal.getInstance().getValue();
    User user = (User) sessionMgr.getAttribute(WebAppConstants.USER);
    if (user == null) {
        String userName = request.getParameter("userName");
        if (userName != null && !"".equals(userName)) {
            user = ServerProxy.getUserManager().getUserByName(userName);
            sessionMgr.setAttribute(WebAppConstants.USER, user);
        }//from ww w .ja  va  2 s  .  c  om
    }

    long mtcId = Long.parseLong(mtForm.getMindtouchConnectorId());
    MindTouchConnector mtc = MindTouchManager.getMindTouchConnectorById(mtcId);

    File attachment = null;
    String jobCommentFilePathName = (String) sessionMgr.getAttribute("uploadAttachment");
    if (jobCommentFilePathName != null) {
        attachment = new File(jobCommentFilePathName);
    }
    sessionMgr.removeElement("uploadAttachment");

    String[] targetLocales = request.getParameterValues("targetLocale");
    String attachmentName = request.getParameter("attachment");
    String uuid = sessionMgr.getAttribute("uuid") == null ? JobImpl.createUuid()
            : (String) sessionMgr.getAttribute("uuid");
    sessionMgr.removeElement("uuid");

    CreateMindTouchJobThread runnable = new CreateMindTouchJobThread(user, currentCompanyId, mtc, mtForm,
            targetLocales, attachment, attachmentName, uuid);
    Thread t = new MultiCompanySupportedThread(runnable);
    t.start();

    pageReturn();
}

From source file:com.zimbra.cs.dav.service.DavServlet.java

private void logRequestInfo(HttpServletRequest req) {
    if (!ZimbraLog.dav.isDebugEnabled()) {
        return;/*w  w w  .  ja v  a  2 s. c  om*/
    }
    StringBuilder hdrs = new StringBuilder();
    hdrs.append("DAV REQUEST:\n");
    hdrs.append(req.getMethod()).append(" ").append(req.getRequestURL().toString()).append(" ")
            .append(req.getProtocol());
    Enumeration<String> paramNames = req.getParameterNames();
    if (paramNames != null && paramNames.hasMoreElements()) {
        hdrs.append("\nDAV REQUEST PARAMS:");
        while (paramNames.hasMoreElements()) {
            String paramName = paramNames.nextElement();
            if (paramName.contains("Auth")) {
                hdrs.append("\n").append(paramName).append("=*** REPLACED ***");
                continue;
            }
            String params[] = req.getParameterValues(paramName);
            if (params != null) {
                for (String param : params) {
                    hdrs.append("\n").append(paramName).append("=").append(param);
                }
            }
        }
    }
    /* Headers can include vital information which affects the request like "If-None-Match" headers,
     * so useful to be able to log them, skipping authentication related headers to avoid leaking passwords
     */
    Enumeration<String> namesEn = req.getHeaderNames();
    if (namesEn != null && namesEn.hasMoreElements()) {
        hdrs.append("\nDAV REQUEST HEADERS:");
        while (namesEn.hasMoreElements()) {
            String hdrName = namesEn.nextElement();
            if (hdrName.contains("Auth") || (hdrName.contains(HttpHeaders.COOKIE))) {
                hdrs.append("\n").append(hdrName).append(": *** REPLACED ***");
                continue;
            }
            Enumeration<String> vals = req.getHeaders(hdrName);
            while (vals.hasMoreElements()) {
                hdrs.append("\n").append(hdrName).append(": ").append(vals.nextElement());
            }
        }
    }
    ZimbraLog.dav.debug(hdrs.toString());
}

From source file:com.topsec.tsm.sim.report.web.ReportController.java

private StringBuffer getNoConditionUrl(String prefix, HttpServletRequest request, Map params) {
    String type = request.getParameter("type");
    String onlyByDvctype = request.getParameter("onlyByDvctype");
    String reportType = request.getParameter("reportType");
    if ("Esm/Topsec/SimEvent".equals(params.get("dvcType"))
            || "Esm/Topsec/SystemLog".equals(params.get("dvcType"))
            || "Esm/Topsec/SystemRunLog".equals(params.get("dvcType"))
            || "Log/Global/Detail".equals(params.get("dvcType"))) {
        onlyByDvctype = "onlyByDvctype";
    }/*  w  ww.j  a va  2s .  com*/
    String[] nodeIds = request.getParameterValues("nodeId");
    String dvcaddress = request.getParameter(ReportUiConfig.dvcaddress);
    StringBuffer sb = new StringBuffer();
    sb.append(prefix).append(ReportUiConfig.dvctype).append("=").append(params.get("dvcType"));
    if (StringUtil.isNotBlank(onlyByDvctype)) {
        sb.append("&onlyByDvctype=onlyByDvctype");
    }
    if (StringUtil.isNotBlank(type)) {
        sb.append("&type").append("=").append(type);
    }
    if (StringUtil.isNotBlank(reportType)) {
        sb.append("&reportType").append("=").append(reportType);
    }
    if (nodeIds == null && "onlyByDvctype".equals(onlyByDvctype)) {
        String dvcType = params.get("dvcType").toString();
        /**? ?ID*/
        if (LogKeyInfo.LOG_GLOBAL_DETAIL.equals(dvcType) || LogKeyInfo.LOG_SIM_EVENT.equals(dvcType)) {
            dvcType = LogKeyInfo.LOG_SYSTEM_TYPE;
        }
        //? ?? ? ????????
        /*List<String> list = dataSourceService.getAuditorNodeIdByDvcType(dvcType);
        for(String str:list){
           sb.append("&nodeId=").append(str);
        }*/
        sb.append("&nodeId=").append(auditor.getNodeId());
    } else {
        for (String str : nodeIds) {
            sb.append("&nodeId=").append(str);
        }
    }
    if (StringUtil.isNotBlank(dvcaddress)) {
        sb.append("&").append(ReportUiConfig.dvcaddress).append("=").append(dvcaddress);
    }
    return sb;
}

From source file:com.topsec.tsm.sim.report.web.TopoReportController.java

private StringBuffer getNoConditionUrl(String prefix, HttpServletRequest request, Map params, boolean isevt) {
    String type = request.getParameter("type");
    String[] nodeIds = request.getParameterValues("nodeId");
    if (GlobalUtil.isNullOrEmpty(nodeIds) && !GlobalUtil.isNullOrEmpty(params.get("nodeIds"))) {
        nodeIds = (String[]) params.get("nodeIds");
    }/*from w  w w  .j  ava 2 s .c  o  m*/
    String dvcaddress = request.getParameter(ReportUiConfig.dvcaddress);
    String reportType = request.getParameter("reportType");
    StringBuffer sb = new StringBuffer();
    if (isevt) {
        sb.append(prefix).append(ReportUiConfig.dvctype).append("=").append(params.get("dvcType"));
    } else if ("comprehensiveReportIndex".equals(reportType)) {
        sb.append(prefix).append(ReportUiConfig.dvctype).append("=").append("DynamicComprehensiveReport");
    } else {
        sb.append(prefix).append(ReportUiConfig.dvctype).append("=").append(params.get("nodeType"));
    }

    if (StringUtil.isNotBlank(type)) {
        sb.append("&type").append("=").append(type);
    }
    if (!GlobalUtil.isNullOrEmpty(nodeIds)) {
        for (String str : nodeIds) {
            sb.append("&nodeId=").append(str);
        }
    }
    if (StringUtil.isNotBlank(dvcaddress)) {
        sb.append("&").append(ReportUiConfig.dvcaddress).append("=").append(dvcaddress);
    }
    if (StringUtil.isNotBlank(reportType)) {
        sb.append("&reportType").append("=").append(reportType);
    }
    return sb;
}