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.erudika.para.security.RestAuthFilter.java

private boolean isWriteRequest(HttpServletRequest req) {
    return req != null && ("POST".equals(req.getMethod()) || "PUT".equals(req.getMethod())
            || "DELETE".equals(req.getMethod()) || "PATCH".equals(req.getMethod()));
}

From source file:com.rest.api.CORSFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {

    response.addHeader("Access-Control-Allow-Origin", "*");
    if (request.getHeader("Access-Control-Request-Method") != null && "OPTIONS".equals(request.getMethod())) {
        response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
        response.addHeader("Access-Control-Allow-Headers", "Content-Type");
        response.addHeader("Access-Control-Max-Age", "1");
    }//from   w  w  w .ja va  2 s.  c o  m
    filterChain.doFilter(request, response);
}

From source file:com.lm.lic.manager.util.GenUtil.java

/**
 * @param request//from w w  w. ja  v a  2 s  .  c om
 */
@SuppressWarnings("unchecked")
public static void debugRequestParams(HttpServletRequest request) {
    Enumeration<String> en = request.getParameterNames();
    while (en.hasMoreElements()) {
        String p = en.nextElement();
        String v = request.getParameter(p);
        System.out.println("\nPARAM: " + p);
        System.out.println("VALUE: " + v);
    }

    en = request.getHeaderNames();
    while (en.hasMoreElements()) {
        String p = en.nextElement();
        String v = request.getParameter(p);
        System.out.println("\nPHEADER: " + p);
        System.out.println("VALUE: " + v);
    }

    String qs = request.getQueryString();
    System.out.println("QueryString: " + qs);
    String method = request.getMethod();
    System.out.println("Method: " + method);
}

From source file:org.apache.hadoop.gateway.dispatch.GatewayDispatchFilter.java

@Override
protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    String method = request.getMethod().toUpperCase();
    Adapter adapter = METHOD_ADAPTERS.get(method);
    if (adapter != null) {
        try {/* www  . j  a v a  2s . co m*/
            adapter.doMethod(dispatch, request, response);
        } catch (URISyntaxException e) {
            throw new ServletException(e);
        }
    } else {
        response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
    }
}

From source file:gov.nih.nci.cabig.caaers.web.filters.CsrfPreventionFilter.java

public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws ServletException, IOException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) resp;
    initializeCsfrToken(request);// w ww. j a v  a 2 s .c  o  m

    if (request.getMethod().toUpperCase().equals("POST") && !isAllowedURI(request.getRequestURI())) {
        boolean isValidRequest = isValidCsrfToken(request);
        if (!isValidRequest) {
            response.sendError(403);
            return;
        }
    }

    chain.doFilter(request, response);
}

From source file:com.baomidou.framework.aop.ResubmitAspect.java

/**
 * <p>/*from  w ww .  j  a  va  2 s  . com*/
 * ?
 * </p>
 * 
 * @param joinPoint
 *            ?
 * @param formToken
 *            ??
 * @throws Throwable
 */
@Around("@annotation(formToken)")
public void execute(ProceedingJoinPoint joinPoint, FormToken formToken) throws Throwable {
    Object[] args = joinPoint.getArgs();
    String className = joinPoint.getTarget().getClass().getName();
    for (Object arg : args) {
        if (arg != null && arg instanceof HttpServletRequest) {
            HttpServletRequest request = (HttpServletRequest) arg;
            HttpSession session = request.getSession(true);
            if (formToken != null) {
                if ("GET".equalsIgnoreCase(request.getMethod())) {
                    /* GET ? token */
                    this.generate(joinPoint, request, session, PARAM_TOKEN_FLAG + className);
                } else {
                    /* POST ? token */
                    this.validation(joinPoint, request, session, PARAM_TOKEN_FLAG + className);
                }
            }
        }
    }
}

From source file:dinamica.util.matcher.AntPathRequestMatcher.java

/**
 * Returns true if the configured pattern (and HTTP-Method) match those of the
 * supplied request.//from   w w w .  j a va 2 s. c o m
 *
 * @param request the request to match against. The ant pattern will be matched
 * against the {@code servletPath} + {@code pathInfo} of the request.
 */
public boolean matches(HttpServletRequest request) {
    if (httpMethod != null && StringUtils.hasText(request.getMethod())
            && httpMethod != valueOf(request.getMethod())) {
        if (logger.isDebugEnabled()) {
            logger.debug("Request '" + request.getMethod() + " " + getRequestPath(request) + "'"
                    + " doesn't match '" + httpMethod + " " + pattern);
        }

        return false;
    }

    if (pattern.equals(MATCH_ALL)) {
        if (logger.isDebugEnabled()) {
            logger.debug("Request '" + getRequestPath(request) + "' matched by universal pattern '/**'");
        }

        return true;
    }

    String url = getRequestPath(request);

    if (logger.isDebugEnabled()) {
        logger.debug("Checking match of request : '" + url + "'; against '" + pattern + "'");
    }

    return matcher.matches(url);
}

From source file:com.jpeterson.littles3.StorageEngine.java

/**
 * Returns the HTTP method of the request. Implements logic to allow an
 * "override" method, specified by the header
 * <code>HEADER_HTTP_METHOD_OVERRIDE</code>. If the override method is
 * provided, it takes precedence over the actual method derived from
 * <code>request.getMethod()</code>.
 * //from w ww.j av  a2s.  c o m
 * @param request
 *            The request being processed.
 * @return The method of the request.
 * @see #HEADER_HTTP_METHOD_OVERRIDE
 */
public static String getMethod(HttpServletRequest request) {
    String method;

    method = request.getHeader(HEADER_HTTP_METHOD_OVERRIDE);

    if (method == null) {
        method = request.getMethod();
    }

    return method;
}

From source file:eu.freme.broker.security.AuthenticationFilter.java

private boolean postToAuthenticate(HttpServletRequest httpRequest, String resourcePath) {
    return BaseRestController.authenticationEndpoint.equalsIgnoreCase(resourcePath)
            && httpRequest.getMethod().equals("POST");
}

From source file:org.focusns.common.web.performance.MonitorFilter.java

private String getRequestDescription(HttpServletRequest request) {
    StringBuilder sb = new StringBuilder(request.getRequestURI());
    if (StringUtils.hasText(request.getQueryString())) {
        sb.append("?").append(request.getQueryString());
    }/* w ww .j  a va2 s  .co  m*/
    sb.append(" [").append(request.getMethod()).append("]");
    return sb.toString();
}