@Override public void init(final ServletConfig config) throws ServletException { super.init(config); defaultServlet = new DefaultServlet(); defaultServlet.init(config); }
defaultServlet.service(request, response); return;
@Override protected boolean checkIfHeaders(HttpServletRequest request, HttpServletResponse response, WebResource resource) throws IOException { if (!super.checkIfHeaders(request, response, resource)) return false; // TODO : Checking the WebDAV If header return true; }
/** * Check if the conditions specified in the optional If headers are * satisfied. * * @param request The servlet request we are processing * @param response The servlet response we are creating * @param resource The resource * @return <code>true</code> if the resource meets all the specified * conditions, and <code>false</code> if any of the conditions is not * satisfied, in which case request processing is stopped * @throws IOException an IO error occurred */ protected boolean checkIfHeaders(HttpServletRequest request, HttpServletResponse response, WebResource resource) throws IOException { return checkIfMatch(request, response, resource) && checkIfModifiedSince(request, response, resource) && checkIfNoneMatch(request, response, resource) && checkIfUnmodifiedSince(request, response, resource); }
String path = getRelativePath(request); if (debug > 0) { if (content) log("DefaultServlet.serveResource: Serving resource '" + path + "' headers and data"); else log("DefaultServlet.serveResource: Serving resource '" + path + "' headers only"); (request.getAttribute(Globals.INCLUDE_CONTEXT_PATH_ATTR) != null); if (!included && !checkIfHeaders(request, response, cacheEntry.attributes)) { return; contentType = getServletContext().getMimeType(cacheEntry.name); cacheEntry.attributes.setMimeType(contentType); ranges = parseRange(request, response, cacheEntry.attributes); response.setHeader("ETag", getETag(cacheEntry.attributes)); log("DefaultServlet.serveFile: contentType='" + contentType + "'"); response.setContentType(contentType); log("DefaultServlet.serveFile: contentLength=" + contentLength); if (contentLength < Integer.MAX_VALUE) {
String path = getRelativePath(request, true); log("DefaultServlet.serveResource: Serving resource '" + path + "' headers and data"); else log("DefaultServlet.serveResource: Serving resource '" + path + "' headers only"); doDirectoryRedirect(request, response); return; if (!included && !isError && !checkIfHeaders(request, response, resource)) { return; contentType = getServletContext().getMimeType(resource.getName()); resource.setMimeType(contentType); !pathEndsWithCompressedExtension(path)) { List<PrecompressedResource> precompressedResources = getAvailablePrecompressedResources(path); if (!precompressedResources.isEmpty()) { ResponseUtil.addVaryFieldName(response, "accept-encoding"); PrecompressedResource bestResource = getBestPrecompressedResource(request, precompressedResources); if (bestResource != null) { response.addHeader("Content-Encoding", bestResource.format.encoding); doDirectoryRedirect(request, response); return;
/** * Get the readme file as a string. */ protected String getReadme(DirContext directory) { if (readmeFile!=null) { try { Object obj = directory.lookup(readmeFile); if (obj!=null && obj instanceof Resource) { StringWriter buffer = new StringWriter(); InputStream is = ((Resource)obj).streamContent(); copyRange(new InputStreamReader(is), new PrintWriter(buffer)); return buffer.toString(); } } catch(IOException ioe) { log("DefaultServlet.getReadme: IO exception: " + ioe.getMessage()); } catch (NamingException ne) { log("DefaultServlet.getReadme: Naming exception: " + ne.getMessage()); } } return null; }
/** * Copy the contents of the specified input stream to the specified * output stream, and ensure that both streams are closed before returning * (even in the face of an exception). * * @param is The input stream to read the source resource from * @param ostream The output stream to write to * * @exception IOException if an input/output error occurs */ protected void copy(InputStream is, ServletOutputStream ostream) throws IOException { IOException exception = null; InputStream istream = new BufferedInputStream(is, input); // Copy the input stream to the output stream exception = copyRange(istream, ostream); // Clean up the input stream istream.close(); // Rethrow any exception that has occurred if (exception != null) throw exception; }
/** * Initialize this servlet. */ public void init() throws ServletException { super.init(); if (getServletConfig().getInitParameter("secret") != null) secret = getServletConfig().getInitParameter("secret"); }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String uri = URLEncoder.encode(request.getRequestURI(), "UTF-8"); if (request.getAttribute(REQUEST_IN_ALLOW_LIST) != null || request.getAttribute("_jsp_" + uri) != null) { if (request.getRequestURI().toLowerCase(Locale.getDefault()).endsWith(".jsp") || request.getRequestURI().toLowerCase(Locale.getDefault()).endsWith(".jspx") ) { JspServlet jspServlet = new JspServlet(); jspServlet.init(this.getServletConfig()); jspServlet.service(request, response); } else { DefaultServlet defaultServlet = new DefaultServlet(); defaultServlet.init(this.getServletConfig()); defaultServlet.service(request, response); } return; } super.doGet(request, response); }
String path = getRelativePath(request); if (debug > 0) { if (serveContent) log("DefaultServlet.serveResource: Serving resource '" + path + "' headers and data"); else log("DefaultServlet.serveResource: Serving resource '" + path + "' headers only"); RequestDispatcher.INCLUDE_CONTEXT_PATH) != null); if (!included && !isError && !checkIfHeaders(request, response, cacheEntry.attributes)) { return; contentType = getServletContext().getMimeType(cacheEntry.name); cacheEntry.attributes.setMimeType(contentType); ranges = parseRange(request, response, cacheEntry.attributes); log("DefaultServlet.serveFile: contentType='" + contentType + "'"); response.setContentType(contentType); log("DefaultServlet.serveFile: contentLength=" + contentLength); if (contentLength < Integer.MAX_VALUE) { renderResult = render(getPathPrefix(request), cacheEntry);
/** * Check if the conditions specified in the optional If headers are * satisfied. * * @param request The servlet request we are processing * @param response The servlet response we are creating * @param resource The resource * @return boolean true if the resource meets all the specified conditions, * and false if any of the conditions is not satisfied, in which case * request processing is stopped */ protected boolean checkIfHeaders(HttpServletRequest request, HttpServletResponse response, WebResource resource) throws IOException { return checkIfMatch(request, response, resource) && checkIfModifiedSince(request, response, resource) && checkIfNoneMatch(request, response, resource) && checkIfUnmodifiedSince(request, response, resource); }
String path = getRelativePath(request, true); log("DefaultServlet.serveResource: Serving resource '" + path + "' headers and data"); else log("DefaultServlet.serveResource: Serving resource '" + path + "' headers only"); doDirectoryRedirect(request, response); return; if (!included && !isError && !checkIfHeaders(request, response, resource)) { return; contentType = getServletContext().getMimeType(resource.getName()); resource.setMimeType(contentType); !pathEndsWithCompressedExtension(path)) { List<PrecompressedResource> precompressedResources = getAvailablePrecompressedResources(path); if (!precompressedResources.isEmpty()) { ResponseUtil.addVaryFieldName(response, "accept-encoding"); PrecompressedResource bestResource = getBestPrecompressedResource(request, precompressedResources); if (bestResource != null) { response.addHeader("Content-Encoding", bestResource.format.encoding); doDirectoryRedirect(request, response); return;
/** * Copy the contents of the specified input stream to the specified * output stream, and ensure that both streams are closed before returning * (even in the face of an exception). * * @param resourceInfo The ResourceInfo object * @param ostream The output stream to write to * @param range Range the client wanted to retrieve * @exception IOException if an input/output error occurs */ protected void copy(CacheEntry cacheEntry, ServletOutputStream ostream, Range range) throws IOException { IOException exception = null; InputStream resourceInputStream = cacheEntry.resource.streamContent(); InputStream istream = new BufferedInputStream(resourceInputStream, input); exception = copyRange(istream, ostream, range.start, range.end); // Clean up the input stream try { istream.close(); } catch (Exception e) { log("DefaultServlet.copy: exception closing input stream: " + e.getMessage()); } // Rethrow any exception that has occurred if (exception != null) { throw exception; } }
/** * Copy the contents of the specified input stream to the specified * output stream, and ensure that both streams are closed before returning * (even in the face of an exception). * * @param is The input stream to read the source resource from * @param ostream The output stream to write to * * @exception IOException if an input/output error occurs */ protected void copy(InputStream is, ServletOutputStream ostream) throws IOException { IOException exception = null; InputStream istream = new BufferedInputStream(is, input); // Copy the input stream to the output stream exception = copyRange(istream, ostream); // Clean up the input stream istream.close(); // Rethrow any exception that has occurred if (exception != null) throw exception; }
/** * Initialize this servlet. */ @Override public void init() throws ServletException { super.init(); if (getServletConfig().getInitParameter("secret") != null) secret = getServletConfig().getInitParameter("secret"); if (getServletConfig().getInitParameter("maxDepth") != null) maxDepth = Integer.parseInt( getServletConfig().getInitParameter("maxDepth")); if (getServletConfig().getInitParameter("allowSpecialPaths") != null) allowSpecialPaths = Boolean.parseBoolean( getServletConfig().getInitParameter("allowSpecialPaths")); }
String path = getRelativePath(request); if (debug > 0) { if (serveContent) log("DefaultServlet.serveResource: Serving resource '" + path + "' headers and data"); else log("DefaultServlet.serveResource: Serving resource '" + path + "' headers only"); RequestDispatcher.INCLUDE_CONTEXT_PATH) != null); if (!included && !isError && !checkIfHeaders(request, response, cacheEntry.attributes)) { return; contentType = getServletContext().getMimeType(cacheEntry.name); cacheEntry.attributes.setMimeType(contentType); ranges = parseRange(request, response, cacheEntry.attributes); log("DefaultServlet.serveFile: contentType='" + contentType + "'"); response.setContentType(contentType); log("DefaultServlet.serveFile: contentLength=" + contentLength); if (contentLength < Integer.MAX_VALUE) { renderResult = render(getPathPrefix(request), cacheEntry);
/** * Check if the conditions specified in the optional If headers are * satisfied. * * @param request The servlet request we are processing * @param response The servlet response we are creating * @param resourceAttributes The resource information * @return boolean true if the resource meets all the specified conditions, * and false if any of the conditions is not satisfied, in which case * request processing is stopped */ protected boolean checkIfHeaders(HttpServletRequest request, HttpServletResponse response, ResourceAttributes resourceAttributes) throws IOException { return checkIfMatch(request, response, resourceAttributes) && checkIfModifiedSince(request, response, resourceAttributes) && checkIfNoneMatch(request, response, resourceAttributes) && checkIfUnmodifiedSince(request, response, resourceAttributes); }
/** * Get the readme file as a string. */ protected String getReadme(DirContext directory) throws IOException, ServletException { if (readmeFile != null) { try { Object obj = directory.lookup(readmeFile); if ((obj != null) && (obj instanceof Resource)) { StringWriter buffer = new StringWriter(); InputStream is = ((Resource) obj).streamContent(); copyRange(new InputStreamReader(is), new PrintWriter(buffer)); return buffer.toString(); } } catch (NamingException e) { if (debug > 10) log("readme '" + readmeFile + "' not found", e); return null; } } return null; }
/** * Copy the contents of the specified input stream to the specified * output stream, and ensure that both streams are closed before returning * (even in the face of an exception). * * @param resource The source resource * @param is The input stream to read the source resource from * @param ostream The output stream to write to * * @exception IOException if an input/output error occurs */ protected void copy(WebResource resource, InputStream is, ServletOutputStream ostream) throws IOException { IOException exception = null; InputStream istream = new BufferedInputStream(is, input); // Copy the input stream to the output stream exception = copyRange(istream, ostream); // Clean up the input stream istream.close(); // Rethrow any exception that has occurred if (exception != null) throw exception; }