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.github.dactiv.fear.user.web.AccountController.java

/**
 * ???//from ww w . j av  a  2  s .c  o m
 *
 * @param username 
 * @param captcha ??
 * @param request http servlet request
 *
 * @return ??:WEB-INF/page/index.ftl
 *
 * @throws Exception
 */
@RequestMapping(value = "forgot-password", method = { RequestMethod.GET, RequestMethod.POST })
public String forgotPassword(String username, String captcha, HttpServletRequest request) throws Exception {
    if (request.getMethod().equals(HttpMethod.GET.name())) {
        return "/forgot-password";
    } else {
        Map<String, Object> user;
        try {
            user = accountService.forgotPassword(username, captcha);
        } catch (ServiceException e) {
            request.setAttribute("message", e.getMessage());
            return "/forgot-password";
        }
        String email = Casts.cast(user.get("email"), String.class);
        request.setAttribute("email", StringUtils.overlay(email, "******", 4, email.indexOf("@")));
        return "reset-password-mail-send";
    }
}

From source file:com.example.HoneycombFilter.java

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

    if (!(request instanceof HttpServletRequest)) {
        chain.doFilter(request, response);
        return;/*  w w  w. j av a  2 s. c om*/
    }
    HttpServletRequest req = (HttpServletRequest) request;
    long start = System.nanoTime();
    try {
        chain.doFilter(request, response);
    } finally {
        long responseTimeNanos = System.nanoTime() - start;
        Event event = libhoney.newEvent();
        event.addField("method", req.getMethod());
        event.addField("path", req.getRequestURI());
        event.addField("query", req.getQueryString());
        Principal principal = req.getUserPrincipal();
        if (principal != null) {
            event.addField("user", principal.getName());
        }
        event.addField("host", req.getRemoteHost());
        event.addField("responseTimeNanos", responseTimeNanos);
        try {
            event.send();
        } catch (HoneyException e) {
            log.error(e.getMessage(), e);
        }
    }
}

From source file:com.streamsets.lib.security.http.SSOUserAuthenticator.java

boolean isLogoutRequest(HttpServletRequest httpReq) {
    String logoutPath = httpReq.getContextPath() + "/logout";
    return httpReq.getMethod().equals("GET") && httpReq.getRequestURI().equals(logoutPath);
}

From source file:com.bradmcevoy.http.ServletRequest.java

public ServletRequest(HttpServletRequest r, ServletContext servletContext) {
    this.request = r;
    this.servletContext = servletContext;
    String sMethod = r.getMethod();
    method = Request.Method.valueOf(sMethod);
    String s = r.getRequestURL().toString(); //MiltonUtils.stripContext(r);
    url = s;/*from w ww  .ja  va  2s.  c  om*/
    tlRequest.set(r);
    tlServletContext.set(servletContext);
}

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

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;
    response.setHeader("Content-Type", "application/json; charset=utf-8");
    String requestType = request.getMethod();
    String url = "";
    String api_key = "";
    String param = "";
    String result = "";
    if (requestType == "GET" || "GET".equals(requestType)) {
        url = getRedmineUrl(request.getRequestURL().toString());
        api_key = getSessionApiKey(request);
        if (api_key == null || "".equals(api_key)) {
            return;
        }/*from www . j  av  a 2s . c  o  m*/
        WebApplicationContext webAppContext = ContextLoader.getCurrentWebApplicationContext();
        RedmineHttpRequestService redmineHttpRequestService = (RedmineHttpRequestService) webAppContext
                .getBean("redmineHttpRequestService");
        result = redmineHttpRequestService.doGET(url, api_key);
    } else if (requestType == "POST" || "POST".equals(requestType)) {
        url = getRedmineUrl(request.getRequestURL().toString());
        api_key = getSessionApiKey(request);
        if (api_key == null || "".equals(api_key)) {
            return;
        }
        param = getParam(request.getInputStream());
        WebApplicationContext webAppContext = ContextLoader.getCurrentWebApplicationContext();
        RedmineHttpRequestService redmineHttpRequestService = (RedmineHttpRequestService) webAppContext
                .getBean("redmineHttpRequestService");
        result = redmineHttpRequestService.doPost(url, param, api_key);
    } else if (requestType == "PUT" || "PUT".equals(requestType)) {
        url = getRedmineUrl(request.getRequestURL().toString());
        api_key = getSessionApiKey(request);
        if (api_key == null || "".equals(api_key)) {
            return;
        }
        param = getParam(request.getInputStream());
        WebApplicationContext webAppContext = ContextLoader.getCurrentWebApplicationContext();
        RedmineHttpRequestService redmineHttpRequestService = (RedmineHttpRequestService) webAppContext
                .getBean("redmineHttpRequestService");
        result = redmineHttpRequestService.doPut(url, param, api_key);
    } else {
        return;
    }

    response.getWriter().write(result);
    return;

}

From source file:com.litemvc.LiteMvcFilter.java

private boolean isMappedMethod(HttpServletRequest request, Method method, Binding binding) {
    if (binding.getMethodName() == null) {
        return method.getName().equals(request.getMethod().toLowerCase());
    } else {//from   ww  w  . jav  a 2  s .  c o  m
        return method.getName().equals(binding.getMethodName());
    }
}

