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.easou.common.util.CommonUtils.java

/**
 * Safe method for retrieving a parameter from the request without
 * disrupting the reader UNLESS the parameter actually exists in the query
 * string.//from w w w .jav  a  2s .  c o m
 * <p>
 * Note, this does not work for POST Requests for "logoutRequest". It works
 * for all other CAS POST requests because the parameter is ALWAYS in the
 * GET request.
 * <p>
 * If we see the "logoutRequest" parameter we MUST treat it as if calling
 * the standard request.getParameter.
 * 
 * @param request
 *            the request to check.
 * @param parameter
 *            the parameter to look for.
 * @return the value of the parameter.
 */
public static String safeGetParameter(final HttpServletRequest request, final String parameter) {
    if ("POST".equals(request.getMethod()) && "logoutRequest".equals(parameter)) {
        LOG.debug(
                "safeGetParameter called on a POST HttpServletRequest for LogoutRequest.  Cannot complete check safely.  Reverting to standard behavior for this Parameter");
        return request.getParameter(parameter);
    }
    return request.getQueryString() == null || request.getQueryString().indexOf(parameter) == -1 ? null
            : request.getParameter(parameter);
}

From source file:gr.abiss.calipso.userDetails.util.SecurityUtil.java

public static void login(HttpServletRequest request, HttpServletResponse response,
        ICalipsoUserDetails userDetails, UserDetailsConfig userDetailsConfig,
        UserDetailsService userDetailsService) {
    if (LOGGER.isDebugEnabled()) {
        if (userDetails != null) {
            LOGGER.debug(request.getMethod() + " login, userDetails email: " + userDetails.getEmail() + ", un: "
                    + userDetails.getUsername() + ", non-blank pw: "
                    + StringUtils.isNotBlank(userDetails.getPassword()));
        }/*from   ww w .  jav a 2 s .c o  m*/
    }
    if (userDetails != null && StringUtils.isNotBlank(userDetails.getUsername())
            && StringUtils.isNotBlank(userDetails.getPassword())) {
        String token = new String(
                Base64.encode((userDetails.getUsername() + ":" + userDetails.getPassword()).getBytes()));
        addCookie(request, response, userDetailsConfig.getCookiesBasicAuthTokenName(), token, false,
                userDetailsConfig);
        userDetailsService.updateLastLogin(userDetails);
    } else {
        LOGGER.warn("Login failed, force logout to clean any stale cookies");
        SecurityUtil.logout(request, response, userDetailsConfig);
        throw new BadCredentialsException("The provided user details are incomplete");
    }

}

From source file:com.meltmedia.cadmium.servlets.FileServletTest.java

public static HttpServletRequest mockGet(String pathInfo) {
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getMethod()).thenReturn(GET_METHOD);
    when(request.getRequestURI()).thenReturn(pathInfo);
    when(request.getDateHeader(anyString())).thenReturn(new Long(-1));
    when(request.getHeader(anyString())).thenReturn(null);
    return request;
}

From source file:com.meltmedia.cadmium.servlets.FileServletTest.java

public static HttpServletRequest mockGetWithGzip(String pathInfo) {
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getMethod()).thenReturn(GET_METHOD);
    when(request.getRequestURI()).thenReturn(pathInfo);
    when(request.getDateHeader(anyString())).thenReturn(new Long(-1));
    when(request.getHeader(ACCEPT_ENCODING_HEADER)).thenReturn("gzip");
    return request;
}

From source file:com.meltmedia.cadmium.servlets.FileServletTest.java

public static HttpServletRequest mockGetWithoutGzip(String pathInfo) {
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getMethod()).thenReturn(GET_METHOD);
    when(request.getRequestURI()).thenReturn(pathInfo);
    when(request.getDateHeader(anyString())).thenReturn(new Long(-1));
    when(request.getHeader(ACCEPT_ENCODING_HEADER)).thenReturn("gzip;q=0");
    return request;
}

From source file:org.artifactory.webapp.servlet.RequestUtils.java

public static boolean isWebdavRequest(HttpServletRequest request) {
    if (!isRepoRequest(request)) {
        return false;
    }//from  w  ww.j a va 2s .c o m
    if (WebdavService.WEBDAV_METHODS.contains(request.getMethod().toLowerCase(Locale.ENGLISH))) {
        return true;
    }
    String wagonProvider = request.getHeader("X-wagon-provider");
    return wagonProvider != null && wagonProvider.contains("webdav");
}

