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:cn.guoyukun.spring.web.utils.ServletUtils.java

/**
 * url?method firstPrefix+lastPrefixes//from  w w  w.  jav  a 2  s .co m
 * ?url/sample/create ?firstPrefix:/sample lastPrefixed /create
 *
 * @param request
 * @param method       
 * @param firstPrefix
 * @param lastPrefixes
 * @return
 */
public static boolean startWith(HttpServletRequest request, RequestMethod method, String firstPrefix,
        String... lastPrefixes) {
    String requestMethod = request.getMethod();
    if (!requestMethod.equalsIgnoreCase(method.name())) {
        return false;
    }
    String url = request.getServletPath();
    if (!url.startsWith(firstPrefix)) {
        return false;
    }

    if (lastPrefixes.length == 0) {
        return true;
    }

    url = url.substring(firstPrefix.length());
    for (String lastPrefix : lastPrefixes) {
        if (url.startsWith(lastPrefix)) {
            return true;
        }
    }

    return false;
}

From source file:au.gov.ansto.bragg.nbi.restlet.fileupload.servlet.ServletFileUpload.java

/**
 * Utility method that determines whether the request contains multipart
 * content./*from  w w  w.jav  a  2 s. co m*/
 *
 * @param request The servlet request to be evaluated. Must be non-null.
 *
 * @return <code>true</code> if the request is multipart;
 *         <code>false</code> otherwise.
 */
public static final boolean isMultipartContent(HttpServletRequest request) {
    if (!POST_METHOD.equalsIgnoreCase(request.getMethod())) {
        return false;
    }
    return FileUploadBase.isMultipartContent(new ServletRequestContext(request));
}

From source file:de.micromata.genome.logging.LogRequestDumpAttribute.java

/**
 * Gen http request dump./*  w w  w .j  av  a2 s.c  om*/
 *
 * @param req the req
 * @return the string
 */
@SuppressWarnings("unchecked")
public static String genHttpRequestDump(HttpServletRequest req) {
    StringBuilder sb = new StringBuilder();

    sb.append("method: ").append(req.getMethod()).append('\n')//
            .append("requestURL: ").append(req.getRequestURL()).append('\n')//
            .append("servletPath: ").append(req.getServletPath()).append('\n')//
            .append("requestURI: ").append(req.getRequestURI()).append('\n') //
            .append("queryString: ").append(req.getQueryString()).append('\n') //
            .append("pathInfo: ").append(req.getPathInfo()).append('\n')//
            .append("contextPath: ").append(req.getContextPath()).append('\n') //
            .append("characterEncoding: ").append(req.getCharacterEncoding()).append('\n') //
            .append("localName: ").append(req.getLocalName()).append('\n') //
            .append("contentLength: ").append(req.getContentLength()).append('\n') //
    ;
    sb.append("Header:\n");
    for (Enumeration<String> en = req.getHeaderNames(); en.hasMoreElements();) {
        String hn = en.nextElement();
        sb.append("  ").append(hn).append(": ").append(req.getHeader(hn)).append("\n");
    }
    sb.append("Attr: \n");
    Enumeration en = req.getAttributeNames();
    for (; en.hasMoreElements();) {
        String k = (String) en.nextElement();
        Object v = req.getAttribute(k);
        sb.append("  ").append(k).append(": ").append(Objects.toString(v, StringUtils.EMPTY)).append('\n');
    }

    return sb.toString();
}

From source file:de.xwic.appkit.core.remote.server.ParameterProvider.java

/**
 * @param request/*from   ww w  . j av  a2  s. c  om*/
 * @return
 */
private static final boolean isMultipart(final HttpServletRequest request) {
    if (!"POST".equalsIgnoreCase(request.getMethod())) {
        return false;
    }
    String contentType = request.getContentType();
    if (contentType == null) {
        return false;
    }
    return contentType.toLowerCase().startsWith("multipart/");
}

From source file:mojo.view.util.DebugUtils.java

public static void logRequestInfo(HttpServletRequest req) {
    logger.debug("session.id          : " + req.getSession().getId());
    logger.debug("request.method      : " + req.getMethod());
    logger.debug("request.pathInfo    : " + req.getPathInfo());
    logger.debug("request.requestURI  : " + req.getRequestURI());
    logger.debug("request.requestURL  : " + req.getRequestURL());
    logger.debug("request.queryString : " + req.getQueryString());
    logger.debug("");

    logRequestHeaders(req);// ww w  .j a  va 2s  . c  o  m
    logRequestParameters(req);
    logRequestAttributes(req);
}

From source file:ee.ria.xroad.proxy.clientproxy.AbstractClientProxyHandler.java

protected static boolean isGetRequest(HttpServletRequest request) {
    return request.getMethod().equalsIgnoreCase("GET");
}

From source file:ee.ria.xroad.proxy.clientproxy.AbstractClientProxyHandler.java

protected static boolean isPostRequest(HttpServletRequest request) {
    return request.getMethod().equalsIgnoreCase("POST");
}

From source file:ch.ralscha.extdirectspring.util.ExtDirectSpringUtil.java

/**
 * Checks if the request is a multipart request
 *
 * @param request the HTTP servlet request
 * @return true if request is a Multipart request (file upload)
 *///from ww w . ja v a 2 s  .c o  m
public static boolean isMultipart(HttpServletRequest request) {
    if (!"post".equals(request.getMethod().toLowerCase())) {
        return false;
    }
    String contentType = request.getContentType();
    return contentType != null && contentType.toLowerCase().startsWith("multipart/");
}

From source file:org.pac4j.cas.client.CasClientWrapper.java

public static boolean isLogoutRequest(final HttpServletRequest request) {
    return "POST".equals(request.getMethod()) && !isMultipartRequest(request)
            && CommonUtils.isNotBlank(CommonUtils.safeGetParameter(request, logoutParameterName));
}

From source file:com.adeptj.modules.security.core.credential.UsernamePasswordCredential.java

public static UsernamePasswordCredential from(HttpServletRequest request) {
    String username = request.getParameter(PARAM_USERNAME);
    String password = request.getParameter(PARAM_PWD);
    if (METHOD_POST.equals(request.getMethod())
            && StringUtils.endsWith(request.getRequestURI(), LOGIN_URI_SUFFIX)
            && StringUtils.isNoneEmpty(username, password)) {
        return new UsernamePasswordCredential(username, password.toCharArray());
    }//w ww. j a  va 2 s  . co  m
    return null;
}