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.enonic.cms.server.service.servlet.CmsDispatcherServlet.java

protected void doService(HttpServletRequest req, HttpServletResponse res) throws Exception {

    HttpMethod requestMethod = HttpMethod.valueOf(req.getMethod());

    if (!ALLOWED_HTTP_METHODS.contains(requestMethod)) {
        res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
        return;//from ww  w. j a v a  2 s. co  m
    }

    startContextIfNeeded();
    if (upgradeIsNeeded(res)) {
        return;
    }

    ServletRequestAccessor.setRequest(req);
    // resolve and set original url if not set
    if (req.getAttribute(Attribute.ORIGINAL_URL) == null) {
        final String originalUrl = OriginalUrlResolver.get().resolveOriginalUrl(req);
        req.setAttribute(Attribute.ORIGINAL_URL, originalUrl);
    }

    if (LOG.isDebugEnabled()) {
        StringBuffer msg = new StringBuffer();
        msg.append("Dispatching request to URL: " + req.getRequestURL());
        LOG.debug(msg.toString());
    }

    super.doService(req, res);
}

From source file:org.craftercms.security.processors.impl.LogoutProcessor.java

protected boolean isLogoutRequest(HttpServletRequest request) {
    return HttpUtils.getRequestUriWithoutContextPath(request).equals(logoutUrl)
            && request.getMethod().equals(logoutMethod);
}

From source file:de.ifgi.mosia.wpswfs.handler.GenericRequestHandler.java

@Override
public void handleRequest(HttpServletRequest req, HttpServletResponse resp)
        throws IOException, ServiceException {
    HttpResponse response;//from  w w  w  .  j a  v  a  2  s .c  o  m
    if (req.getMethod().equalsIgnoreCase("GET")) {
        response = handleGet(req, resp);
    } else {
        throw new UnsupportedOperationException("Only GET and POST are supported.");
    }

    writeResponse(response, resp);
}

From source file:com.bluexml.side.Framework.alfresco.shareLanguagePicker.CustomWebScriptServlet.java

@Override
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("Processing request (" + req.getMethod() + ") " + req.getRequestURL()
                + (req.getQueryString() != null ? "?" + req.getQueryString() : ""));
    }/*  w  w  w .  ja v a  2 s  . co m*/

    if (req.getCharacterEncoding() == null) {
        req.setCharacterEncoding("UTF-8");
    }
    // initialize the request context
    RequestContext context = null;
    try {
        context = FrameworkHelper.initRequestContext(req);
    } catch (Exception ex) {
        throw new ServletException(ex);
    }
    LanguageSetter.setLanguageFromLayoutParam(req, context);

    WebScriptServletRuntime runtime = new WebScriptServletRuntime(container, authenticatorFactory, req, res,
            serverProperties);
    runtime.executeScript();
}

From source file:com.alfaariss.oa.profile.aselect.binding.BindingFactory.java

/**
 * Returns the binding object specified by the request.
 * //from   w  w  w  .java2 s. com
 * @param oServletRequest The servlet request object.
 * @param oServletResponse The servlet response object.
 * @return IBinding: CGIBinding
 * @throws BindingException if binding creation fails.
 */
public IBinding getBinding(HttpServletRequest oServletRequest, HttpServletResponse oServletResponse)
        throws BindingException {
    IBinding oBinding = null;
    String sMethod = oServletRequest.getMethod();
    try {
        if (sMethod.equalsIgnoreCase("GET")) {
            //PROTOCOL_CGI;
            oBinding = new CGIBinding(oServletRequest, oServletResponse);
        }
    } catch (Exception e) {
        _logger.fatal("Internal error during binding creation", e);
        throw new BindingException(SystemErrors.ERROR_INTERNAL);
    }

    return oBinding;
}

From source file:com.flexive.war.filter.SessionFixationFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    if (servletRequest instanceof HttpServletRequest) {
        final HttpServletRequest request = (HttpServletRequest) servletRequest;

        if ("POST".equals(request.getMethod())) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("SessionFixationFilter: creating new session before login");
            }/*from w w w . j av  a2  s.  c o  m*/

            // remember old attributes (esp. JSF viewstate)
            final Map<String, Object> attributes = getAttributes(request.getSession());

            // create new session ID
            final String oldSessionId = request.getSession(true).getId();
            request.getSession().invalidate();
            request.getSession(true);
            if (oldSessionId.equals(request.getSession().getId())) {
                if (LOG.isWarnEnabled()) {
                    LOG.warn("Invalidating the session did not generate a new session ID. Your application may "
                            + "be vulnerable to session fixation attacks. When using JBoss, try setting "
                            + "emptySessionPath=\"false\" in your server.xml.");
                }
            }

            // integrate old values
            setAttributes(request.getSession(false), attributes);
        }
    }
    filterChain.doFilter(servletRequest, servletResponse);
}

From source file:com.github.restdriver.clientdriver.HttpRealRequest.java

public HttpRealRequest(HttpServletRequest request) {
    this.path = request.getPathInfo();
    this.method = Method.custom(request.getMethod().toUpperCase());
    this.params = HashMultimap.create();

    if (request.getQueryString() != null) {
        MultiMap<String> parameterMap = new MultiMap<String>();
        UrlEncoded.decodeTo(request.getQueryString(), parameterMap, "UTF-8", 0);
        for (Entry<String, String[]> paramEntry : parameterMap.toStringArrayMap().entrySet()) {
            String[] values = paramEntry.getValue();
            for (String value : values) {
                this.params.put(paramEntry.getKey(), value);
            }//from  w ww  .  ja  va  2  s  .  c  om
        }
    }

    headers = new HashMap<String, Object>();
    Enumeration<String> headerNames = request.getHeaderNames();
    if (headerNames != null) {
        while (headerNames.hasMoreElements()) {
            String headerName = headerNames.nextElement();
            headers.put(headerName.toLowerCase(), request.getHeader(headerName));
        }
    }

    try {
        this.bodyContent = IOUtils.toByteArray(request.getInputStream());
    } catch (IOException e) {
        throw new RuntimeException("Failed to read body of request", e);
    }

    this.bodyContentType = request.getContentType();
}

From source file:org.openmrs.contrib.metadatarepository.webapp.controller.UserFormController.java

private boolean isFormSubmission(HttpServletRequest request) {
    return request.getMethod().equalsIgnoreCase("post");
}

From source file:com.eviware.soapui.model.support.AbstractMockDispatcher.java

public MockResult dispatchRequest(HttpServletRequest request, HttpServletResponse response)
        throws DispatchException {
    String method = request.getMethod();

    if (method.equals("POST")) {
        return dispatchPostRequest(request, response);
    } else if (method.equals("GET")) {
        return dispatchGetRequest(request, response);
    } else if (method.equals("HEAD")) {
        return dispatchHeadRequest(request, response);
    } else if (method.equals("PUT")) {
        return dispatchPutRequest(request, response);
    } else if (method.equals("DELETE")) {
        return dispatchDeleteRequest(request, response);
    } else if (method.equals("PATCH")) {
        return dispatchPatchRequest(request, response);
    }//from w  w w .j  av a 2s  .c  o  m

    throw new DispatchException("Unsupported HTTP Method: " + method);
}