List of usage examples for javax.servlet.http HttpServletRequest getPathInfo
public String getPathInfo();
From source file:nl.npcf.eav.web.EAVController.java
private EAVStore.Path getPath(String skip, boolean skipFirstNode, HttpServletRequest request) throws EAVPathException { int length = skip.length(); String pathInfo = request.getPathInfo(); String path = pathInfo.substring(length); if (path.startsWith(EAVStore.PATH_SEPARATOR)) { path = path.substring(1);/*from w ww . j a va2 s . c o m*/ } if (skipFirstNode) { int slash = path.indexOf(EAVStore.PATH_SEPARATOR); if (slash >= 0) { path = path.substring(slash + 1); } else { path = ""; } } return eavStore.getSchema().createPath(path, false); }
From source file:ch.entwine.weblounge.kernel.endpoint.RuntimeInformationEndpoint.java
/** * Returns the endpoint documentation./* www . j a va2s .c o m*/ * * @return the endpoint documentation */ @GET @Path("/docs") @Produces(MediaType.TEXT_HTML) public String getDocumentation(@Context HttpServletRequest request) { if (docs == null) { String docsPath = request.getRequestURI(); String docsPathExtension = request.getPathInfo(); String servicePath = request.getRequestURI().substring(0, docsPath.length() - docsPathExtension.length()); docs = RuntimeInformationEndpointDocs.createDocumentation(servicePath); } return docs; }
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 {//from w ww . java 2 s . co m checkAcceptType(getAccept(request), getRequestExtension(request.getPathInfo())); } response.setStatus(HttpStatus.SC_OK); safelyBuild(request, response, input, output); }
From source file:com.vmware.photon.controller.api.common.filters.LoggingFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest) { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String requestId = requestIdProvider.get().toString(); LoggingUtils.setRequestId(requestId); logger.debug("Request: {} {}", httpRequest.getMethod(), httpRequest.getPathInfo()); StopWatch stopwatch = new StopWatch(); stopwatch.start();// w w w.j a v a 2 s . co m try { chain.doFilter(request, response); } finally { stopwatch.stop(); String msg = String.format("Response: %s [%s] in %sms", httpRequest.getPathInfo(), httpResponse.getStatus(), stopwatch.getTime()); if (httpResponse.getStatus() == HttpServletResponse.SC_OK) { logger.debug(msg); } else { logger.info(msg); } LoggingUtils.clearRequestId(); } } else { chain.doFilter(request, response); } }
From source file:com.googlesource.gerrit.plugins.github.oauth.OAuthGitFilter.java
private String getRequestPathWithQueryString(HttpServletRequest httpRequest) { String requestPathWithQueryString = httpRequest.getContextPath() + httpRequest.getServletPath() + Strings.nullToEmpty(httpRequest.getPathInfo()) + "?" + httpRequest.getQueryString(); return requestPathWithQueryString; }
From source file:de.mpg.mpdl.inge.pubman.web.servlet.RedirectServlet.java
/** * {@inheritDoc}/* w w w. j a v a 2 s .c o m*/ */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String id = req.getPathInfo().substring(1); boolean download = ("download".equals(req.getParameter("mode"))); boolean tme = ("tme".equals(req.getParameter("mode"))); String userHandle = req.getParameter(LoginHelper.PARAMETERNAME_USERHANDLE); // no component -> viewItemOverviewPage if (!id.contains("/component/")) { StringBuffer redirectUrl = new StringBuffer(); LoginHelper loginHelper = (LoginHelper) req.getSession().getAttribute("LoginHelper"); if (loginHelper != null && loginHelper.isDetailedMode()) { redirectUrl.append("/pubman/faces/viewItemFullPage.jsp?itemId=" + id); } else { redirectUrl.append("/pubman/faces/viewItemOverviewPage.jsp?itemId=" + id); } if (userHandle != null) { redirectUrl.append("&" + LoginHelper.PARAMETERNAME_USERHANDLE + "=" + userHandle); } resp.sendRedirect(redirectUrl.toString()); return; } // is component if (id.contains("/component/")) { String[] pieces = id.split("/"); if (pieces.length != 4) { resp.sendError(404, "File not found"); } // open component or download it if (req.getParameter("mode") == null || download) { try { InputStream input = getContentAsInputStream(req, resp, download, pieces); if (input == null) { return; } byte[] buffer = new byte[2048]; int numRead; long numWritten = 0; OutputStream out = resp.getOutputStream(); while ((numRead = input.read(buffer)) != -1) { logger.debug(numRead + " bytes read."); out.write(buffer, 0, numRead); resp.flushBuffer(); numWritten += numRead; } input.close(); out.close(); } catch (URISyntaxException e) { throw new ServletException(e); } } // view technical metadata if (tme) { OutputStream out = resp.getOutputStream(); resp.setCharacterEncoding("UTF-8"); try { InputStream input = getContentAsInputStream(req, resp, false, pieces); if (input == null) { return; } String b = new String(); try { b = getTechnicalMetadataByTika(input); } catch (TikaException e) { logger.warn("TikaException when parsing " + pieces[3], e); } catch (SAXException e) { logger.warn("SAXException when parsing " + pieces[3], e); } resp.setHeader("Content-Type", "text/plain; charset=UTF-8"); out.write(b.toString().getBytes()); return; } catch (Exception e) { throw new ServletException(e); } } } }
From source file:org.atmosphere.samples.pubsub.spring.PubSubController.java
private void doGet(AtmosphereResource r, HttpServletRequest req, HttpServletResponse res) { // Log all events on the console, including WebSocket events. r.addEventListener(new WebSocketEventListenerAdapter()); res.setContentType("text/html;charset=ISO-8859-1"); Broadcaster b = lookupBroadcaster(req.getPathInfo()); r.setBroadcaster(b);/*from w w w .j a va 2s. co m*/ String header = req.getHeader(HeaderConfig.X_ATMOSPHERE_TRANSPORT); if (HeaderConfig.LONG_POLLING_TRANSPORT.equalsIgnoreCase(header)) { req.setAttribute(ApplicationConfig.RESUME_ON_BROADCAST, Boolean.TRUE); r.suspend(-1); } else { r.suspend(-1); } }
From source file:com.jaspersoft.jasperserver.rest.services.RESTResource.java
@Override protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { String uri = restUtils.extractRepositoryUri(req.getPathInfo()); resourcesManagementRemoteService.deleteResource(uri); resp.setStatus(HttpServletResponse.SC_OK); }
From source file:com.zimbra.common.util.HttpUtil.java
/** * Creates the content disposition value for a given filename. * @param request/*from ww w . j a v a2 s . c om*/ * @param disposition * @param filename * @return */ public static String createContentDisposition(HttpServletRequest request, String disposition, String filename) { StringBuffer result = new StringBuffer(disposition); result.append("; "); // First, check to see if we're just dealing with a straight ascii filename // If that's the case nothing else needs to be done if (StringUtil.isAsciiString(filename) && filename.indexOf('"') == -1) { result.append("filename=").append("\"").append(filename).append("\""); return result.toString(); } // Now here's where it gets fun. Some browsers don't do well with any // encoding -- see <http://stackoverflow.com/questions/1361604> for a // list. Most browsers support RFC 5987 for encoding non-ascii // filenames. String pathInfo = request.getPathInfo(); String ua = request.getHeader("User-Agent"); Browser browser = guessBrowser(ua); int majorVer = browser.getMajorVersion(ua); if (pathInfo != null && pathInfo.endsWith(filename)) { // If we have a path info that matches our filename, we'll leave out the // filename= part of the header and let the browser use that } else if (browser == Browser.IE && majorVer < 9) { result.append("filename=").append(new String( URLCodec.encodeUrl(IE_URL_SAFE, filename.getBytes(Charsets.UTF_8)), Charsets.ISO_8859_1)); } else if (browser == Browser.SAFARI && majorVer < 6 || browser == Browser.CHROME && majorVer < 11) { // force it over to Latin 1 and '?' any of the characters we don't know. result.append("filename=") .append(new String(filename.getBytes(Charsets.ISO_8859_1), Charsets.ISO_8859_1)); } else { // use RFC 5987 result.append("filename*=") // note: the *= is not a typo .append("UTF-8''") // encode it just like IE .append(new String(URLCodec.encodeUrl(IE_URL_SAFE, filename.getBytes(Charsets.UTF_8)), Charsets.ISO_8859_1)); } return result.toString(); }