Example usage for javax.servlet ServletRequest getParameter

List of usage examples for javax.servlet ServletRequest getParameter

Introduction

In this page you can find the example usage for javax.servlet ServletRequest 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:com.edgenius.wiki.security.acegi.CaptchaValidationProcessingFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    String captchaResponse = request.getParameter(captchaValidationParameter);
    //        if(true)
    //           throw new IOException("EOF");
    if ((request != null) && request instanceof HttpServletRequest && (captchaResponse != null)) {
        logger.debug("captcha validation parameter found");

        //get session
        HttpSession session = ((HttpServletRequest) request).getSession();

        if (session != null) {
            String id = session.getId();
            boolean valid = this.captchaService.validateReponseForId(id, captchaResponse);
            processVerify(request, response, chain, valid);
        } else {//from  www  .  j  av  a  2 s .c o  m
            logger.debug("no session found, user don't even ask a captcha challenge");
        }
    } else {
        chain.doFilter(request, response);
    }

}

From source file:org.kuali.rice.krad.filter.TestingLoginFilter.java

/**
 * Looks for a login user request parameter and establishs a user session for that user, then simply
 * returns a login message./*from w w w  .  ja  v  a  2  s . c  om*/
 *
 * {@inheritDoc}
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpServletRequest = (HttpServletRequest) request;

    if (StringUtils.isBlank(request.getParameter("login_user"))) {
        return;
    }

    final String user = request.getParameter("login_user");

    UserSession userSession = new UserSession(user);
    httpServletRequest.getSession().setAttribute(KRADConstants.USER_SESSION_KEY, userSession);

    // wrap the request with the signed in user
    // UserLoginFilter and WebAuthenticationService will build the session
    request = new HttpServletRequestWrapper(httpServletRequest) {
        @Override
        public String getRemoteUser() {
            return user;
        }
    };

    response.getWriter().print("Login Successful.");
}

From source file:com.acs.manager.CustomManager.java

public UIViewRoot restoreView(FacesContext context, String viewId, String renderKitId) {

    // no need to synchronize here even though the user, double clicking 
    // a button, may start two request threads. Each will just parse the
    // view state info creating a new view root
    UIViewRoot viewRoot = null;//from   w  w w  . j  a v  a2s. c  om

    // the view key from the request
    ServletRequest request = (ServletRequest) context.getExternalContext().getRequest();
    String postedViewId = request.getParameter(ENHANCED_SERVER_STATE_SAVING);

    if (null != postedViewId) {

        //restore viewRoot from serialized view that was saved in session
        SerializedView serializedView = (SerializedView) context.getExternalContext().getSessionMap()
                .get(postedViewId);
        if (null != serializedView) {
            ViewStructure viewStructure = (ViewStructure) serializedView.getStructure();
            viewRoot = (UIViewRoot) viewStructure.createComponent();
            viewStructure.restoreStructure(viewStructure, viewRoot);
            if (null != viewRoot) {
                viewRoot.processRestoreState(context, serializedView.getState());
            }
        }
    }

    return viewRoot;
}

From source file:com.java2s.SendFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws java.io.IOException, ServletException {

    //get the file name from the 'file' parameter
    String fileName = request.getParameter("file");
    if (fileName == null || fileName.equals(""))
        throw new ServletException("Invalid or non-existent file parameter in SendPdf component.");

    if (fileName.indexOf(".pdf") == -1)
        fileName = fileName + ".pdf";

    ServletOutputStream stream = null;// ww  w .  j a  v  a 2 s .  c om
    BufferedInputStream buf = null;
    HttpServletResponse httpResp = null;
    try {

        httpResp = (HttpServletResponse) response;
        stream = httpResp.getOutputStream();
        File pdf = new File(PDF_DIR + "/" + fileName);

        //set response headers
        httpResp.setContentType(PDF_CONTENT_TYPE);
        httpResp.addHeader("Content-Disposition", "attachment; filename=" + fileName);
        httpResp.setContentLength((int) pdf.length());

        FileInputStream input = new FileInputStream(pdf);
        buf = new BufferedInputStream(input);
        int readBytes = 0;
        //read from the file; write to the ServletOutputStream
        while ((readBytes = buf.read()) != -1)
            stream.write(readBytes);

    } catch (Exception ioe) {

        //  throw new ServletException(ioe.getMessage());
        System.out.println(ioe.getMessage());

    } finally {

        if (buf != null)
            buf.close();
        if (stream != null) {
            stream.flush();
            //stream.close();
        }

    } //end finally
    chain.doFilter(request, httpResp);
}

