List of usage examples for javax.servlet.http HttpServletRequest getRequestURI
public String getRequestURI();
From source file:org.myjerry.evenstar.web.controller.PageNotFoundController.java
@Override public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { // extract the request URI // and check to see if this is a blog page URL // if yes - go ahead and display the page String uri = request.getRequestURI(); BlogPost post = this.blogPostService.getPostForURI(uri); if (post != null) { RequestDispatcher dispatcher = request.getRequestDispatcher( "/viewPost.html?postID=" + post.getPostID() + "&blogID=" + post.getBlogID()); dispatcher.forward(request, response); return null; }//from w ww .java 2 s .c o m ModelAndView mav = new ModelAndView(); mav.setViewName(".page.not.found"); return mav; }
From source file:com.google.appinventor.server.WebAppLaunchServlet.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { String userId = userInfoProvider.getUserId(); String launchFile;/*from ww w .ja v a 2s . c om*/ try { String uri = req.getRequestURI(); // First, call split with no limit parameter. String[] uriComponents = uri.split("/"); String launchKind = uriComponents[REQUEST_INDEX]; if (launchKind.equals(ServerLayout.WEBAPP_FILE)) { uriComponents = uri.split("/", SPLIT_LIMIT_FILE); if (FILE_PATH_INDEX > uriComponents.length) { throw CrashReport.createAndLogError(LOG, req, null, new IllegalArgumentException("Missing web app file path.")); } String fileName = uriComponents[FILE_PATH_INDEX]; launchFile = storageIo.downloadUserFile(userId, fileName, "UTF-8"); } else { throw CrashReport.createAndLogError(LOG, req, null, new IllegalArgumentException("Unknown launch kind: " + launchKind)); } } catch (IllegalArgumentException e) { throw CrashReport.createAndLogError(LOG, req, null, e); } byte[] content = launchFile.getBytes(); // Set http response information resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType("text/html"); resp.setContentLength(launchFile.length()); // Attach download data ServletOutputStream out = resp.getOutputStream(); out.write(content); out.close(); }
From source file:belajar.nfc.controller.OptionsController.java
@RequestMapping(method = RequestMethod.OPTIONS) public void handleOptionsUser(HttpServletRequest request, HttpServletResponse response) { String host = request.getHeader("Host"); String origin = request.getHeader("Origin"); LOGGER.info("Options Controller URI [{}] method [{}] headers [{}] ipserver [{}]", new Object[] { request.getRequestURI(), request.getMethod(), origin, host }); }
From source file:cn.im47.cloud.storage.utilities.RangingResourceHttpRequestHandler.java
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String requestURI = request.getRequestURI(); String contextPath = request.getContextPath(); String requestPath = requestURI.substring(contextPath.length()); //locations are set up for delegation if desired /*//from ww w .j a va 2 s . com if (!requestPath.startsWith("/media/")) { super.handleRequest(request, response); } */ boolean useRanges = false; int rangeStart = 0; int rangeEnd = 0; String rangeHeader = request.getHeader(RANGE); if (null != rangeHeader) { try { if (rangeHeader.startsWith(BYTES_PREFIX)) { String range = rangeHeader.substring(BYTES_PREFIX.length()); int splitIndex = range.indexOf("-"); String startString = range.substring(0, splitIndex); String endString = range.substring(splitIndex + 1); rangeStart = Integer.parseInt(startString); rangeEnd = Integer.parseInt(endString); useRanges = true; } } catch (Exception e) { useRanges = false; if (log.isLoggable(Level.FINE)) { log.fine("Unable to decode range header " + rangeHeader); } } } response.setContentType(context.getServletContext().getMimeType(requestPath)); response.setHeader("Accept-Ranges", "bytes"); Resource theResource = context.getResource(requestPath); String contentLength = Long.toString(theResource.contentLength()); InputStream in = context.getResource(requestPath).getInputStream(); OutputStream out = response.getOutputStream(); if (useRanges) { response.setHeader(CONTENT_RANGE, "bytes " + rangeStart + "-" + rangeEnd + "/" + contentLength); response.setContentLength(1 + rangeEnd - rangeStart); copyStream(in, out, rangeStart, rangeEnd); } else { copyStream(in, out); } }
From source file:com.flipkart.phantom.runtime.impl.jetty.filter.ServletTraceFilter.java
/** Helper method to get the span name from trace data or the request */ private String getSpanName(TraceData traceData, HttpServletRequest request) { if (traceData.getSpanName() == null || traceData.getSpanName().isEmpty()) { return request.getRequestURI(); }//from w w w .j av a 2s. c om return traceData.getSpanName(); }
From source file:com.erudika.para.security.LinkedInAuthFilter.java
/** * Handles an authentication request./* w ww. j a va2s. co m*/ * @param request HTTP request * @param response HTTP response * @return an authentication object that contains the principal object if successful. * @throws IOException ex */ @Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws IOException { final String requestURI = request.getRequestURI(); UserAuthentication userAuth = null; if (requestURI.endsWith(LINKEDIN_ACTION)) { String authCode = request.getParameter("code"); if (!StringUtils.isBlank(authCode)) { String url = Utils.formatMessage(TOKEN_URL, authCode, request.getRequestURL().toString(), Config.LINKEDIN_APP_ID, Config.LINKEDIN_SECRET); HttpPost tokenPost = new HttpPost(url); CloseableHttpResponse resp1 = httpclient.execute(tokenPost); if (resp1 != null && resp1.getEntity() != null) { Map<String, Object> token = jreader.readValue(resp1.getEntity().getContent()); if (token != null && token.containsKey("access_token")) { userAuth = getOrCreateUser(null, (String) token.get("access_token")); } EntityUtils.consumeQuietly(resp1.getEntity()); } } } User user = SecurityUtils.getAuthenticatedUser(userAuth); if (userAuth == null || user == null || user.getIdentifier() == null) { throw new BadCredentialsException("Bad credentials."); } else if (!user.getActive()) { throw new LockedException("Account is locked."); } return userAuth; }
From source file:com.jk.web.filters.JKDefaultFilter.java
@Override public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) throws IOException, ServletException { try {/*w w w . j a v a2s .c o m*/ final HttpServletRequest request = (HttpServletRequest) req; final HttpServletResponse response = (HttpServletResponse) res; this.logger.info("@doFilter : ".concat(request.getRequestURI())); JKWebContextUtil.sync(request); final boolean multipart = ServletFileUpload.isMultipartContent(request); if (!multipart) { final boolean toPdf = request.getParameter(JKWebConstants.PARAMTER_CONVERT_TO_PDF) != null; if (toPdf) { this.logger.info("toPDF request"); final HttpServletRequestWrapper rq = new HttpServletRequestWrapper(request); final CharResponseWrapper rs = new CharResponseWrapper(response); chain.doFilter(rq, rs); JKWebUtil.toPDF(request, response, rs.toString()); } else { chain.doFilter(request, response); } } else { chain.doFilter(request, response); } } catch (final Exception e) { if (e instanceof ServletException) { throw (ServletException) e; } throw new ServletException(e); } finally { JKThreadLocal.remove(); this.logger.info("@End of doFilter"); } }
From source file:com.npower.dl.OMADownloadServlet.java
public void doInstallNotification(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String uri = request.getRequestURI(); log.info("Download Service: Install Notification: uri: " + uri); //String downloadID = DownloadDescriptorFactory.parserDownloadID(uri); try {//from w ww. j av a 2 s.co m log.info("Receive Install Notification: " + uri); } catch (Exception ex) { throw new ServletException(ex); } finally { } }
From source file:net.community.chest.gitcloud.facade.backend.git.GitBackendServlet.java
@Override protected void service(HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException { if (logger.isDebugEnabled()) { logger.debug(//w w w .ja v a 2 s .co m "service(" + req.getMethod() + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]"); } if (logger.isTraceEnabled()) { logHeaders(req, ServletUtils.getRequestHeaders(req), "REQ"); } super.service(req, rsp); if (logger.isDebugEnabled()) { logger.debug("service(" + req.getMethod() + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]" + " Content-Type: " + rsp.getContentType() + ", status=" + rsp.getStatus()); } if (logger.isTraceEnabled()) { logHeaders(req, ServletUtils.getResponseHeaders(rsp), "RSP"); } }