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:cn.vlabs.duckling.vwb.CPSFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    int advSiteId = Integer.parseInt(StringUtils.defaultIfEmpty(request.getParameter("as"), "-1"));

    if (advSiteId <= 0) {
        chain.doFilter(request, response);
        return;/*from  www .j a  va  2 s.c o  m*/
    }

    HttpServletResponse rep = (HttpServletResponse) response;
    HttpServletRequest req = (HttpServletRequest) request;
    request.setAttribute("cps", advSiteId);

    Cookie[] cookies = req.getCookies();

    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (StringUtils.equals(CPS_ADV, cookie.getName())) {
                cookie.setPath(req.getContextPath());
                cookie.setMaxAge(0);
            }
        }
    }

    Cookie myCookie = new Cookie(CPS_ADV, advSiteId + "");
    myCookie.setMaxAge(60 * 60 * 24);//
    myCookie.setPath(req.getContextPath());
    rep.addCookie(myCookie);
    chain.doFilter(request, response);
}

From source file:com.iflytek.edu.cloud.frame.web.filter.CheckOpenServiceFilter.java

private Locale getLocale(ServletRequest request) {
    String localePart = request.getParameter(Constants.SYS_PARAM_KEY_LOCALE);
    if (!StringUtils.hasText(localePart))
        localePart = "zh_CN";

    Locale locale = StringUtils.parseLocaleString(localePart);
    return locale;
}

From source file:org.apache.openejb.arquillian.tests.filterenventry.PojoServletFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws ServletException, IOException {
    String name = req.getParameter("name");
    if (StringUtils.isEmpty(name)) {
        name = "OpenEJB";
    }/*from   www. j  av a2s  .  c  o m*/

    if (car != null) {
        resp.getOutputStream().println(car.drive(name));
    }
    if (localCompany != null) {
        resp.getOutputStream().println("Local: " + localCompany.employ(name));
    }
    if (market != null) {
        resp.getOutputStream().println(market.shop(name));
    }
    if (connectionPool != null) {
        resp.getOutputStream().println("Connection Pool: " + connectionPool);
    }
    if (startCount != null) {
        resp.getOutputStream().println("Start Count: " + startCount);
    }
    if (initSize != null) {
        resp.getOutputStream().println("Init Size: " + initSize);
    }
    if (totalQuantity != null) {
        resp.getOutputStream().println("Total Quantity: " + totalQuantity);
    }
    if (enableEmail != null) {
        resp.getOutputStream().println("Enable Email: " + enableEmail);
    }
    if (optionDefault != null) {
        resp.getOutputStream().println("Option Default: " + optionDefault);
    }
    if (StringUtils.isNotEmpty(returnEmail) && returnEmail.equals("tomee@apache.org")) {
        resp.getOutputStream().println(returnEmail);
    }
    if (auditWriter != null) {
        resp.getOutputStream().println(auditWriter.getClass().getName());
    }
    if (defaultCode != null) {
        resp.getOutputStream().println("DefaultCode: " + defaultCode);
    }
}

From source file:org.kuali.rice.devtools.pdle.PostDataLoadEncryptionServlet.java

@Override
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
    String attributesToEncryptPropertyFileName = request.getParameter(ATTRIBUTES_TO_ENCRYPT_PROPERTIES);
    if (StringUtils.isBlank(attributesToEncryptPropertyFileName)) {
        throw new IllegalArgumentException(
                "No valid " + ATTRIBUTES_TO_ENCRYPT_PROPERTIES + " parameter was passed to this Servlet.");
    }/*from www.  j  ava2  s  . com*/
    boolean checkOjbEncryptConfig = true;
    String checkOjbEncryptConfigValue = request.getParameter(CHECK_OJB_ENCRYPT_CONFIG);
    if (!StringUtils.isBlank(checkOjbEncryptConfigValue)) {
        checkOjbEncryptConfig = Boolean.valueOf(checkOjbEncryptConfigValue).booleanValue();
    }
    execute(attributesToEncryptPropertyFileName, checkOjbEncryptConfig);
    response.getOutputStream().write(("<html><body><p>Successfully encrypted attributes as defined in: "
            + attributesToEncryptPropertyFileName + "</p></body></html>").getBytes());
}

From source file:net.paoding.rose.web.paramresolver.ServletRequestDataBinder.java

