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:cherry.foundation.springmvc.OperationLogHandlerInterceptor.java

private StringBuilder createBasicInfo(HttpServletRequest request) {
    StringBuilder builder = new StringBuilder();
    return builder.append(request.getRemoteAddr()).append(" ").append(request.getMethod()).append(" ")
            .append(request.getRequestURI());
}

From source file:ar.com.zauber.commons.spring.web.AbstractConfirmationController.java

/** @see la aceptacion de la confirmacin */
public final ModelAndView postconfirm(final HttpServletRequest request, final HttpServletResponse response) {
    if (!request.getMethod().equalsIgnoreCase("post")) {
        throw new IllegalArgumentException("only accept POST method");
    }/*  w  w  w .  j a  v  a2  s  .  c  om*/

    ModelAndView ret = null;
    final String secret = ServletRequestUtils.getStringParameter(request, "secret", null);

    if (secret == null) {
        ret = new ModelAndView(errorView);
    } else {
        try {
            final T cmd = secretsMap.getT(secret);
            setup(cmd);
            cmd.run();
            if (unregisterCmd) {
                secretsMap.unregister(cmd);
            }
            ret = new ModelAndView(successConfirmView, getViewModel(cmd));
        } catch (final NoSuchEntityException e) {
            // void
        }

        if (ret == null) {
            ret = new ModelAndView(errorView);
        }
    }

    return ret;
}

From source file:com.netflix.zuul.scriptManager.FilterScriptManagerServlet.java

/**
 * Determine if the incoming action + method is a correct combination. If not, output the usage docs and set an error code on the response.
 *
 * @param request/*from   w  w  w.ja v a2  s.  co  m*/
 * @param response
 * @return true if valid, false if not
 */
private static boolean isValidAction(HttpServletRequest request, HttpServletResponse response) {
    String action = request.getParameter("action");
    if (action != null) {
        action = action.trim().toUpperCase();
        /* test for GET actions */
        if (VALID_GET_ACTIONS.contains(action)) {
            if (!request.getMethod().equals("GET")) {
                // valid action, wrong method
                setUsageError(405, "ERROR: Invalid HTTP method for action type.", response);
                return false;
            }
            // valid action and method
            return true;
        }

        if (VALID_PUT_ACTIONS.contains(action)) {
            if (!(request.getMethod().equals("PUT") || request.getMethod().equals("POST"))) {
                // valid action, wrong method
                setUsageError(405, "ERROR: Invalid HTTP method for action type.", response);
                return false;
            }
            // valid action and method
            return true;
        }

        // wrong action
        setUsageError(400, "ERROR: Unknown action type.", response);
        return false;
    } else {
        setUsageError(400, "ERROR: Invalid arguments.", response);
        return false;
    }
}

From source file:com.bluexml.side.Framework.alfresco.languagepicker.MyWebScriptServlet.java

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() : ""));

    if (req.getCharacterEncoding() == null) {
        req.setCharacterEncoding("UTF-8");
    }/* w w w . j  a v  a  2  s.  c om*/

    setUserLanguage(req);

    try {
        WebScriptServletRuntime runtime = new WebScriptServletRuntime(container, authenticatorFactory, req, res,
                serverProperties);
        runtime.executeScript();
    } finally {
        // clear threadlocal
        I18NUtil.setLocale(null);
    }
}

From source file:de.digiway.rapidbreeze.client.infrastructure.cnl.ClickAndLoadHandler.java

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    switch (request.getMethod().toUpperCase()) {
    case GET_METHOD:
        handleGet(request, response);/*from ww w  .java 2 s . c  om*/
        break;
    case POST_METHOD:
        handlePost(request, response);
        break;
    }
}

From source file:com.adobe.acs.commons.http.injectors.AbstractHtmlRequestInjector.java

@SuppressWarnings("squid:S3923")
protected boolean accepts(final ServletRequest servletRequest, final ServletResponse servletResponse) {

    if (!(servletRequest instanceof HttpServletRequest) || !(servletResponse instanceof HttpServletResponse)) {
        return false;
    }//from w  w w.  ja  va  2 s.  c  om

    final HttpServletRequest request = (HttpServletRequest) servletRequest;

    if (!StringUtils.equalsIgnoreCase("get", request.getMethod())) {
        // Only inject on GET requests
        return false;
    } else if (StringUtils.equals(request.getHeader("X-Requested-With"), "XMLHttpRequest")) {
        // Do not inject into XHR requests
        return false;
    } else if (StringUtils.contains(request.getPathInfo(), ".")
            && !StringUtils.contains(request.getPathInfo(), ".html")) {
        // If extension is provided it must be .html
        return false;
    } else if (StringUtils.endsWith(request.getHeader("Referer"), "/editor.html" + request.getRequestURI())) {
        // Do not apply to pages loaded in the TouchUI editor.html
        return false;
    } else if (StringUtils.endsWith(request.getHeader("Referer"), "/cf")) {
        // Do not apply to pages loaded in the Classic Content Finder
        return false;
    }

    // Add HTML check
    if (log.isTraceEnabled()) {
        log.trace("Injecting HTML via AbstractHTMLRequestInjector");
    }
    return true;
}

From source file:com.jsqlboxdemo.dispatcher.Dispatcher.java

