List of usage examples for javax.servlet.http HttpServletRequest getMethod
public String getMethod();
From source file:com.github.dactiv.fear.user.web.AccountController.java
/** * ??//w w w . ja v a2 s . co m * * @param entity map * @param request http servlet request * * @return ??:WEB-INF/page/index.ftl * * @throws Exception */ @RequestMapping(value = "registration", method = { RequestMethod.GET, RequestMethod.POST }) public String registration(@RequestParam Map<String, Object> entity, HttpServletRequest request) throws Exception { if (request.getMethod().equals(HttpMethod.GET.name())) { return "registration"; } else { accountService.registration(entity); String username = entity.get("username").toString(); String password = entity.get("password").toString(); SecurityUtils.getSubject() .login(new UsernamePasswordToken(username, password, request.getRemoteHost())); return "redirect:/account/user-profile"; } }
From source file:ar.com.zauber.commons.web.proxy.HttpClientRequestProxy.java
/** * @param request/*from w ww . j a v a2 s .c o m*/ * @return */ private HttpMethod buildRequest(final HttpServletRequest request, final URLResult urlResult) { final String method = request.getMethod().toUpperCase(); final HttpMethod ret; final String uri = urlResult.getURL().toExternalForm(); if ("GET".equals(method)) { ret = new GetMethod(uri); proxyHeaders(request, ret); } else if ("POST".equals(method) || "PUT".equals(method)) { final EntityEnclosingMethod pm = "POST".equals(method) ? new PostMethod(uri) : new PutMethod(uri); proxyHeaders(request, pm); try { pm.setRequestEntity(new InputStreamRequestEntity(request.getInputStream())); } catch (IOException e) { throw new UnhandledException("No pudo abrirse el InputStream" + "del request.", e); } ret = pm; } else if ("DELETE".equals(method)) { /* rfc2616 The Content-Length field of a request or response is added or deleted according to the rules in section 4.4. A transparent proxy MUST preserve the entity-length (section 7.2.2) of the entity-body, although it MAY change the transfer-length (section 4.4). */ final DeleteMethod dm = new DeleteMethod(uri); proxyHeaders(request, dm); //No body => No Header dm.removeRequestHeader("Content-Length"); ret = dm; } else { throw new NotImplementedException("i accept patches :)"); } if (request.getQueryString() != null) { ret.setQueryString(request.getQueryString()); } return ret; }
From source file:com.github.reverseproxy.ReverseProxyJettyHandler.java
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String requestPath = request.getRequestURI(); String queryString = request.getQueryString(); String method = request.getMethod(); String requestBody = IOUtils.toString(request.getReader()); requestBody = URLDecoder.decode(requestBody, "UTF-8"); //TODO String urlWithFullPath = StringUtils.isEmpty(queryString) ? requestPath : requestPath + "?" + queryString; String forwardUrl = getForwardUrl(urlWithFullPath); if (forwardUrl == null) { throw new IOException("Invalid forwardurl for : " + requestPath); }/*from w w w . j a va 2s .com*/ URLConnection urlConnection = getUrlConnection(request, method, requestBody, forwardUrl); writeResponse(urlConnection, response); }
From source file:com.castlemock.war.config.LoggingInterceptor.java
/** * The method handles incoming requests and logs them if debug mode is enabled. The method will log the following * things:/*from w w w . ja v a 2 s . co m*/ * 1. The request URI * 2. The request method * 3. The controller responsible for handling the request * @param request The incoming request. The request will be parsed and logged * @param response The outgoing response * @param handler The handler contains information about the method and controller that will process the incoming request * @return Always returns true * @see AbstractController */ @Override public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler) { if (LOGGER.isDebugEnabled()) { final StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("Start processing the following request: " + request.getRequestURI() + " (" + request.getMethod() + ")."); if (handler instanceof HandlerMethod) { final HandlerMethod handlerMethod = (HandlerMethod) handler; stringBuilder.append("This request is going to be processed by the following controller: " + handlerMethod.getBeanType().getSimpleName()); } LOGGER.debug(stringBuilder.toString()); } return true; }
From source file:net.eusashead.hateoas.conditional.interceptor.ConditionalResponseInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { if (request.getMethod().equals(GET)) { postHandleGetOrHead(request, response); } else if (request.getMethod().equals(HEAD)) { postHandleGetOrHead(request, response); } else if (request.getMethod().equals(PUT)) { postHandlePut(request, response); } else if (request.getMethod().equals(DELETE)) { postHandleDelete(request);// w w w.j a v a 2s. c o m } else if (request.getMethod().equals(POST)) { postHandlePost(request); } }
From source file:org.socialsignin.springsocial.security.signin.SpringSocialSecurityAccessDeniedHandler.java
private boolean providerCombinationAllowsAccessForEvaluator(HttpServletRequest request, Authentication existingAuthentication, WebInvocationPrivilegeEvaluator evaluator, Set<String> additionProviderIdsCombination) { return evaluator.isAllowed(request.getContextPath(), getUri(request), request.getMethod(), springSocialSecurityAuthenticationFactory.updateAuthenticationForNewProviders( existingAuthentication, additionProviderIdsCombination)); }
From source file:ar.com.zauber.commons.spring.web.handlers.strategy.ByMethodTransactionStrategy.java
/** @see TransactionStrategy#getTransactionTemplate(Object) */ public TransactionTemplate getTransactionTemplate(Object handler, HttpServletRequest request) { /* Si recibo un GET y la clase del handler no esta entre las que modifican * la base con un GET retorna un template de solo lectura, * y si el metodo es otro o la clase del handler es especial retorno el * template de escritura *//*from w w w . j a va2s . c om*/ TransactionTemplate ret = null; if (handler == null || (request.getMethod().equals("GET") && !specialClass.contains(handler.getClass()))) { ret = readTemplate; } else { ret = writeTemplate; } return ret; }
From source file:com.alibaba.dubboadmin.web.mvc.RouterController.java
@RequestMapping("/governance/services/{service}/{type}/{id}/{action}") public String serviceActionWithId(@RequestParam Map<String, Object> param, @PathVariable("service") String service, @PathVariable("type") String type, @PathVariable("id") String id, @PathVariable("action") String action, HttpServletRequest request, HttpServletResponse response, Model model) { String method = request.getMethod(); String app = null;/*from w w w. j av a 2 s . c om*/ System.out.println("type: " + type); System.out.println("action: " + action); System.out.println("method: " + method); for (Map.Entry<String, Object> entry : param.entrySet()) { if (entry.getKey().equals("application")) { app = (String) entry.getValue(); } System.out.println("key: " + entry.getKey()); System.out.println("value: " + entry.getValue()); } return appActionWithIdandAction(app, service, type, id, action, request, response, model); }
From source file:com.stormpath.sdk.servlet.mvc.AbstractController.java
@Override public ViewModel handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String method = request.getMethod(); boolean hasAccount = accountResolver.hasAccount(request); if (HttpMethod.GET.name().equalsIgnoreCase(method)) { if (hasAccount && isNotAllowedIfAuthenticated()) { return new DefaultViewModel(nextUri).setRedirect(true); }// w ww.ja v a2 s . c o m return doGet(request, response); } else if (HttpMethod.POST.name().equalsIgnoreCase(method)) { if (isNotAllowedIfAuthenticated() && hasAccount) { response.sendError(403); return null; } return doPost(request, response); } else { return service(request, response); } }