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.sun.faces.lifecycle.LifecycleImpl.java

private boolean reload(PhaseId phaseId, FacesContext context) {

    if (!phaseId.equals(PhaseId.RESTORE_VIEW)) {
        return (false);
    }/*from  w  w w.j  a  v a2 s. c  o  m*/
    if (!(context.getExternalContext().getRequest() instanceof HttpServletRequest)) {
        return (false);
    }
    HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
    String method = request.getMethod();

    // Is this a GET request with query parameters?
    if ("GET".equals(method)) {
        Iterator names = context.getExternalContext().getRequestParameterNames();
        if (names.hasNext()) {
            return (false);
        }
    }

    // Is this a POST or PUT request?
    if ("POST".equals(method) || "PUT".equals(method)) {
        return (false);
    }

    // Assume this is a reload
    return (true);

}

From source file:com.envision.envservice.filter.AccessLogFilter.java

private void logAccessAPI(HttpServletRequest request) {
    try {/*from   ww w .ja  v a2 s  . co  m*/
        UserBo user = (UserBo) request.getSession().getAttribute(Constants.SESSION_USER);
        String userId = user != null ? user.getUser_id() : "NOT_LOGIN";
        String remoteAddr = IPUtil.getRemoteAddr(request);
        String method = request.getMethod();
        String requestURI = request.getRequestURI();
        String userAgent = StringUtils.defaultString(request.getHeader("User-Agent"));

        String queryString = request.getQueryString();
        if (queryString != null) {
            queryString = URLDecoder.decode(request.getQueryString(), Constants.CHARSET);
        }
        requestURI = requestURI
                + (StringUtils.isNotEmpty(queryString) ? ("?" + queryString) : StringUtils.EMPTY);

        EnvLog.getAccessAPILogger().info(
                String.format("[%s] [%s] [%s] %s [%s]", userId, remoteAddr, method, requestURI, userAgent));
    } catch (Exception e) {
        EnvLog.getAccessAPILogger().warn("AccessAPI logger error: " + e.getMessage(), e);
    }
}

From source file:com.vmware.photon.controller.api.common.filters.LoggingFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    if (request instanceof HttpServletRequest) {
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse = (HttpServletResponse) response;
        String requestId = requestIdProvider.get().toString();

        LoggingUtils.setRequestId(requestId);
        logger.debug("Request: {} {}", httpRequest.getMethod(), httpRequest.getPathInfo());

        StopWatch stopwatch = new StopWatch();
        stopwatch.start();//w  w  w.  ja  va  2  s  .  com
        try {
            chain.doFilter(request, response);
        } finally {
            stopwatch.stop();
            String msg = String.format("Response: %s [%s] in %sms", httpRequest.getPathInfo(),
                    httpResponse.getStatus(), stopwatch.getTime());
            if (httpResponse.getStatus() == HttpServletResponse.SC_OK) {
                logger.debug(msg);
            } else {
                logger.info(msg);
            }

            LoggingUtils.clearRequestId();
        }
    } else {
        chain.doFilter(request, response);
    }
}

From source file:io.kamax.mxisd.controller.DefaultExceptionHandler.java

private String handle(HttpServletRequest req, String erroCode, String error) {
    JsonObject obj = new JsonObject();
    obj.addProperty("errcode", erroCode);
    obj.addProperty("error", error);
    obj.addProperty("success", false);
    log.info("Request {} {} - Error {}: {}", req.getMethod(), req.getRequestURL(), erroCode, error);
    return gson.toJson(obj);
}

From source file:com.trendmicro.hdfs.webdav.HDFSWebDAVServlet.java

