Java Code Examples for org.eclipse.jetty.server.Request#getPathInfo()
The following examples show how to use
org.eclipse.jetty.server.Request#getPathInfo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UIControlsHandler.java From haxademic with MIT License | 6 votes |
@Override public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException { // Get request path and check to see if it looks like a file String requestPath = baseRequest.getPathInfo(); String requestPathNoSlash = requestPath.substring(1); if(WebServer.DEBUG == true) P.println("requestPath", requestPath); String[] pathComponents = requestPathNoSlash.split("/"); String result = handleCustomPaths(requestPath, pathComponents); if(result != null) { // Set response props response.addHeader("Access-Control-Allow-Origin", "*"); // Disable CORS response.setStatus(HttpServletResponse.SC_OK); // set 200 response.setContentType("text/json; charset=utf-8"); // default to json // Inform jetty that this request has now been handled response.getWriter().println(result); baseRequest.setHandled(true); } }
Example 2
Source File: TraceHandlerDelegate.java From buck with Apache License 2.0 | 6 votes |
@Override @Nullable public ImmutableMap<String, Object> getDataForRequest(Request baseRequest) throws IOException { String path = baseRequest.getPathInfo(); Matcher matcher = TraceDataHandler.ID_PATTERN.matcher(path); if (!matcher.matches()) { return null; } ImmutableMap.Builder<String, Object> templateData = ImmutableMap.builder(); String id = matcher.group(1); templateData.put("traceId", id); // Read the args to `buck` out of the Chrome Trace. TraceAttributes traceAttributes = buildTraces.getTraceAttributesFor(id); templateData.put("dateTime", traceAttributes.getFormattedDateTime()); if (traceAttributes.getCommand().isPresent()) { templateData.put("command", traceAttributes.getCommand().get()); } return templateData.build(); }
Example 3
Source File: TestRequestDispatcher.java From joynr with Apache License 2.0 | 6 votes |
private void forwardToUrl(final String targetContextPath, Request baseRequest, HttpServletResponse response) throws ServletException, IOException { logger.info("Forward request {} to context {}", baseRequest.toString(), targetContextPath); synchronized (contextForwardCounts) { int currentContextForwardCount = 0; if (contextForwardCounts.containsKey(targetContextPath)) { currentContextForwardCount = contextForwardCounts.get(targetContextPath); } contextForwardCounts.put(targetContextPath, currentContextForwardCount + 1); } ServletContext currentContext = baseRequest.getServletContext(); String currentContextPath = currentContext.getContextPath(); String forwardContextPath = currentContextPath.replace(ClusteredBounceProxyWithDispatcher.CONTEXT_DISPATCHER, targetContextPath); ServletContext forwardContext = currentContext.getContext(forwardContextPath); String forwardPath = baseRequest.getPathInfo(); RequestDispatcher requestDispatcher = forwardContext.getRequestDispatcher(forwardPath); requestDispatcher.forward(baseRequest, response); }
Example 4
Source File: WebServerRequestHandler.java From haxademic with MIT License | 4 votes |
@Override public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException { // Get request path and check to see if it looks like a file String requestPath = baseRequest.getPathInfo(); // if path ends with a slash, append index.html if(requestPath.lastIndexOf("/") == requestPath.length() - 1) { requestPath += "index.html"; } // get path without initial slash String requestPathNoSlash = requestPath.substring(1); if(WebServer.DEBUG == true) P.println("requestPath", requestPath); // Set response props response.addHeader("Access-Control-Allow-Origin", "*"); // Disable CORS response.setStatus(HttpServletResponse.SC_OK); // set 200 response.setContentType("text/html; charset=utf-8"); // default to text // look for static files on the www filesystem String filePathToCheck = WebServer.WWW_PATH + requestPathNoSlash; // check to redirect if no trailing slash, but has index.html if(FileUtil.fileExists(filePathToCheck + "/index.html") == true) { requestPath += "/"; response.sendRedirect(requestPath); baseRequest.setHandled(true); return; } // CHECK FOR (& SERVE) STATIC FILES if(FileUtil.fileExists(filePathToCheck)) { String filePath = filePathToCheck; if(WebServer.DEBUG == true) P.println("Found static file:", filePath); if(filePath.indexOf(".html") != -1) { writeTextFileFromPath(response, filePath, "text/html"); } else if(filePath.indexOf(".css") != -1) { writeTextFileFromPath(response, filePath, "text/css"); } else if(filePath.indexOf(".js") != -1) { writeTextFileFromPath(response, filePath, "application/javascript"); } else if(filePath.indexOf(".svg") != -1) { writeTextFileFromPath(response, filePath, "image/svg+xml"); } else if(filePath.indexOf(".ttf") != -1 || filePath.indexOf(".otf") != -1) { writeBinaryFileFromPath(response, filePath, "application/font-sfnt"); } else if(filePath.indexOf(".png") != -1) { writeBinaryFileFromPath(response, filePath, "image/png"); } else if(filePath.indexOf(".jpg") != -1) { writeBinaryFileFromPath(response, filePath, "image/jpeg"); } else if(filePath.indexOf(".gif") != -1) { writeBinaryFileFromPath(response, filePath, "image/gif"); } else if(filePath.indexOf(".tga") != -1) { writeBinaryFileFromPath(response, filePath, "image/targa"); } } else { String[] pathComponents = requestPathNoSlash.split("/"); String result = handleCustomPaths(requestPath, pathComponents); if(result != null) { response.getWriter().println(result); } else { response.getWriter().println("{\"log\": \"No Response\"}"); } } // Inform jetty that this request has now been handled baseRequest.setHandled(true); }
Example 5
Source File: TraceDataHandler.java From buck with Apache License 2.0 | 4 votes |
private void doGet(Request baseRequest, HttpServletResponse response) throws IOException { String path = baseRequest.getPathInfo(); Matcher matcher = ID_PATTERN.matcher(path); if (!matcher.matches()) { Responses.writeFailedResponse(baseRequest, response); return; } String id = matcher.group(1); response.setContentType(MediaType.JAVASCRIPT_UTF_8.toString()); response.setStatus(HttpServletResponse.SC_OK); boolean hasValidCallbackParam = false; Writer responseWriter = response.getWriter(); String callback = baseRequest.getParameter("callback"); if (callback != null) { Matcher callbackMatcher = CALLBACK_PATTERN.matcher(callback); if (callbackMatcher.matches()) { hasValidCallbackParam = true; responseWriter.write(callback); responseWriter.write("("); } } responseWriter.write("["); Iterator<InputStream> traceStreams = buildTraces.getInputsForTraces(id).iterator(); boolean isFirst = true; while (traceStreams.hasNext()) { if (!isFirst) { responseWriter.write(","); } else { isFirst = false; } try (InputStream input = traceStreams.next(); InputStreamReader inputStreamReader = new InputStreamReader(input)) { CharStreams.copy(inputStreamReader, responseWriter); } } responseWriter.write("]"); if (hasValidCallbackParam) { responseWriter.write(");\n"); } response.flushBuffer(); baseRequest.setHandled(true); }