List of usage examples for javax.servlet.http HttpServletRequest getMethod
public String getMethod();
From source file:cn.sel.wetty.interceptor.AccessLogger.java
private void o(HttpServletRequest request, HttpServletResponse response) { String msg = String.format("%s\t[%s] -> %s \tStatus:%s\tHeaders:%s", request.getRequestURI(), request.getMethod(), request.getRemoteAddr(), response.getStatus(), getHeaders(response)); LOGGER.info(msg);/*from w ww. ja v a 2 s. c o m*/ }
From source file:de.iew.web.utils.ValidatingFormAuthenticationFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { final HttpServletRequest request = (HttpServletRequest) req; final HttpServletResponse response = (HttpServletResponse) res; if (request.getMethod().equals(RequestMethod.POST.name())) { // If the incoming request is a POST, then we send it up // to the AbstractAuthenticationProcessingFilter. super.doFilter(request, response, chain); } else {/*from w w w. j av a2 s . co m*/ // If it's a GET, we ignore this request and send it // to the next filter in the chain. In this case, that // pretty much means the request will hit the /login // controller which will process the request to show the // login page. chain.doFilter(request, response); } }
From source file:newcontroller.RouterHandlerMapping.java
@Override protected Object getHandlerInternal(HttpServletRequest request) throws Exception { if (request.getRequestURI().equalsIgnoreCase("favicon.ico")) { return null; }/*from ww w . j a va 2 s . co m*/ String method = request.getMethod(); String path = request.getRequestURI(); return this.router.match(method, path); }
From source file:com.sri.save.florahttp.FloraHttpServlet.java
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (request.getMethod().equals("OPTIONS")) { baseRequest.setHandled(true);/*from w w w . java 2s .c o m*/ HttpUtil.corsOptions(request, response, true); return; } baseRequest.setHandled(true); PrintWriter out = response.getWriter(); response.setContentType("application/json"); response.setHeader("Access-Control-Allow-Origin", "*"); // allows CORS // Dispatch the call to the Flora JSON server String method = request.getParameter("method"); if (method == null) { throw new ServletException("Missing method parameter"); } else if (method.equals("loadFile")) { // perhaps this should be done using POST String filename = request.getParameter("filename"); try { florajson.loadFile(filename); out.print("true"); } catch (FloraJsonServerException ex) { throw new ServletException(ex.getMessage()); } } else if (method.equals("getTaxonomyRoots")) { try { ArrayNode result = florajson.getRootClasses(); out.print(result.toString()); } catch (FloraJsonServerException ex) { throw new ServletException(ex.getMessage()); } } else if (method.equals("getSubClasses")) { String id = request.getParameter("id"); try { ObjectNode result = florajson.getSubClasses(id); out.print(result.toString()); } catch (FloraJsonServerException ex) { throw new ServletException(ex.getMessage()); } } else if (method.equals("getClassDetails")) { String id = request.getParameter("id"); try { ObjectNode result = florajson.getClassDetails(id); out.print(result.toString()); } catch (FloraJsonServerException ex) { throw new ServletException(ex.getMessage()); } } else if (method.equals("query")) { String qstring = request.getParameter("queryString"); try { ObjectNode result = florajson.query(qstring); out.print(result.toString()); } catch (FloraJsonServerException ex) { throw new ServletException(ex.getMessage()); } } else throw new ServletException("Unrecognized method: " + method); }
From source file:com.jaspersoft.jasperserver.rest.RESTAbstractService.java
/** * Check for the request method, and dispatch the code to the right class method * PUT and DELETE methods can be overridden by using the X-Method-Override header or * the special parameter X-Method-Override when using a POST. * * @param req//from w w w . ja v a 2s . c o m * @param resp * @throws ServiceException */ public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { String method = req.getMethod().toLowerCase(); // Tunnels a PUT or DELETE request over the HTTP POST request. String methodOverride = req.getHeader("X-Method-Override"); if (methodOverride == null) { methodOverride = req.getParameter("X-Method-Override"); } if (methodOverride != null && HTTP_POST.equals(method)) { methodOverride = methodOverride.toLowerCase(); if (HTTP_DELETE.equals(methodOverride) || HTTP_PUT.equals(methodOverride)) { method = methodOverride; } } if (log.isDebugEnabled()) { log.debug("execute: Resource=" + req.getPathInfo() + " Method=" + method); } if (HTTP_GET.equals(method)) { doGet(req, resp); } else if (HTTP_POST.equals(method)) { doPost(req, resp); } else if (HTTP_PUT.equals(method)) { doPut(req, resp); } else if (HTTP_DELETE.equals(method)) { doDelete(req, resp); } else { restUtils.setStatusAndBody(HttpServletResponse.SC_METHOD_NOT_ALLOWED, resp, "Method not supported for this object type"); } if (log.isDebugEnabled()) { log.debug("finished: Resource=" + req.getPathInfo() + " Method=" + method); } }
From source file:org.biokoframework.http.response.impl.AbstractHttpResponseBuilder.java
@Override public final void build(HttpServletRequest request, HttpServletResponse response, Fields input, Fields output) throws IOException, RequestNotSupportedException { if (request.getMethod().equals("POST") || request.getMethod().equals("PUT")) { checkAcceptType(Arrays.asList(request.getContentType()), getRequestExtension(request.getPathInfo())); } else {/* w w w . j a v a2 s . c o m*/ checkAcceptType(getAccept(request), getRequestExtension(request.getPathInfo())); } response.setStatus(HttpStatus.SC_OK); safelyBuild(request, response, input, output); }
From source file:org.deegree.securityproxy.authentication.wass.AddParameterAnonymousAuthenticationFilter.java
private HttpServletRequest wrapRequest(HttpServletRequest request) throws ServletException { String method = request.getMethod(); LOG.debug("Retrieved " + method + " request"); if (isGetRequestedAndSupported(method)) { LOG.debug("Handle GET request with query string " + request.getQueryString()); return new KvpRequestWrapper(request); } else if (isPostRequestedAndSupported(method)) { LOG.debug("Handle POST request"); try {/*from w w w. j av a2 s .co m*/ return new HttpServletRequestBodyWrapper(request); } catch (IOException e) { throw new ServletException(e); } } return request; }
From source file:fi.vm.sade.organisaatio.resource.TempFileResource.java
@POST @Path("/") @Produces(MediaType.TEXT_PLAIN)//www . java 2 s .c o m @Consumes(MediaType.MULTIPART_FORM_DATA) @Secured({ "ROLE_APP_ORGANISAATIOHALLINTA" }) public String addImage(@Context HttpServletRequest request, @Context HttpServletResponse response) { LOG.info("Adding attachment " + request.getMethod()); Map<String, String> result = null; try { boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); for (FileItem item : upload.parseRequest(request)) { if (item.getName() != null) { result = storeAttachment(item); } } } else { response.setStatus(400); response.getWriter().append("Not a multipart request"); } LOG.info("Added attachment: " + result); JSONObject json = new JSONObject(result); return json.toString(); } catch (Exception e) { return "organisaatio.fileupload.error"; } }
From source file:net.groupbuy.interceptor.TokenInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String token = WebUtils.getCookie(request, TOKEN_COOKIE_NAME); if (request.getMethod().equalsIgnoreCase("POST")) { String requestType = request.getHeader("X-Requested-With"); if (requestType != null && requestType.equalsIgnoreCase("XMLHttpRequest")) { if (token != null && token.equals(request.getHeader(TOKEN_PARAMETER_NAME))) { return true; } else { response.addHeader("tokenStatus", "accessDenied"); }/* w ww.ja v a2s . c o m*/ } else { if (token != null && token.equals(request.getParameter(TOKEN_PARAMETER_NAME))) { return true; } } if (token == null) { token = UUID.randomUUID().toString(); WebUtils.addCookie(request, response, TOKEN_COOKIE_NAME, token); } response.sendError(HttpServletResponse.SC_FORBIDDEN, ERROR_MESSAGE); return false; } else { if (token == null) { token = UUID.randomUUID().toString(); WebUtils.addCookie(request, response, TOKEN_COOKIE_NAME, token); } request.setAttribute(TOKEN_ATTRIBUTE_NAME, token); return true; } }
From source file:edu.usu.sdl.openstorefront.core.model.ErrorInfo.java
public ErrorInfo(Throwable error, HttpServletRequest request) { this.error = error; if (request != null) { requestUrl = request.getRequestURI(); requestMethod = request.getMethod(); clientIp = NetworkUtil.getClientIp(request); StringBuilder input = new StringBuilder(); if (StringUtils.isNotBlank(request.getQueryString())) { input.append("Query: ").append(request.getQueryString()).append("\n"); }//ww w .ja va 2 s . co m inputData = input.toString(); } }