List of usage examples for javax.servlet.http HttpServletRequest getMethod
public String getMethod();
From source file:it.unitn.disi.smatch.webapi.server.controllers.AbstractController.java
protected JSONObject getJSONRaw(HttpServletRequest request) throws IOException, JSONException { InputStream in = request.getInputStream(); int len = 0;//from ww w . j av a 2 s . c o m byte[] b = new byte[KB]; StringBuffer buff = new StringBuffer(); while ((len = in.read(b)) > 0) { buff.append(new String(b, 0, len)); } logger.debug("REQUEST: " + request.getMethod() + " " + request.getRequestURI() + "\n" + buff.toString()); return new JSONObject(buff.toString()); }
From source file:com.ucap.uccc.cmis.impl.webservices.CmisWebServicesServlet.java
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // set CMIS version request.setAttribute(CMIS_VERSION, cmisVersion); // handle GET requests if (request.getMethod().equals("GET")) { UrlBuilder baseUrl = compileBaseUrl(request, response); String queryString = request.getQueryString(); if (queryString != null) { String doc = docs.get(queryString.toLowerCase(Locale.ENGLISH)); if (doc != null) { printXml(request, response, doc, baseUrl); return; }// w w w . ja va 2 s . co m } printPage(request, response, baseUrl); return; } // handle other non-POST requests if (!request.getMethod().equals("POST")) { printError(request, response, "Not a HTTP POST request."); return; } // handle POST requests ProtectionRequestWrapper requestWrapper = null; try { requestWrapper = new ProtectionRequestWrapper(request, MAX_SOAP_SIZE); } catch (ServletException e) { printError(request, response, "The request is not MTOM encoded."); return; } super.service(requestWrapper, response); }
From source file:com.yoshio3.modules.AzureADServerAuthModule.java
public boolean isRedirectedRequestFromAuthServer(HttpServletRequest httpRequest, Map<String, String> params) { return httpRequest.getMethod().equalsIgnoreCase("POST") && (httpRequest.getParameterMap().containsKey(ERROR) || httpRequest.getParameterMap().containsKey(ID_TOKEN) || httpRequest.getParameterMap().containsKey(CODE)); }
From source file:com.google.appengine.tools.mapreduce.MapReduceServletTest.java
public void testGetJobDetailCSRF() { JobID jobId = new JobID("foo", 1); // Send it as a task queue request but not an ajax request - should be denied. HttpServletRequest request = createMockRequest( MapReduceServlet.COMMAND_PATH + "/" + MapReduceServlet.GET_JOB_DETAIL_PATH, true, false); expect(request.getMethod()).andReturn("POST").anyTimes(); expect(request.getParameter(AppEngineJobContext.JOB_ID_PARAMETER_NAME)).andReturn("" + jobId).anyTimes(); HttpServletResponse response = createMock(HttpServletResponse.class); // Set before error and last one wins, so this is harmless. response.setContentType("application/json"); EasyMock.expectLastCall().anyTimes(); try {//from w ww . j a v a2 s .c o m response.sendError(403, "Received unexpected non-XMLHttpRequest command."); } catch (IOException ioe) { // Can't actually be sent in mock setup } replay(request, response); servlet.doGet(request, response); verify(request, response); }
From source file:ltistarter.controllers.BaseController.java
/** * Just populate some common model stuff for less repeating * * @param req the request/*from ww w. j a v a 2 s . c om*/ * @param principal the current security principal (if there is one) * @param model the model */ void commonModelPopulate(HttpServletRequest req, Principal principal, Model model) { model.addAttribute("today", new Date()); // TODO real user and pass model.addAttribute("basicUser", "admin"); model.addAttribute("basicPass", "admin"); // TODO real key and secret? model.addAttribute("oauthKey", "key"); model.addAttribute("oauthSecret", "secret"); // a little extra request handling stuff model.addAttribute("req", req); model.addAttribute("reqURI", req.getMethod() + " " + req.getRequestURI()); // current user model.addAttribute("username", principal != null ? principal.getName() : "ANONYMOUS"); }
From source file:com.nebhale.cyclinglibrary.web.GzipFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { HttpServletRequest newRequest;// ww w . ja v a2 s .co m if (sendsGzipEncoding(request)) { newRequest = new DelegatingHttpServletRequest(request, new GZIPInputStream(request.getInputStream())); } else { String method = request.getMethod(); if ("POST".equals(method) || "PUT".equals(method)) { this.logger.warn("Uncompressed input received for '{} {}'", method, request.getRequestURI()); } newRequest = request; } HttpServletResponse newResponse; OutputStream outputStream; if (acceptsGzipEncoding(request)) { response.setHeader("Content-Encoding", "gzip"); outputStream = new GZIPOutputStream(response.getOutputStream()); newResponse = new DelegatingHttpServletResponse(response, outputStream); } else { String method = request.getMethod(); if (!"DELETE".equals(method)) { this.logger.warn("Uncompressed output requested for '{} {}'", method, request.getRequestURI()); } outputStream = response.getOutputStream(); newResponse = response; } filterChain.doFilter(newRequest, newResponse); }
From source file:com.globalsight.everest.webapp.pagehandler.administration.config.fileextension.FileExtensionMainHandler.java
private void handleFilters(HttpServletRequest p_request, SessionManager sessionMgr, String action) { String FileExtensionName = (String) p_request.getParameter("FileExtensionName"); String FileExtensionCName = (String) p_request.getParameter("FileExtensionCName"); if (p_request.getMethod().equalsIgnoreCase(WebAppConstants.REQUEST_METHOD_GET)) { FileExtensionName = (String) sessionMgr.getAttribute("FileExtensionName"); FileExtensionCName = (String) sessionMgr.getAttribute("FileExtensionCName"); }//from ww w .jav a2 s . com sessionMgr.setAttribute("FileExtensionName", FileExtensionName); sessionMgr.setAttribute("FileExtensionCName", FileExtensionCName); }
From source file:com.google.appengine.tools.mapreduce.MapReduceServletTest.java
public void testCommandError() throws Exception { HttpServletRequest request = createMockRequest( MapReduceServlet.COMMAND_PATH + "/" + MapReduceServlet.GET_JOB_DETAIL_PATH, false, true); expect(request.getMethod()).andReturn("GET").anyTimes(); HttpServletResponse response = createMock(HttpServletResponse.class); PrintWriter responseWriter = createMock(PrintWriter.class); responseWriter.write('{'); responseWriter.write("\"error_class\""); responseWriter.write(':'); responseWriter.write("\"java.lang.RuntimeException\""); responseWriter.write(','); responseWriter.write("\"error_message\""); responseWriter.write(':'); responseWriter.write("\"Full stack trace is available in the server logs. " + "Message: blargh\""); responseWriter.write('}'); responseWriter.flush();/*from ww w.ja va2s . c o m*/ // This method can't actually throw this exception, but that's not // important to the test. expect(request.getParameter("mapreduce_id")).andThrow(new RuntimeException("blargh")); response.setContentType("application/json"); expect(response.getWriter()).andReturn(responseWriter).anyTimes(); replay(request, response, responseWriter); servlet.doPost(request, response); verify(request, response, responseWriter); }
From source file:com.erudika.para.security.RestAuthFilter.java
private boolean userAuthRequestHandler(HttpServletRequest request, HttpServletResponse response) { Authentication userAuth = SecurityContextHolder.getContext().getAuthentication(); User user = SecurityUtils.getAuthenticatedUser(userAuth); String reqUri = request.getRequestURI(); String method = request.getMethod(); if (user != null && user.getActive()) { App parentApp;//from ww w . j a v a 2s . com if (userAuth instanceof JWTAuthentication) { parentApp = ((JWTAuthentication) userAuth).getApp(); } else { parentApp = Para.getDAO().read(App.id(user.getAppid())); } if (parentApp != null) { String resource = RestUtils.extractResourceName(request); if (!parentApp.isAllowedTo(user.getId(), resource, request.getMethod())) { RestUtils .returnStatusResponse(response, HttpServletResponse.SC_FORBIDDEN, Utils.formatMessage( "You don't have permission to access this resource. " + "[user: {0}, resource: {1} {2}]", user.getId(), method, reqUri)); return false; } } else { RestUtils.returnStatusResponse(response, HttpServletResponse.SC_NOT_FOUND, "App not found."); return false; } } else { RestUtils.returnStatusResponse(response, HttpServletResponse.SC_UNAUTHORIZED, Utils .formatMessage("You don't have permission to access this resource. [{0} {1}]", method, reqUri)); return false; } return true; }
From source file:de.jaxenter.eesummit.caroline.gui.filter.LogFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { String remoteAddress = null;/*from w w w.j a v a 2 s .co m*/ String sessionId = null; String uid = "0"; long start = 0; String url = ""; String method = ""; Throwable throwable = null; boolean dropped = false; String agent = null; try { Validate.isTrue(request instanceof HttpServletRequest, "filter oops?"); HttpServletRequest req = (HttpServletRequest) request; if (req.getCharacterEncoding() == null || forceRequestEncoding) { req.setCharacterEncoding(requestEncoding); } url = req.getRequestURI(); method = req.getMethod(); String qs = req.getQueryString(); agent = req.getHeader("User-Agent"); if (qs != null) { url += "?" + qs; } for (String stopUrl : dropUrls) { // does any stopUrl match url if (url.indexOf(stopUrl) != -1) { dropped = true; break; // stop searching } } if (!dropped) { if (ndcEnabled) { if (ndcAddress) { String forwarded = req.getHeader("X-Forwarded-For"); if (forwarded != null) { remoteAddress = forwarded; } else { remoteAddress = request.getRemoteAddr(); } } if (ndcSession) { HttpSession session = req.getSession(false); // do not create if (session != null) { sessionId = session.getId(); String sessOID = (String) session.getAttribute("USER_ID_LOG"); uid = sessOID == null ? "0" : sessOID; } } } StringBuilder msg = simulateNDC(remoteAddress, sessionId, uid); msg.append("request start ").append(method).append(" ").append(url).append(" UA=").append(agent); logger.info(msg.toString()); start = System.currentTimeMillis(); } filterChain.doFilter(request, response); } catch (IOException e) { throwable = e; throw e; } catch (ServletException e) { if (e.getRootCause() != null) { throwable = e.getRootCause(); } else { throwable = e; } throw e; } catch (Throwable e) { // be sure to get all errors throwable = e; throw new ServletException(e); } finally { if (!dropped) { long time = System.currentTimeMillis() - start; StringBuilder msg = simulateNDC(remoteAddress, sessionId, uid); msg.append("request done ").append(method).append(" "); msg.append(url).append(" time=").append(time).append("ms"); if (throwable == null) { logger.info(msg.toString()); } else { String name = throwable.getClass().getSimpleName(); msg.append(" ex=").append(name); msg.append(" msg=").append(throwable.getMessage()); if (name.equals("ViewExpiredException") || name.equals("ClientAbortException")) { logger.warn(msg.toString()); } else { msg.append(" UA=").append(agent); // also log agent in error case logger.error(msg.toString()); } } } } }