public static void dispach(PageContext pageContext) throws Exception {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    String uri = StringUtils.substringBefore(request.getRequestURI(), ".");
    String contextPath = request.getContextPath();

    if (!StringUtils.isEmpty(contextPath))
        uri = StringUtils.substringAfter(uri, contextPath);
    if (StringUtils.isEmpty(uri) || "/".equals(uri))
        uri = "/home";

    String[] paths = StringUtils.split(uri, "/");
    String[] pathParams;/*from  www.  ja  v a2  s .c o  m*/
    String resource = null;
    String operation = null;

    if (paths.length >= 2) {// /team/add/100...
        resource = paths[0];
        operation = paths[1];
        pathParams = new String[paths.length - 2];
        for (int i = 2; i < paths.length; i++)
            pathParams[i - 2] = paths[i];
    } else { // /home_default
        resource = paths[0];
        pathParams = new String[0];
    }

    if (operation == null)
        operation = "default";
    StringBuilder controller = new StringBuilder("com.jsqlboxdemo.controller.").append(resource).append("$")
            .append(resource).append("_").append(operation);
    if ("POST".equals(request.getMethod()))
        controller.append("_post");

    WebBox box;
    try {
        Class boxClass = Class.forName(controller.toString());
        box = BeanBox.getPrototypeBean(boxClass);
    } catch (Exception e) {
        throw new ClassNotFoundException("There is no WebBox classs '" + controller + "' found.");
    }
    request.setAttribute("pathParams", pathParams);
    box.show(pageContext);
}

From source file:com.googlecode.commonspringaspects.servlets.PerformanceHttpRequestHandler.java

public void handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    if (!enabled) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;/*from  w w w  . j a v  a  2s .c  om*/
    }

    if (request.getMethod().equals("POST")) {

        MonitorFactory.reset();
        response.sendRedirect(request.getRequestURI());

    } else {

        response.setContentType("text/html");
        PrintWriter writer = response.getWriter();
        writer.print("<html>");
        writer.print("<body><form action='' method='post'> <input type='submit' value='Reset JAMon'> </form>");
        writer.print(MonitorFactory.getRootMonitor().getReport(3, "desc"));
        writer.print("</body></html>");

    }
}

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

@Override
public ReceivePack create(C request, Repository db)
        throws ServiceNotEnabledException, ServiceNotAuthorizedException {
    final String logPrefix;
    if (request instanceof HttpServletRequest) {
        HttpServletRequest req = (HttpServletRequest) request;
        logPrefix = "create(" + req.getMethod() + ")[" + req.getRequestURI() + "][" + req.getQueryString()
                + "]";
    } else {/*from   www. ja va 2 s.c om*/
        logPrefix = "create(" + db.getDirectory() + ")";
    }
    if (logger.isDebugEnabled()) {
        logger.debug(logPrefix + ": " + db.getDirectory());
    }

    ReceivePack receive = new ReceivePack(db) {
        @Override
        @SuppressWarnings("synthetic-access")
        public void receive(InputStream input, OutputStream output, OutputStream messages) throws IOException {
            InputStream effIn = input;
            OutputStream effOut = output, effMessages = messages;
            if (logger.isTraceEnabled()) {
                LineLevelAppender inputAppender = new LineLevelAppender() {
                    @Override
                    public void writeLineData(CharSequence lineData) throws IOException {
                        logger.trace(logPrefix + " upload(C): " + lineData);
                    }

                    @Override
                    public boolean isWriteEnabled() {
                        return true;
                    }
                };
                effIn = new TeeInputStream(effIn, new HexDumpOutputStream(inputAppender), true);

                LineLevelAppender outputAppender = new LineLevelAppender() {
                    @Override
                    public void writeLineData(CharSequence lineData) throws IOException {
                        logger.trace(logPrefix + " upload(S): " + lineData);
                    }

                    @Override
                    public boolean isWriteEnabled() {
                        return true;
                    }
                };
                effOut = new TeeOutputStream(effOut, new HexDumpOutputStream(outputAppender));

                if (effMessages != null) {
                    LineLevelAppender messagesAppender = new LineLevelAppender() {
                        @Override
                        public void writeLineData(CharSequence lineData) throws IOException {
                            logger.trace(logPrefix + " upload(M): " + lineData);
                        }

                        @Override
                        public boolean isWriteEnabled() {
                            return true;
                        }
                    };
                    // TODO review the decision to use an AsciiLineOutputStream here
                    effMessages = new TeeOutputStream(effMessages, new AsciiLineOutputStream(messagesAppender));
                }
            }

            super.receive(effIn, effOut, effMessages);
        }
    };
    receive.setTimeout(receiveTimeoutValue);

    // TODO set pushing user identity for reflog
    // receive.setRefLogIdent(new PersonIdent(user.username, user.username + "@" + origin))

    // TODO set advanced options
    // receive.setAllowCreates(user.canCreateRef(repository));
    // receive.setAllowDeletes(user.canDeleteRef(repository));
    // receive.setAllowNonFastForwards(user.canRewindRef(repository));

    // TODO setup the receive hooks
    // receive.setPreReceiveHook(preRcvHook);
    // receive.setPostReceiveHook(postRcvHook);

    return receive;
}

From source file:es.osoco.grails.plugins.otp.web.OneTimePasswordAuthenticationFilter.java

@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
        throws AuthenticationException {

    if (postOnly && !request.getMethod().equals("POST")) {
        throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
    }//from   w  w  w. j  a  v  a 2s. c  o  m

    String username = obtainUsername(request);
    String password = obtainPassword(request);

    username = username == null ? "" : username.trim();
    password = password == null ? "" : password;

    OneTimePasswordAuthenticationToken authRequest = new OneTimePasswordAuthenticationToken(username, password);

    // Place the last username attempted into HttpSession for views
    HttpSession session = request.getSession(false);

    if (session != null || getAllowSessionCreation()) {
        request.getSession().setAttribute(SPRING_SECURITY_LAST_USERNAME_KEY,
                TextEscapeUtils.escapeEntities(username));
    }

    // Allow subclasses to set the "details" property
    setDetails(request, authRequest);

    return getAuthenticationManager().authenticate(authRequest);
}