From source file:org.springframework.security.captcha.CaptchaValidationProcessingFilter.java

/**
 * @param request servlet request./*from   w  w w . j  a va 2s .  c o  m*/
 * @param response servlet response
 * @param chain Filter chain
 * @throws IOException io
 * @throws ServletException servlet
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    String captchaResponse = request.getParameter(captchaValidationParameter);

    if (request instanceof HttpServletRequest && (captchaResponse != null)) {
        logger.debug("captcha validation parameter found");

        // validate the request against CaptchaServiceProxy
        boolean valid = false;

        logger.debug("try to validate");

        //get session
        HttpSession session = ((HttpServletRequest) request).getSession();

        if (session != null) {
            String id = session.getId();
            valid = this.captchaService.validateReponseForId(id, captchaResponse);
            logger.debug("captchaServiceProxy says : request is valid = " + valid);

            if (valid) {
                logger.debug("update the context");
                ((CaptchaSecurityContext) SecurityContextHolder.getContext()).setHuman();

                //logger.debug("retrieve original request from ")
            } else {
                logger.debug("captcha test failed");
            }
        } else {
            logger.debug("no session found, user don't even ask a captcha challenge");
        }
    } else {
        logger.debug("captcha validation parameter not found, do nothing");
    }

    if (logger.isDebugEnabled()) {
        logger.debug("chain ...");
    }

    chain.doFilter(request, response);
}

From source file:org.sonar.ide.test.TestServlet.java

@Override
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    String json;//from w  ww . j  a  v a  2s .c  o  m
    try {
        String resourceKey = request.getParameter("resource");
        String[] parts = resourceKey.split(":");
        switch (parts.length) {
        case 2:
            json = loadProjectData(parts[0], parts[1]);
            break;
        case 3:
            json = loadFileData(parts[0], parts[1], parts[2]);
            break;
        default:
            json = "[]";
            break;
        }
    } catch (Exception e) {
        SonarTestServer.LOG.error(e.getMessage(), e);
        json = "[]";
    }
    out.println(json);
}

From source file:com.aurel.track.admin.customize.category.filter.parameters.FilterSelectsParametersUtil.java

/**
 * Replaces the parameters from the filterUpperTO selects with corresponding parameters from request 
 * @param filterUpperTO//  www.  j a v  a2s  .  c o  m
 * @param request
 * @param personBean
 * @param locale
 * @param clear
 * @return
 */
