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:net.community.chest.gitcloud.facade.backend.git.GitBackendServlet.java

@Override
protected void service(HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException {
    if (logger.isDebugEnabled()) {
        logger.debug(// w w  w  .  ja  v a2  s .c  o m
                "service(" + req.getMethod() + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]");
    }

    if (logger.isTraceEnabled()) {
        logHeaders(req, ServletUtils.getRequestHeaders(req), "REQ");
    }

    super.service(req, rsp);

    if (logger.isDebugEnabled()) {
        logger.debug("service(" + req.getMethod() + ")[" + req.getRequestURI() + "][" + req.getQueryString()
                + "]" + " Content-Type: " + rsp.getContentType() + ", status=" + rsp.getStatus());
    }

    if (logger.isTraceEnabled()) {
        logHeaders(req, ServletUtils.getResponseHeaders(rsp), "RSP");
    }
}

From source file:com.softwarementors.extjs.djn.servlet.DirectJNgineServlet.java

private static RequestType getFromRequestContentType(HttpServletRequest request) {
    assert request != null;

    String contentType = request.getContentType();
    String pathInfo = request.getPathInfo();

    if (!StringUtils.isEmpty(pathInfo) && pathInfo.startsWith(PollRequestProcessor.PATHINFO_POLL_PREFIX)) {
        return RequestType.POLL;
    } else if (StringUtils.startsWithCaseInsensitive(contentType, "application/json")) {
        return RequestType.JSON;
    } else if (StringUtils.startsWithCaseInsensitive(contentType, "application/x-www-form-urlencoded")
            && request.getMethod().equalsIgnoreCase("post")) {
        return RequestType.FORM_SIMPLE_POST;
    } else if (ServletFileUpload.isMultipartContent(request)) {
        return RequestType.FORM_UPLOAD_POST;
    } else if (RequestRouter.isSourceRequest(pathInfo)) {
        return RequestType.SOURCE;
    } else {//from   w  ww. j ava 2  s .co  m
        String requestInfo = ServletUtils.getDetailedRequestInformation(request);
        RequestException ex = RequestException.forRequestFormatNotRecognized();
        logger.error("Error during file uploader: " + ex.getMessage() + "\nAdditional request information: "
                + requestInfo, ex);
        throw ex;
    }
}

From source file:de.devbliss.apitester.dummyserver.DummyRequestHandler.java

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    ApiTest.HTTP_REQUEST method = ApiTest.HTTP_REQUEST.valueOf(request.getMethod());

    switch (method) {
    case GET:/*w  w w  .  java 2s .  com*/
        handleGet(target, response);
        break;
    case POST:
    case PATCH:
    case PUT:
        handlePostPatchPut(target, request, response);
        break;
    }

    baseRequest.setHandled(true);
}

From source file:org.deegree.securityproxy.authentication.wass.AddParameterAnonymousAuthenticationFilterTest.java

private HttpServletRequest mockRequest(String method) {
    HttpServletRequest mock = mock(HttpServletRequest.class);
    when(mock.getMethod()).thenReturn(method);
    return mock;/*from   w ww .j  av a  2  s.  c o m*/
}

From source file:io.specto.hoverfly.recorder.HoverflyFilter.java

private HoverflyRecording.HoverFlyRequest recordRequest(final HttpServletRequest request) throws IOException {
    final String path = request.getPathInfo();
    final String query = request.getQueryString();
    final String requestMethod = request.getMethod();
    final String destination = simulatedBaseUrl;
    final String requestBody = request.getReader() != null ? CharStreams.toString(request.getReader()) : "";
    return new HoverflyRecording.HoverFlyRequest(path, requestMethod, destination, query, requestBody);
}

From source file:org.socialsignin.exfmproxy.mvc.ExFmProxyController.java

protected String getJson(HttpServletRequest request, String url) {
    String json = "";
    String method = request.getMethod().toLowerCase();
    if (method.equals("get")) {
        if (request.getQueryString() != null) {
            json = restTemplate.getForObject(url + "?" + request.getQueryString(), String.class);
        } else {//from   w  w w  .  j av  a  2  s  .  co m
            json = restTemplate.getForObject(url, String.class);
        }
    } else if (method.equals("post")) {
        HttpHeaders requestHeaders = new HttpHeaders();

        requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

        HttpEntity<?> httpEntity = new HttpEntity<Object>(requestHeaders);
        json = restTemplate.postForEntity(url, httpEntity, String.class).getBody();

    }
    return json.trim();
}

From source file:com.mirantis.cachemod.filter.CacheFilter.java

private boolean isCacheable(ServletRequest request) {
    if (request instanceof HttpServletRequest) {
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        if (conf.getEscapeMethods().contains(httpRequest.getMethod())) {
            return false;
        }/*from  ww w.j  av a2s  .  co  m*/
        if (conf.isEscapeSessionId() && httpRequest.isRequestedSessionIdFromURL()) {
            return false;
        }
    }
    return true;
}

From source file:net.shopxx.interceptor.TokenInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    String token = WebUtils.getCookie(request, TOKEN_COOKIE_NAME);
    if (StringUtils.equalsIgnoreCase(request.getMethod(), "POST")) {
        if (StringUtils.isNotEmpty(token)) {
            String requestType = request.getHeader("X-Requested-With");
            if (StringUtils.equalsIgnoreCase(requestType, "XMLHttpRequest")) {
                if (StringUtils.equals(token, request.getHeader(TOKEN_PARAMETER_NAME))) {
                    return true;
                } else {
                    response.addHeader("tokenStatus", "accessDenied");
                }/*from w  w  w .  j  ava  2s  . c  o  m*/
            } else {
                if (StringUtils.equals(token, request.getParameter(TOKEN_PARAMETER_NAME))) {
                    return true;
                }
            }
        } else {
            WebUtils.addCookie(request, response, TOKEN_COOKIE_NAME,
                    DigestUtils.md5Hex(UUID.randomUUID() + RandomStringUtils.randomAlphabetic(30)));
        }
        response.sendError(HttpServletResponse.SC_FORBIDDEN, ERROR_MESSAGE);
        return false;
    } else {
        if (StringUtils.isEmpty(token)) {
            token = DigestUtils.md5Hex(UUID.randomUUID() + RandomStringUtils.randomAlphabetic(30));
            WebUtils.addCookie(request, response, TOKEN_COOKIE_NAME, token);
        }
        request.setAttribute(TOKEN_ATTRIBUTE_NAME, token);
        return true;
    }
}

From source file:io.apiman.test.common.mock.EchoServlet.java

/**
 * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *//*  ww w .  jav  a  2  s  . c o m*/
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String method = req.getMethod();
    doEchoResponse(req, resp, methodsWithBody.contains(method));
}

From source file:com.mycompany.projetsportmanager.filter.XHttpMethodOverrideFilter.java

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

    String headerValue = request.getHeader(this.headerParam);
    if ("POST".equals(request.getMethod()) && StringUtils.hasLength(headerValue)) {
        String method = headerValue.toUpperCase(Locale.ENGLISH);
        HttpServletRequest wrapper = new HttpMethodRequestWrapper(request, method);
        filterChain.doFilter(wrapper, response);
    } else {//from ww w. ja v  a 2  s.  c  o  m
        filterChain.doFilter(request, response);
    }
}