@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug(request.getMethod() + " for '" + request.getRequestURI() + "' from " + request.getRemoteUser()
                + " at " + request.getRemoteAddr());
    }//from ww  w .j  a v a  2 s  . com
    try {
        super.service(request, response);
    } catch (Exception e) {
        if (e instanceof AccessControlException || e.getCause() instanceof AccessControlException) {
            LOG.info("Insufficient permissions for request for '" + request.getRequestURI() + "' from "
                    + request.getRemoteUser() + " at " + request.getRemoteAddr());
            if (request.getMethod().equalsIgnoreCase("GET")) {
                // Provide a plain 401 response for GETs
                new WebdavResponseImpl(response).sendError(HttpServletResponse.SC_UNAUTHORIZED);
            } else {
                // Otherwise send a multistatus response
                MultiStatus ms = new MultiStatus();
                ms.addResponse(new MultiStatusResponse(request.getRequestURL().toString(), 401,
                        "You do not have permission to access this resource."));
                new WebdavResponseImpl(response).sendMultiStatus(ms);
            }
        } else {
            LOG.warn("Exception processing request for '" + request.getRequestURI() + "' from "
                    + request.getRemoteUser() + " at " + request.getRemoteAddr() + " authType "
                    + request.getAuthType(), e);
            new WebdavResponseImpl(response).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    }
}

From source file:org.alfresco.repo.web.scripts.servlet.jive.JiveToolkitAuthenticatorFactory.java

/**
 * Debugging method for obtaining the state of a request as a String.
 * /*  w w  w.  j a  v a2s.co m*/
 * @param request The request to retrieve the state from <i>(may be null)</i>.
 * @return The request state as a human-readable string value <i>(will not be null)</i>.
 */
private String requestToString(final HttpServletRequest request) {
    StringBuffer result = new StringBuffer(128);

    if (request != null) {
        result.append("\n\tMethod: ");
        result.append(request.getMethod());
        result.append("\n\tURL: ");
        result.append(String.valueOf(request.getRequestURI()));
        result.append("\n\tHeaders: ");

        Enumeration<String> headerNames = request.getHeaderNames();

        while (headerNames.hasMoreElements()) {
            String headerName = headerNames.nextElement();
            String headerValue = request.getHeader(headerName);

            result.append("\n\t\t");
            result.append(headerName);
            result.append(" : ");
            result.append(headerValue);
        }
    } else {
        result.append("(null)");
    }

    return (result.toString());
}

From source file:com.centurylink.mdw.hub.servlet.RestServlet.java

@Override
public void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if ("PATCH".equalsIgnoreCase(request.getMethod())
            || "PATCH".equalsIgnoreCase(request.getHeader("X-HTTP-Method-Override"))) {
        doPatch(request, response);//  www . ja  v  a2 s  .  c  o m
    } else {
        super.service(request, response);
    }
}

From source file:com.cfitzarl.cfjwed.core.security.CsrfValidatingFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletresponse, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    HttpServletResponse response = (HttpServletResponse) servletresponse;

    Authentication authentication = SecurityContextWrapper.getAuthentication();
    String csrfToken = request.getHeader(SessionConstant.CSRF_TOKEN);

    if (!EXCLUDED_METHODS.contains(request.getMethod())) {
        if ((authentication != null) && (authentication instanceof UsernamePasswordAuthenticationToken)) {
            if (!authentication.getDetails().equals(csrfToken)) {
                throw new UnauthorizedException("Invalid or missing CSRF token");
            }//from  w w  w  . j av a  2s .co m
        }
    }

    chain.doFilter(servletRequest, servletresponse);
}

From source file:de.codecentric.boot.admin.zuul.filters.route.SimpleHostRoutingFilter.java

private String getVerb(HttpServletRequest request) {
    String sMethod = request.getMethod();
    return sMethod.toUpperCase();
}

From source file:net.eusashead.hateoas.conditional.interceptor.ConditionalResponseInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    if (request.getMethod().equals(GET)) {
        return preHandleGetOrHead(request, response);
    } else if (request.getMethod().equals(HEAD)) {
        return preHandleGetOrHead(request, response);
    } else if (request.getMethod().equals(PUT)) {
        return preHandlePutOrDelete(request, response);
    } else if (request.getMethod().equals(DELETE)) {
        return preHandlePutOrDelete(request, response);
    }/*w w w .  j  a v  a2 s.  c  o m*/
    return true;
}