From source file:org.artifactory.webapp.servlet.RepoFilter.java

private static String requestDebugString(HttpServletRequest request) {
    String queryString = request.getQueryString();
    String str = request.getMethod() + " (" + new HttpAuthenticationDetails(request).getRemoteAddress() + ") "
            + RequestUtils.getServletPathFromRequest(request) + (queryString != null ? queryString : "");
    return str;/* www  .  j  a  v a 2s.c o  m*/
}

From source file:gov.loc.ndmso.proxyfilter.RequestProxy.java

private static HttpMethod setupProxyRequest(final HttpServletRequest hsRequest, final URL targetUrl)
        throws IOException {
    final String methodName = hsRequest.getMethod();
    final HttpMethod method;
    if ("POST".equalsIgnoreCase(methodName)) {
        PostMethod postMethod = new PostMethod();
        InputStreamRequestEntity inputStreamRequestEntity = new InputStreamRequestEntity(
                hsRequest.getInputStream());
        postMethod.setRequestEntity(inputStreamRequestEntity);
        method = postMethod;//w  w  w. j a v a2  s  . co m
    } else if ("GET".equalsIgnoreCase(methodName)) {
        method = new GetMethod();
    } else {
        // log.warn("Unsupported HTTP method requested: " + hsRequest.getMethod());
        return null;
    }

    method.setFollowRedirects(false);
    method.setPath(targetUrl.getPath());
    method.setQueryString(targetUrl.getQuery());

    @SuppressWarnings("unchecked")
    Enumeration<String> e = hsRequest.getHeaderNames();
    if (e != null) {
        while (e.hasMoreElements()) {
            String headerName = e.nextElement();
            if ("host".equalsIgnoreCase(headerName)) {
                //the host value is set by the http client
                continue;
            } else if ("content-length".equalsIgnoreCase(headerName)) {
                //the content-length is managed by the http client
                continue;
            } else if ("accept-encoding".equalsIgnoreCase(headerName)) {
                //the accepted encoding should only be those accepted by the http client.
                //The response stream should (afaik) be deflated. If our http client does not support
                //gzip then the response can not be unzipped and is delivered wrong.
                continue;
            } else if (headerName.toLowerCase().startsWith("cookie")) {
                //fixme : don't set any cookies in the proxied request, this needs a cleaner solution
                continue;
            }

            @SuppressWarnings("unchecked")
            Enumeration<String> values = hsRequest.getHeaders(headerName);
            while (values.hasMoreElements()) {
                String headerValue = values.nextElement();
                // log.info("setting proxy request parameter:" + headerName + ", value: " + headerValue);
                method.addRequestHeader(headerName, headerValue);
            }
        }
    }

    // add rs5/tomcat5 request header for ML
    method.addRequestHeader("X-Via", "tomcat5");

    // log.info("proxy query string " + method.getQueryString());
    return method;
}

From source file:eu.eidas.node.logging.LoggingUtil.java

public static void logServletCall(HttpServletRequest request, final String className, final Logger logger) {
    if (!StringUtils.isEmpty(request.getRemoteHost())) {
        MDC.put(LoggingMarkerMDC.MDC_REMOTE_HOST, request.getRemoteHost());
    }//from   ww  w .  j a  v a 2 s.c  o m
    MDC.put(LoggingMarkerMDC.MDC_SESSIONID, request.getSession().getId());
    logger.info(LoggingMarkerMDC.WEB_EVENT,
            "**** CALL to servlet " + className + " FROM " + request.getRemoteAddr() + " HTTP "
                    + request.getMethod() + " SESSIONID " + request.getSession().getId() + "****");

}

From source file:com.google.appengine.tools.mapreduce.MapReduceServletTest.java

private static HttpServletRequest createMockStartJobRequest(Configuration conf) {
    HttpServletRequest request = createMockRequest(
            MapReduceServlet.COMMAND_PATH + "/" + MapReduceServlet.START_JOB_PATH, false, true);
    expect(request.getMethod()).andReturn("POST").anyTimes();
    return request;
}