public static FilterUpperTO replaceFilterSelectsParameters(FilterUpperTO filterUpperTO, ServletRequest request,
        TPersonBean personBean, Locale locale, boolean clear) throws NotExistingBeanException {
    if (request != null) {
        //only the upper selects are parameterizable for encoded query urls!
        List<IntegerStringBean> parametrizedFields = FilterSelectsParametersUtil
                .getParameterizedFields(filterUpperTO);
        if (parametrizedFields != null && !parametrizedFields.isEmpty()) {
            //prepares the paramsRequest: from label based values in request it creates fieldID based values 
            Map<Integer, String> paramsRequest = new HashMap<Integer, String>();
            for (int i = 0; i < parametrizedFields.size(); i++) {
                IntegerStringBean integerStringBean = parametrizedFields.get(i);
                String value = request.getParameter(integerStringBean.getLabel());
                if (value != null && value.length() > 0) {
                    Integer fieldID = integerStringBean.getValue();
                    paramsRequest.put(fieldID, value);
                }
            }
            filterUpperTO = FilterSelectsListsLoader.loadFilterSelects(filterUpperTO, personBean, locale, false,
                    false);
            filterUpperTO = replaceFilterSelectsParameters(filterUpperTO, personBean.getObjectID(),
                    paramsRequest, clear);
        }
    }
    return filterUpperTO;
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo.java

/**
 * The editKey can be a HTTP query parameter or it can be a request attribute.
 *///from  ww  w .  j av  a  2s .co  m
public static String getEditKeyFromRequest(ServletRequest request) {
    String key = null;
    if (request instanceof VitroRequest) {
        return request.getParameter("editKey");
    } else if (request instanceof HttpServletRequest) {
        HttpServletRequest hsreq = (HttpServletRequest) request;
        boolean isMultipart = ServletFileUpload.isMultipartContent(hsreq);
        if (isMultipart) {
            //multipart parsing will consume all request parameters so
            //the editKey needs to be stashed in the request attributes.
            key = (String) request.getAttribute("editKey");
            if (key == null) {
                // handle the cancel button where nothing is really uploaded
                key = request.getParameter("editKey");
            }
        } else {
            key = (String) request.getAttribute("editKey");
            if (key != null) {
                return key;
            } else {
                key = request.getParameter("editKey");
            }
        }
    }

    if (key != null && key.trim().length() > 0) {
        return key;
    } else {
        log.debug("cannnot find editKey in request query parameters or from request");
        return null;
    }
}

From source file:dk.netarkivet.harvester.webinterface.SnapshotHarvestDefinition.java

/**
 * Flip the active status of a harvestdefinition named in the "flipactive" parameter.
 *
 * @param context The context of the web servlet
 * @param i18n Translation information//from   w  w w  . jav  a 2 s. c o m
 * @return True if a harvest definition changed state.
 */
public boolean flipActive(PageContext context, I18n i18n) {
    ArgumentNotValid.checkNotNull(context, "PageContext context");
    ArgumentNotValid.checkNotNull(i18n, "I18n i18n");

    ServletRequest request = context.getRequest();
    String flipactive = request.getParameter(Constants.FLIPACTIVE_PARAM);
    // Change activation if requested
    if (flipactive != null) {
        HarvestDefinition hd = hdDaoProvider.get().getHarvestDefinition(flipactive);
        if (hd != null) {
            boolean isActive = hd.getActive();
            boolean useDeduplication = Settings.getBoolean(HarvesterSettings.DEDUPLICATION_ENABLED);
            if (!isActive) {
                if (hd instanceof FullHarvest) {
                    FullHarvest fhd = (FullHarvest) hd;
                    validatePreviousHd(fhd, context, i18n);
                    if (useDeduplication) {
                        // The client for requesting job index.
                        JobIndexCache jobIndexCache = IndexClientFactory.getDedupCrawllogInstance();
                        Long harvestId = fhd.getOid();
                        Set<Long> jobSet = hdDaoProvider.get()
                                .getJobIdsForSnapshotDeduplicationIndex(harvestId);
                        jobIndexCache.requestIndex(jobSet, harvestId);
                    } else {
                        // If deduplication disabled set indexReady to true
                        // right now, so the job generation can proceed.
                        fhd.setIndexReady(true);
                    }
                } else { // hd is not Fullharvest
                    log.warn("Harvestdefinition #" + hd.getOid() + " is not a FullHarvest " + " but a "
                            + hd.getClass().getName());
                    return false;
                }
            }
            hd.setActive(!hd.getActive());
            hdDaoProvider.get().update(hd);
            return true;
        } else {
            HTMLUtils.forwardWithErrorMessage(context, i18n, "errormsg;harvestdefinition.0.does.not.exist",
                    flipactive);
            throw new ForwardedToErrorPage("Harvest definition " + flipactive + " doesn't exist");
        }
    }
    return false;
}

From source file:com.belajar_filter.config.GeneralFilterConfig.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain fc)
        throws IOException, ServletException {
    log.debug("execute do filter ... ");
    HttpServletResponse response = (HttpServletResponse) res;
    HttpServletRequest request = (HttpServletRequest) req;

    String getParam = req.getParameter("name");
    log.debug("intercept param : " + getParam);

    fc.doFilter(req, res);//  w w  w. j a  v a 2 s  .c om

}