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.rsginer.spring.filters.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())) {
        LOG.trace("Sending Header....");
        // CORS "pre-flight" request
        response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
        //         response.addHeader("Access-Control-Allow-Headers", "Authorization");
        response.addHeader("Access-Control-Allow-Headers", "Content-Type");
        response.addHeader("Access-Control-Max-Age", "1");
    }/*from ww w.jav  a2 s. c o m*/

    filterChain.doFilter(request, response);
}

From source file:com.idega.servlet.filter.CacheFilter.java

/**
 * <p>// ww  w  . ja  v a  2 s  .  com
 * TODO tryggvil describe method cacheRequest
 * </p>
 * @param request
 * @param response
 * @return
 */
protected boolean cacheRequest(HttpServletRequest request, HttpServletResponse response) {
    checkInitialization();
    if (defaultEnabled) {
        String method = request.getMethod();
        if (method.equals(METHOD_GET)) {
            LoginBusinessBean loginBusiness = LoginBusinessBean.getLoginBusinessBean(request);
            if (loginBusiness.isLoggedOn(request)) {
                //Never cache for a logged on user:
                return false;
            }
            return true;
        }
    }
    return false;
}

From source file:net.community.chest.gitcloud.facade.backend.git.GitBackendServlet.java

private void logHeaders(HttpServletRequest req, Map<String, String> hdrsMap, String hdrsType) {
    for (Map.Entry<String, String> hdrEntry : hdrsMap.entrySet()) {
        String hdrName = hdrEntry.getKey(), hdrValue = hdrEntry.getValue();
        logger.trace("service(" + req.getMethod() + ")[" + req.getRequestURI() + "][" + req.getQueryString()
                + "]" + " " + hdrsType + " " + hdrName + ": " + hdrValue);
    }//from   w w  w.ja  v a  2s.  c om
}

From source file:business.security.CustomLoggingInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    log.trace(String.format("%s\t%s\t%s\t%s\t%s", new Date(), request.getRemoteAddr(),
            request.getUserPrincipal() == null ? " - " : request.getUserPrincipal().getName(),
            request.getMethod(), request.getRequestURI()));
    return super.preHandle(request, response, handler);
}

From source file:com.twinsoft.convertigo.engine.util.HttpServletRequestTwsWrapper.java

public HttpServletRequestTwsWrapper(HttpServletRequest request) {
    super(request);
    try {//from   w  ww .j a  va2s  .c  om
        if (request.getCharacterEncoding() == null) {
            request.setCharacterEncoding("UTF-8");
        }

        if (request.getMethod().equalsIgnoreCase("PUT")
                && MimeType.WwwForm.is(HeaderName.ContentType.getHeader(request))) {
            try {
                String content = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
                addQuery(content);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        // parse GET parameters
        addQuery(request.getQueryString());

        // retrieve POST parameters ( == not defined in GET )
        for (Entry<String, String[]> entry : GenericUtils.<Map<String, String[]>>cast(request.getParameterMap())
                .entrySet()) {
            if (!parameters.containsKey(entry.getKey())) {
                parameters.put(entry.getKey(), entry.getValue());
            }
        }
    } catch (UnsupportedEncodingException e) {
        parameters.clear();
        parameters.putAll(GenericUtils.<Map<String, String[]>>cast(request.getParameterMap()));
    }
}

From source file:belajar.nfc.controller.OptionsController.java

@RequestMapping(value = "/{id}", method = RequestMethod.OPTIONS)
public void handleOptionsUserWithId(@PathVariable String id, HttpServletRequest request,
        HttpServletResponse response) {//w  w w .  ja  va 2 s  .  c o m
    String host = request.getHeader("Host");
    String origin = request.getHeader("Origin");
    LOGGER.info("Options Controller URI [{}] method [{}] headers [{}] ipserver [{}]",
            new Object[] { request.getRequestURI(), request.getMethod(), origin, host });
}

From source file:com.boundlessgeo.geoserver.api.controllers.ConfigurationLockInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    if (THREAD_LOCK.get() != null) {
        throw new RuntimeException("existing lock found on " + request.getPathInfo());
    }//from   w w  w  . j a v a 2 s .c  o m
    String method = request.getMethod().toLowerCase();
    GeoServerConfigurationLock.LockType lockType;
    switch (method) {
    case "get":
    case "head":
    case "options":
        lockType = GeoServerConfigurationLock.LockType.READ;
        break;
    default:
        // defaulting to a write lock is probably the safest bet here
        // unless a new, popular read method is invented sometime...
        lockType = GeoServerConfigurationLock.LockType.WRITE;
    }
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("DEBUG LOCK: " + lockType);
    }
    THREAD_LOCK.set(lockType);
    lock().lock(lockType);
    return true;
}

From source file:com.laxser.blitz.web.RequestPath.java

private ReqMethod parseMethod(HttpServletRequest request) {
    ReqMethod reqMethod = ReqMethod.parse(request.getMethod());
    if (reqMethod != null && reqMethod.equals(ReqMethod.POST)) {
        // ?getParameter
        // 1?_method?queryString?body
        // 2?getParameterencodingUTF-8? ????
        String queryString = request.getQueryString();
        if (queryString != null) {
            boolean methodChanged = false;
            int start = queryString.indexOf("_method=");
            if (start == 0 || (start > 0 && queryString.charAt(start - 1) == '&')) {
                int end = queryString.indexOf('&', start);
                String method = queryString.substring(start + "_method=".length(), //
                        end > 0 ? end : queryString.length());
                ReqMethod _reqMethod = ReqMethod.parse(method);
                if (_reqMethod != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("override http method from POST to " + _reqMethod);
                    }//  w w w  . j a va2 s.c  om
                    reqMethod = _reqMethod;
                    methodChanged = true;
                }
            }
            if (!methodChanged) {
                int inBodyStart = queryString.indexOf("_method_in_body=1");
                if (inBodyStart == 0 || (inBodyStart > 0 && queryString.charAt(inBodyStart - 1) == '&')) {
                    String method = request.getParameter("_method");
                    ReqMethod _reqMethod = ReqMethod.parse(method);
                    if (_reqMethod != null) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("override http method from POST to " + _reqMethod);
                        }
                        reqMethod = _reqMethod;
                        methodChanged = true;
                    }
                }
            }
        }
    }
    return reqMethod;
}

From source file:org.openqa.grid.selenium.proxy.DefaultRemoteProxy.java

public void afterCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) {
    session.put("lastCommand", request.getMethod() + " - " + request.getPathInfo() + " executing ...");
}

From source file:org.openqa.grid.selenium.proxy.DefaultRemoteProxy.java

public void beforeCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) {
    session.put("lastCommand", request.getMethod() + " - " + request.getPathInfo() + " executed.");
}