From source file:net.sourceforge.subsonic.backend.controller.RedirectionController.java

private String getFullRequestURL(HttpServletRequest request) throws UnsupportedEncodingException {
    StringBuilder builder = new StringBuilder(request.getRequestURL());

    // For backwards compatibility; return query parameters in exact same sequence.
    if ("GET".equalsIgnoreCase(request.getMethod())) {
        if (request.getQueryString() != null) {
            builder.append("?").append(request.getQueryString());
        }//from w w  w .ja v  a  2s  . c o  m
        return builder.toString();
    }

    builder.append("?");

    Enumeration<?> paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
        String paramName = (String) paramNames.nextElement();
        String[] paramValues = request.getParameterValues(paramName);
        for (String paramValue : paramValues) {
            String p = URLEncoder.encode(paramValue, "UTF-8");
            builder.append(paramName).append("=").append(p).append("&");
        }
    }

    return builder.toString();
}

From source file:net.sf.j2ep.ProxyFilter.java

/**
 * Will create the method and execute it. After this the method
 * is sent to a ResponseHandler that is returned.
 * /*w  w  w .  j ava 2s .  co m*/
 * @param httpRequest Request we are receiving from the client
 * @param url The location we are proxying to
 * @return A ResponseHandler that can be used to write the response
 * @throws MethodNotAllowedException If the method specified by the request isn't handled
 * @throws IOException When there is a problem with the streams
 * @throws HttpException The httpclient can throw HttpExcetion when executing the method
 */
private ResponseHandler executeRequest(HttpServletRequest httpRequest, String url)
        throws MethodNotAllowedException, IOException, HttpException {
    RequestHandler requestHandler = RequestHandlerFactory.createRequestMethod(httpRequest.getMethod());

    HttpMethod method = requestHandler.process(httpRequest, url);
    method.setFollowRedirects(false);

    /*
     * Why does method.validate() return true when the method has been
     * aborted? I mean, if validate returns true the API says that means
     * that the method is ready to be executed. TODO I don't like doing type
     * casting here, see above.
     */
    if (!((HttpMethodBase) method).isAborted()) {
        httpClient.executeMethod(method);

        if (method.getStatusCode() == 405) {
            Header allow = method.getResponseHeader("allow");
            String value = allow.getValue();
            throw new MethodNotAllowedException("Status code 405 from server",
                    AllowedMethodHandler.processAllowHeader(value));
        }
    }

    return ResponseHandlerFactory.createResponseHandler(method);
}

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

/**
 * Reject the change//from  w  ww.  j  av a2 s.c  o  m
 * 
 * @see org.springframework.web.servlet.mvc.AbstractController#
 *              handleRequest(HttpServletRequest, HttpServletResponse)
 */
public final ModelAndView postreject(final HttpServletRequest request, final HttpServletResponse response) {
    ModelAndView ret = null;
    final String secret = ServletRequestUtils.getStringParameter(request, "secret", null);

    if (!request.getMethod().equalsIgnoreCase("post")) {
        throw new IllegalArgumentException("only accept POST method");
    }

    if (secret == null) {
        ret = new ModelAndView(errorView);
    } else {
        try {
            final T cmd = secretsMap.getT(secret);
            secretsMap.unregister(cmd);
            ret = new ModelAndView(successRejectView, getViewModel(cmd));
        } catch (final NoSuchEntityException e) {
            ret = new ModelAndView(errorView);
        }
    }

    return ret;
}

From source file:org.toobsframework.pres.app.controller.AppHandler.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response,
        UrlDispatchInfo dispatchInfo) throws Exception {

    String output = "";
    String urlPath = this.urlPathHelper.getLookupPathForRequest(request);

    AppRequest appRequest = urlResolver.resolve(appManager, urlPath, request.getMethod());
    if (log.isDebugEnabled()) {

        appManager.showApps();//from ww w .  j av  a 2 s. c om

        log.debug("AppView App   : " + appRequest.getAppName());
        log.debug("AppView isComp: " + appRequest.getRequestType());
        log.debug("AppView View  : " + appRequest.getViewName());
        appRequest.debugUrlParams();
    }

    Date startTime = null;
    if (log.isDebugEnabled()) {
        startTime = new Date();
    }

    Map<String, Object> params = ParameterUtil.buildParameterMap(request);
    IComponentRequest componentRequest = componentRequestManager.set(dispatchInfo, request, response, params,
            false);

    output = appManager.renderView(appRequest, componentRequest, transformerHelper);

    //Write out to the response.
    response.setContentType("text/html; charset=UTF-8");
    response.setHeader("Pragma", "no-cache"); // HTTP 1.0
    response.setHeader("Cache-Control", "no-cache, must-revalidate, private"); // HTTP 1.1
    PrintWriter writer = response.getWriter();
    writer.print(output);
    writer.flush();

    if (log.isDebugEnabled()) {
        Date endTime = new Date();
        log.debug("Time [" + appRequest.getAppName() + ":" + appRequest.getViewName() + "] - "
                + (endTime.getTime() - startTime.getTime()));
    }
    return null;

}