List of usage examples for javax.servlet.http HttpServletRequest getPathInfo
public String getPathInfo();
From source file:org.redhat.jboss.httppacemaker.ProxyServlet.java
/** Reads the request URI from {@code servletRequest} and rewrites it, considering {@link * #targetUri}. It's used to make the new request. *///from w w w . j a v a 2 s .co m protected String rewriteUrlFromRequest(HttpServletRequest servletRequest) { StringBuilder uri = new StringBuilder(500); uri.append(this.targetUri.toString()); // Handle the path given to the servlet if (servletRequest.getPathInfo() != null) {//ex: /my/path.html uri.append(encodeUriQuery(servletRequest.getPathInfo())); } // Handle the query string String queryString = servletRequest.getQueryString();//ex:(following '?'): name=value&foo=bar#fragment if (queryString != null && queryString.length() > 0) { uri.append('?'); int fragIdx = queryString.indexOf('#'); String queryNoFrag = (fragIdx < 0 ? queryString : queryString.substring(0, fragIdx)); uri.append(encodeUriQuery(queryNoFrag)); if (fragIdx >= 0) { uri.append('#'); uri.append(encodeUriQuery(queryString.substring(fragIdx + 1))); } } return uri.toString(); }
From source file:be.milieuinfo.core.proxy.controller.ProxyServlet.java
private String rewriteUrlFromRequest(HttpServletRequest servletRequest) { StringBuilder uri = new StringBuilder(500); uri.append(this.targetUri.toString()); // Handle the path given to the servlet if (servletRequest.getPathInfo() != null) {//ex: /my/path.html uri.append(servletRequest.getPathInfo()); }//from w ww.j ava2s .com // Handle the query string String queryString = servletRequest.getQueryString();//ex:(following '?'): name=value&foo=bar#fragment if (queryString != null && queryString.length() > 0) { uri.append('?'); int fragIdx = queryString.indexOf('#'); String queryNoFrag = (fragIdx < 0 ? queryString : queryString.substring(0, fragIdx)); uri.append(encodeUriQuery(queryNoFrag)); if (fragIdx >= 0) { uri.append('#'); uri.append(encodeUriQuery(queryString.substring(fragIdx + 1))); } } return uri.toString(); }
From source file:com.sonicle.webtop.vfs.PublicService.java
@Override public void processDefaultAction(HttpServletRequest request, HttpServletResponse response) throws Exception { PublicPath path = new PublicPath(request.getPathInfo()); WebTopSession wts = getWts();/* w w w .ja v a 2 s .c o m*/ try { try { if (path.getContext().equals(PUBPATH_CONTEXT_LINK)) { FileUrlPath fileUrlPath = new FileUrlPath(path.getRemainingPath()); SharingLink link = null; if (!StringUtils.isBlank(fileUrlPath.getLinkId())) { link = manager.getSharingLink(fileUrlPath.getLinkId()); } if (link == null) { // Link not found logger.trace("Link not found [{}]", fileUrlPath.getLinkId()); writeErrorPage(request, response, wts, "linknotfound"); } else if (link.isExpired(DateTimeUtils.now())) { // Link expired logger.trace("Link expired [{}]", fileUrlPath.getLinkId()); writeErrorPage(request, response, wts, "linkexpired"); } else if (!isLinkAuthorized(link)) { // Link not authorized writeLinkPage(request, response, wts, "Authorize", link); } else if (link.getType().equals(SharingLink.TYPE_DOWNLOAD)) { if (PathUtils.isFolder(link.getFilePath())) { Integer dl = ServletUtils.getIntParameter(request, "dl", 0); if (dl == 1) { // Download file request String fileId = ServletUtils.getStringParameter(request, "fileId", true); String outName; if (PathUtils.isFolder(fileId)) { if (PathUtils.isRootFolder(fileId)) { outName = StringUtils.defaultString( PathUtils.getFileName(link.getFilePath()), link.getLinkId()); } else { outName = PathUtils.getFileName(fileId); } outName += ".zip"; } else { outName = PathUtils.getFileName(fileId); } String servicePublicUrl = WT.getServicePublicUrl(wts.getProfileDomainId(), SERVICE_ID); String url = buildPublicLinkPathGetUrl(servicePublicUrl, link, outName, fileId); ServletUtils.setLocationHeader(response, url); response.setStatus(HttpServletResponse.SC_FOUND); } else if (fileUrlPath.isGet()) { // Real binary stream String p = ServletUtils.getStringParameter(request, "p", true); String filePath = PathUtils.concatPaths(link.getFilePath(), p); writeStoreFile(response, link.getStoreId(), filePath, fileUrlPath.getOutFileName()); manager.notifySharingLinkUsage(link.getLinkId(), filePath, wts.getRemoteIP(), wts.getPlainUserAgent()); } else { writeLinkPage(request, response, wts, "DownloadLink", link); } } else { Integer raw = ServletUtils.getIntParameter(request, "raw", 0); if (raw == 1) { // Link points directly to raw data (no preview) String servicePublicUrl = WT.getServicePublicUrl(wts.getProfileDomainId(), SERVICE_ID); String url = VfsManager.buildLinkPublicGetUrl(servicePublicUrl, link); ServletUtils.setLocationHeader(response, url); response.setStatus(HttpServletResponse.SC_FOUND); } else if (fileUrlPath.isGet()) { // Real binary stream writeStoreFile(response, link.getStoreId(), link.getFilePath(), fileUrlPath.getOutFileName()); manager.notifySharingLinkUsage(link.getLinkId(), link.getFilePath(), wts.getRemoteIP(), wts.getPlainUserAgent()); } else { logger.trace("Invalid request"); writeErrorPage(request, response, wts, "badrequest"); } } } else if (link.getType().equals(SharingLink.TYPE_UPLOAD)) { Integer maxUpload = WT.getCoreServiceSettings(SERVICE_ID).getUploadMaxFileSize(); VfsUserSettings us = new VfsUserSettings(SERVICE_ID, link.getProfileId()); JsWTSPublic.Vars vars = new JsWTSPublic.Vars(); vars.put("uploadMaxFileSize", LangUtils.coalesce(us.getPublicUploadMaxFileSize(), maxUpload)); writeLinkPage(request, response, wts, "UploadLink", link, vars); } } else { logger.trace("Invalid context [{}]", path.getContext()); writeErrorPage(request, response, wts, "badrequest"); } } catch (Exception ex) { writeErrorPage(request, response, wts, "badrequest"); //logger.trace("Error", t); } } catch (Throwable t) { logger.error("Unexpected error", t); } }
From source file:com.ewcms.web.pubsub.PubsubServlet.java
/** * Comet event?/*from w w w . j a v a2 s . c o m*/ * * ???<a href = "http://tomcat.apache.org/tomcat-6.0-doc/aio.html#Example_code">ChatServlet</a> * * @param event * The Comet event that will be processed * @throws IOException * @throws ServletException */ public void event(CometEvent event) throws IOException, ServletException { HttpServletRequest request = event.getHttpServletRequest(); HttpServletResponse response = event.getHttpServletResponse(); if (event.getEventType() == CometEvent.EventType.BEGIN) { logger.debug("Begin for session:{} ", request.getSession(true).getId()); String fullContentType = "text/html;charset=UTF-8"; response.setContentType(fullContentType); addConnection(request.getPathInfo(), response); } else if (event.getEventType() == CometEvent.EventType.ERROR) { logger.debug("Error for session: {}", request.getSession(true).getId()); removeConnection(response); event.close(); } else if (event.getEventType() == CometEvent.EventType.END) { logger.debug("End for session:{} ", request.getSession(true).getId()); removeConnection(response); event.close(); } else if (event.getEventType() == CometEvent.EventType.READ) { InputStream is = request.getInputStream(); byte[] buf = new byte[512]; do { int n = is.read(buf); // can throw an IOException if (n > 0) { logger.debug("Read {} bytes:{} for session:{}", new Object[] { n, new String(buf, 0, n), request.getSession(true).getId() }); } else if (n < 0) { return; } } while (is.available() > 0); } }
From source file:com.adobe.acs.commons.http.injectors.AbstractHtmlRequestInjector.java
@SuppressWarnings("squid:S3923") protected boolean accepts(final ServletRequest servletRequest, final ServletResponse servletResponse) { if (!(servletRequest instanceof HttpServletRequest) || !(servletResponse instanceof HttpServletResponse)) { return false; }/*from w w w.ja v a 2 s.co m*/ final HttpServletRequest request = (HttpServletRequest) servletRequest; if (!StringUtils.equalsIgnoreCase("get", request.getMethod())) { // Only inject on GET requests return false; } else if (StringUtils.equals(request.getHeader("X-Requested-With"), "XMLHttpRequest")) { // Do not inject into XHR requests return false; } else if (StringUtils.contains(request.getPathInfo(), ".") && !StringUtils.contains(request.getPathInfo(), ".html")) { // If extension is provided it must be .html return false; } else if (StringUtils.endsWith(request.getHeader("Referer"), "/editor.html" + request.getRequestURI())) { // Do not apply to pages loaded in the TouchUI editor.html return false; } else if (StringUtils.endsWith(request.getHeader("Referer"), "/cf")) { // Do not apply to pages loaded in the Classic Content Finder return false; } // Add HTML check if (log.isTraceEnabled()) { log.trace("Injecting HTML via AbstractHTMLRequestInjector"); } return true; }
From source file:com.telefonica.euro_iaas.paasmanager.rest.auth.OpenStackAuthenticationFilterTest.java
@Test public void doFilterTestRootPath() throws IOException, ServletException { HttpServletRequest servletRequest = mock(HttpServletRequest.class); HttpServletResponse servletResponse = mock(HttpServletResponse.class); FilterChain filterChain = mock(FilterChain.class); HttpSession httpSession = mock(HttpSession.class); when(servletRequest.getHeader(anyString())).thenReturn("3df25213cac246f8bccad5c70cb3582e") .thenReturn("00000000000000000000000000000194"); when(servletRequest.getPathInfo()).thenReturn("/"); when(servletRequest.getRequestURI()).thenReturn("/vdc/00000000000000000000000000000194/"); when(servletRequest.getSession()).thenReturn(httpSession); when(httpSession.getId()).thenReturn("1234"); openStackAuthenticationFilter.doFilter(servletRequest, servletResponse, filterChain); }
From source file:org.apache.hadoop.gateway.AuditLoggingTest.java
@Test /**//from www .j a v a2 s.co m * Empty filter chain. Two events with same correlation ID are expected: * * action=access request_type=uri outcome=unavailable * action=access request_type=uri outcome=success message=Response status: 404 */ public void testNoFiltersAudit() throws ServletException, IOException { FilterConfig config = EasyMock.createNiceMock(FilterConfig.class); EasyMock.replay(config); HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class); ServletContext context = EasyMock.createNiceMock(ServletContext.class); GatewayConfig gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class); EasyMock.expect(request.getMethod()).andReturn(METHOD).anyTimes(); EasyMock.expect(request.getPathInfo()).andReturn(PATH).anyTimes(); EasyMock.expect(request.getContextPath()).andReturn(CONTEXT_PATH).anyTimes(); EasyMock.expect(request.getRemoteAddr()).andReturn(ADDRESS).anyTimes(); EasyMock.expect(request.getRemoteHost()).andReturn(HOST).anyTimes(); EasyMock.expect(request.getServletContext()).andReturn(context).anyTimes(); EasyMock.expect(context.getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE)).andReturn(gatewayConfig) .anyTimes(); EasyMock.expect(gatewayConfig.getHeaderNameForRemoteAddress()).andReturn("Custom-Forwarded-For").anyTimes(); EasyMock.replay(request); EasyMock.replay(context); EasyMock.replay(gatewayConfig); HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class); EasyMock.replay(response); FilterChain chain = EasyMock.createNiceMock(FilterChain.class); EasyMock.replay(chain); GatewayFilter gateway = new GatewayFilter(); gateway.init(config); gateway.doFilter(request, response, chain); gateway.destroy(); assertThat(CollectAppender.queue.size(), is(1)); Iterator<LoggingEvent> iterator = CollectAppender.queue.iterator(); LoggingEvent accessEvent = iterator.next(); verifyAuditEvent(accessEvent, CONTEXT_PATH + PATH, ResourceType.URI, Action.ACCESS, ActionOutcome.UNAVAILABLE, null, "Request method: GET"); }
From source file:com.bright.assetbank.application.servlet.ApplicationActionServlet.java
public void doGet(HttpServletRequest a_request, HttpServletResponse a_response) /* */ throws IOException, ServletException /* */ {/*from w w w.ja v a 2s. c om*/ /* 384 */ super.doGet(a_request, a_response); /* */ /* 386 */ String action = a_request.getPathInfo(); /* */ /* 388 */ if ((StringUtils.isNotEmpty(action)) && (!this.m_noStoreActionSet.contains(action.substring(1)))) /* */ { /* 391 */ if (RequestUtil.getOriginalRequestUrl(a_request) == null) /* */ { /* 395 */ boolean bManualOveride = false; /* 396 */ if (a_request.getSession().getAttribute("manualOveride") != null) /* */ { /* */ try /* */ { /* 400 */ bManualOveride = ((Boolean) a_request.getSession().getAttribute("manualOveride")) .booleanValue(); /* */ } /* */ catch (Exception e) /* */ { /* 405 */ GlobalApplication.getInstance().getLogger().error(e.getMessage()); /* */ } /* */ } /* */ /* 409 */ a_request.getSession().removeAttribute("manualOveride"); /* */ /* 411 */ if (!bManualOveride) /* */ { /* 413 */ String sPath = a_request.getRequestURI() .substring(a_request.getContextPath().length()) + (StringUtils.isNotEmpty(a_request.getQueryString()) ? "?" + a_request.getQueryString() : ""); /* 414 */ a_request.getSession().setAttribute("lastGetRequestUri", sPath); /* */ } /* */ } /* */ } /* */ }
From source file:com.buglabs.bug.ws.program.ProgramServlet.java
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String path = req.getPathInfo(); String response = null;/*from www . j a va 2 s .c o m*/ if (path == null) { // Get a list of description of all programs. resp.setContentType(TEXT_XML_MIME_TYPE); response = getAllBundles(); resp.getWriter().println(response); } else { String id = path.substring(1).trim(); // User should not be able to access System Bundle if (Long.parseLong(id) == 0) { resp.setContentType(TEXT_PLAIN_MIME_TYPE); resp.sendError(503); return; } if (!isNumber(id)) { resp.setContentType(TEXT_PLAIN_MIME_TYPE); resp.sendError(0, "Invalid program id: " + id); return; } Bundle b = findBundleById(id); if (b == null) { resp.setContentType(TEXT_PLAIN_MIME_TYPE); resp.sendError(0, "No program with id: " + id); return; } File jarfile = null; try { URI uri = new URI(b.getLocation()); jarfile = new File(uri); } catch (URISyntaxException e) { log.log(LogService.LOG_ERROR, "Unable to get bundle location, invalid URL.", e); } if (jarfile != null && jarfile.exists() && jarfile.isFile()) { resp.setContentType(APPLICATION_JAVA_ARCHIVE_MIME_TYPE); FileInputStream fis = new FileInputStream(jarfile); IOUtils.copy(fis, resp.getOutputStream()); } else if (jarfile != null && jarfile.exists() && jarfile.isDirectory()) { resp.setContentType(APPLICATION_JAVA_ARCHIVE_MIME_TYPE); File bundleFile = new File(incomingBundleDir + File.separator + BUNDLE_TEMP_FILENAME); jarfile = createJar(jarfile, bundleFile); FileInputStream fis = new FileInputStream(jarfile); IOUtils.copy(fis, resp.getOutputStream()); } else { resp.setContentType(TEXT_PLAIN_MIME_TYPE); resp.sendError(0, "No program with id: " + id); } } }
From source file:org.realityforge.proxy_servlet.AbstractProxyServlet.java
/** * Reads the request URI from {@code servletRequest} and rewrites it, considering {@link * #_targetUri}. It's used to make the new request. *///from w w w .j a v a2s. c om protected String rewriteUrlFromRequest(final HttpServletRequest servletRequest) { final StringBuilder sb = new StringBuilder(500); sb.append(_target); // Handle the path given to the servlet if (null != servletRequest.getPathInfo()) { //ex: /my/path.html sb.append(encodeUriQuery(servletRequest.getPathInfo())); } // Handle the query string //ex:(following '?'): name=value&foo=bar#fragment final String queryString = servletRequest.getQueryString(); if (null != queryString && queryString.length() > 0) { sb.append('?'); final int fragIdx = queryString.indexOf('#'); final String queryNoFrag = (fragIdx < 0 ? queryString : queryString.substring(0, fragIdx)); sb.append(encodeUriQuery(queryNoFrag)); //Fragments should never be sent so we don't.... } return sb.toString(); }