/**
 * ?/*from www .ja  v  a  2s .  co m*/
 * 
 * Extension point that subclasses can use to add extra bind values
 * for a request. Invoked before {@link #doBind(MutablePropertyValues)}. The
 * default implementation is empty.
 * 
 * @param mpvs
 *            the property values that will be used for data binding
 * @param request
 *            the current request
 */
protected void addBindValues(MutablePropertyValues mpvs, ServletRequest request) {
    String type = request.getParameter("_rest");
    if ((StringUtils.isNotBlank(type)) && (type.equalsIgnoreCase("rest"))) {
        StringBuffer data = new StringBuffer();
        String line = null;
        try {
            BufferedReader reader = request.getReader();
            while ((line = reader.readLine()) != null) {
                data.append(line);
            }
            String jsonStr = data.toString();
            if (StringUtils.isNotBlank(jsonStr)) {
                JSONObject json = JSONObject.fromObject(jsonStr);
                @SuppressWarnings("unchecked")
                Iterator<String> it = json.keys();
                while (it.hasNext()) {
                    String key = it.next();
                    mpvs.addPropertyValue(key, json.get(key));
                }
            }
        } catch (Exception e) {

        }
    }
}

From source file:org.displaytag.filter.ResponseOverrideFilter.java

/**
 * {@inheritDoc}//from  w ww  . jav a 2  s .  com
 */
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {

    if (servletRequest.getParameter(TableTagParameters.PARAMETER_EXPORTING) == null) {
        if (log.isDebugEnabled()) {
            log.debug(Messages.getString("ResponseOverrideFilter.parameternotfound")); //$NON-NLS-1$
        }
        // don't filter!
        filterChain.doFilter(servletRequest, servletResponse);
        return;
    }

    HttpServletRequest request = (HttpServletRequest) servletRequest;

    BufferedResponseWrapper wrapper = new BufferedResponseWrapper13Impl((HttpServletResponse) servletResponse);

    Map contentBean = new HashMap(4);
    if (buffer) {
        contentBean.put(TableTagParameters.BEAN_BUFFER, Boolean.TRUE);
    }
    request.setAttribute(TableTag.FILTER_CONTENT_OVERRIDE_BODY, contentBean);

    filterChain.doFilter(request, wrapper);

    ExportDelegate.writeExport((HttpServletResponse) servletResponse, servletRequest, wrapper);
}

From source file:org.wso2.sample.is.sso.agent.SSOAgentSampleFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {

    String httpBinding = servletRequest.getParameter(SSOAgentConstants.SSOAgentConfig.SAML2.HTTP_BINDING);
    if (httpBinding != null && !httpBinding.isEmpty()) {
        if ("HTTP-POST".equals(httpBinding)) {
            httpBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST";
        } else if ("HTTP-Redirect".equals(httpBinding)) {
            httpBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect";
        } else {/*ww  w  . jav a  2  s.  com*/
            LOGGER.log(Level.INFO, "Unknown SAML2 HTTP Binding. Defaulting to HTTP-POST");
            httpBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST";
        }
    } else {
        LOGGER.log(Level.INFO, "SAML2 HTTP Binding not found in request. Defaulting to HTTP-POST");
        httpBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST";
    }
    SSOAgentConfig config = (SSOAgentConfig) filterConfig.getServletContext()
            .getAttribute(SSOAgentConstants.CONFIG_BEAN_NAME);
    config.getSAML2().setHttpBinding(httpBinding);
    config.getOpenId()
            .setClaimedId(servletRequest.getParameter(SSOAgentConstants.SSOAgentConfig.OpenID.CLAIMED_ID));
    config.getOpenId().setMode(servletRequest.getParameter(SSOAgentConstants.OpenID.OPENID_MODE));

    if (StringUtils.isNotEmpty(servletRequest.getParameter(USERNAME))
            && StringUtils.isNotEmpty(servletRequest.getParameter(PASSWORD))) {

        String authorization = servletRequest.getParameter(USERNAME) + ":"
                + servletRequest.getParameter(PASSWORD);
        // Base64 encoded username:password value
        authorization = new String(Base64.encode(authorization.getBytes(CHARACTER_ENCODING)));
        String htmlPayload = "<html>\n" + "<body>\n" + "<p>You are now redirected back to "
                + properties.getProperty("SAML2.IdPURL") + " \n"
                + "If the redirection fails, please click the post button.</p>\n"
                + "<form method='post' action='" + properties.getProperty("SAML2.IdPURL") + "'>\n"
                + "<input type='hidden' name='sectoken' value='" + authorization + "'/>\n" + "<p>\n"
                + "<!--$saml_params-->\n" + "<button type='submit'>POST</button>\n" + "</p>\n" + "</form>\n"
                + "<script type='text/javascript'>\n" + "document.forms[0].submit();\n" + "</script>\n"
                + "</body>\n" + "</html>";
        config.getSAML2().setPostBindingRequestHTMLPayload(htmlPayload);
    } else {
        // Reset previously sent HTML payload
        config.getSAML2().setPostBindingRequestHTMLPayload(null);
    }
    servletRequest.setAttribute(SSOAgentConstants.CONFIG_BEAN_NAME, config);
    super.doFilter(servletRequest, servletResponse, filterChain);
}

From source file:org.wso2.carbon.identity.captcha.connector.recaptcha.PathBasedReCaptchaConnector.java

private Map<String, String> getConnectorConfigs(ServletRequest servletRequest) throws Exception {

    String tenantDomain = servletRequest.getParameter("tenantDomain");
    if (StringUtils.isBlank(tenantDomain)) {
        tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    }/*from ww w .  java 2  s.  c o m*/

    Map<String, String> connectorConfigs;
    connectorConfigs = identityGovernanceService.getConfiguration(
            new String[] { CONNECTOR_NAME + CaptchaConstants.ReCaptchaConnectorPropertySuffixes.ENABLE,
                    CONNECTOR_NAME + CaptchaConstants.ReCaptchaConnectorPropertySuffixes.SECURED_DESTINATIONS,
                    CONNECTOR_NAME + CaptchaConstants.ReCaptchaConnectorPropertySuffixes.SECURED_PAGES,
                    CONNECTOR_NAME + CaptchaConstants.ReCaptchaConnectorPropertySuffixes.ON_FAIL_REDIRECT_URL },
            tenantDomain);

    return connectorConfigs;
}

From source file:com.google.gerrit.httpd.auth.oauth.OAuthSession.java

private boolean checkState(ServletRequest request) {
    String s = Strings.nullToEmpty(request.getParameter("state"));
    if (!s.equals(state)) {
        log.error("Illegal request state '" + s + "' on OAuthProtocol " + this);
        return false;
    }/*from   w w w  .j  a  v  a  2  s.  c om*/
    return true;
}

From source file:org.acegisecurity.captcha.CaptchaValidationProcessingFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    String captchaResponse = request.getParameter(captchaValidationParameter);

    if ((request != null) && 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");
            }/* w  w w.  ja va2 s. com*/
        } 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);
}