Example usage for javax.servlet.http HttpServletRequest getMethod

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

Introduction

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

Prototype

public String getMethod();

Source Link

Document

Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.

Usage

From source file:com.acciente.commons.htmlform.Parser.java

/**
 * This method parses all the parameters contained in the http servlet request, in particular it parses and
 * merges parameters from the sources listed below. If a parameter is defined in more than on source the higher
 * numbered source below prevails.//w  ww .  jav  a 2s.  c om
 *
 *    1  - parameters in the URL's query query string (GET params)
 *    2  - parameters submitted using POST including multi-part parameters such as fileuploads
 *
 * @param oRequest a http servlet request object
 * @param iStoreFileOnDiskThresholdInBytes a file size in bytes above which the uploaded file will be stored on disk
 * @param oUploadedFileStorageDir a File object representing a path to which the uploaded files should be saved,
 * if null is specified a temporary directory is created in the java system temp directory path
 *
 * @return a map containing the paramater names and values, the paramter names are keys in the map
 *
 * @throws ParserException thrown if there is an error parsing the parameter data
 * @throws IOException thrown if there is an I/O error
 * @throws FileUploadException thrown if there is an error processing the multi-part data
 */
public static Map parseForm(HttpServletRequest oRequest, int iStoreFileOnDiskThresholdInBytes,
        File oUploadedFileStorageDir) throws ParserException, IOException, FileUploadException {
    Map oGETParams = null;

    // first process the GET parameters (if any)
    if (oRequest.getQueryString() != null) {
        oGETParams = parseGETParams(oRequest);
    }

    Map oPOSTParams = null;

    // next process POST parameters
    if ("post".equals(oRequest.getMethod().toLowerCase())) {
        // check how the POST data has been encoded
        if (ServletFileUpload.isMultipartContent(oRequest)) {
            oPOSTParams = parsePOSTMultiPart(oRequest, iStoreFileOnDiskThresholdInBytes,
                    oUploadedFileStorageDir);
        } else {
            // we have plain text
            oPOSTParams = parsePOSTParams(oRequest);
        }
    }

    Map oMergedParams;

    // merge the GET and POST parameters
    if (oGETParams != null) {
        oMergedParams = oGETParams;

        if (oPOSTParams != null) {
            oMergedParams.putAll(oPOSTParams);
        }
    } else {
        // we know that the oGETParams must be null
        oMergedParams = oPOSTParams;
    }

    return oMergedParams;
}

From source file:org.mitre.eidas.CsrfSecurityRequestMatcher.java

@Override
public boolean matches(HttpServletRequest request) {
    if (allowedMethods.matcher(request.getMethod()).matches()) {
        return false;
    }/* w  ww.ja v  a2  s  .c o  m*/

    return !unprotectedMatcher.matches(request);
}

From source file:org.italiangrid.storm.webdav.authz.util.CustomMethodAntPathRequestMatcher.java

@Override
public boolean matches(HttpServletRequest request) {

    if (request.getMethod() != null && !request.getMethod().equals(httpOrDAVMethod)) {
        if (logger.isDebugEnabled()) {
            logger.debug("Request '" + request.getMethod() + " " + getRequestPath(request) + "'"
                    + " doesn't match '" + httpOrDAVMethod + " " + antMatcher.getPattern());
        }//from  w  w w  .j  a v  a  2s. com
        return false;
    }

    // Method matches, delegate down request match
    return antMatcher.matches(request);

}

From source file:com.gisnet.cancelacion.config.CsrfUrlMatcher.java

@Override
public boolean matches(HttpServletRequest request) {
    if (allowedMethods.matcher(request.getMethod()).matches()) {
        return false;
    }/*  www  .ja v a  2 s .c  om*/
    for (AntPathRequestMatcher ant : requestMatchers) {
        if (ant.matches(request)) {
            return false;
        }
    }

    return true;
}

From source file:cherry.foundation.springmvc.CsrfRequestMatcher.java

@Override
public boolean matches(HttpServletRequest request) {
    if (allowedMethods.matcher(request.getMethod()).matches()) {
        return false;
    }//w  w  w .  j  a  v  a2s . c o  m
    for (RequestMatcher matcher : excludes) {
        if (matcher.matches(request)) {
            return false;
        }
    }
    return true;
}

From source file:org.jasig.cas.support.openid.web.support.OpenIdPostUrlHandlerMapping.java

@Override
protected Object lookupHandler(final String urlPath, final HttpServletRequest request) throws Exception {

    if ("POST".equals(request.getMethod())
            && (("check_authentication".equals(request.getParameter("openid.mode")))
                    || ("associate".equals(request.getParameter("openid.mode"))))) {
        return super.lookupHandler(urlPath, request);
    }/*  w  w  w  .ja v  a 2 s. co m*/

    return null;
}

From source file:com.firstclarity.magnolia.study.blossom.sample.ContactFormComponent.java

@RequestMapping("/contact")
public String handleRequest(@ModelAttribute ContactForm contactForm, BindingResult result,
        HttpServletRequest request) {

    if ("POST".equals(request.getMethod())) {

        new ContactFormValidator().validate(contactForm, result);
        if (result.hasErrors()) {
            return "mymodule/components/contactForm.jsp";
        }/*from   www  .  j av a 2 s .  co m*/

        return "mymodule/components/contactFormSubmitted.jsp";
    }

    return "mymodule/components/contactForm.jsp";
}

From source file:org.italiangrid.storm.webdav.authz.util.ReadonlyHTTPMethodMatcher.java

@Override
public boolean matches(HttpServletRequest request) {

    if (request.getMethod() == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("null method in incoming request will not match this matcher.");
        }/*from ww  w .  j  a  v a  2  s.c  om*/
        return false;
    }

    final boolean methodMatches = METHODS.contains(request.getMethod());

    if (logger.isDebugEnabled() && !methodMatches) {
        logger.debug("Request method '{} {}' does not match with this matcher.", request.getMethod(),
                getRequestPath(request));
        return methodMatches;
    }

    return methodMatches && pathMatcher.matches(request);

}

From source file:org.uaa.security.core.AuthorizationManager.java

public void decide(UsernamePasswordToken token, HttpServletRequest request) throws AccessDeniedException {
    String action = request.getMethod().toUpperCase();
    String uri = request.getRequestURI();
    String context = request.getContextPath();
    log.debug(uri.replace(context, ""));

    List<Integer> roles = token.getRoles();

    if (!SecuritySupport.isAllowed(action, uri.replace(context, ""), roles)) {
        log.info("you don't have needed authorities to access this resource");
        throw new AccessDeniedException("you don't have needed authorities to access this resource");
    }/*from   w  ww  . ja  v  a  2s.co  m*/
}

From source file:com.evolveum.midpoint.web.security.MidPointAccessDeniedHandler.java

private boolean isLoginLogoutRequest(HttpServletRequest req) {
    if (!"post".equalsIgnoreCase(req.getMethod())) {
        return false;
    }//from  w ww.j a  va2 s  . c o  m

    String uri = req.getRequestURI();
    return createUri(req, "/j_spring_security_logout").equals(uri)
            || createUri(req, "/spring_security_login").equals(uri);
}