18 package org.turro.elephant.download;
20 import java.io.IOException;
21 import java.net.URISyntaxException;
22 import java.net.URLDecoder;
23 import java.nio.charset.StandardCharsets;
24 import javax.servlet.ServletException;
25 import javax.servlet.annotation.WebServlet;
26 import javax.servlet.http.HttpServlet;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29 import org.apache.hc.core5.http.HttpStatus;
30 import org.turro.collections.KeyValueMap;
31 import org.turro.elephant.context.Application;
32 import org.turro.elephant.context.ElephantApplication;
33 import org.turro.elephant.context.ElephantContext;
34 import org.turro.file.Document;
35 import org.turro.file.Folder;
36 import org.turro.http.Respond;
37 import org.turro.log.SystemLogger;
38 import org.turro.log.WebLoggers;
44 @WebServlet(name =
"Download", urlPatterns = {
"/down_/*"})
47 private void processDownload(
Application application, String path, KeyValueMap map)
throws IOException {
50 processResource(application, path, response);
51 }
catch (URISyntaxException ex) {
56 private void processResource(
Application application, String path, HttpServletResponse response)
throws IOException, URISyntaxException {
57 if(path.contains(
"/WEB-INF") && !application.
isInRole(
"download:app")) {
58 response.setStatus(HttpStatus.SC_FORBIDDEN);
63 Respond.to(response).flush(doc.document());
74 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
75 KeyValueMap map =
new KeyValueMap();
76 for(String key : request.getParameterMap().keySet()) {
77 map.put(key, URLDecoder.decode(request.getParameter(key), StandardCharsets.UTF_8));
83 protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
84 processRequest(request, response);
88 protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
89 processRequest(request, response);
94 return "Download servlet";
abstract HttpServletResponse getHttpServletResponse()
boolean isInRole(String role)
static String getRelativePath(String path)
static String getRealPath(String path)
static URI toUri(String localPath)
void processRequest(HttpServletRequest request, HttpServletResponse response)
void doGet(HttpServletRequest request, HttpServletResponse response)
void doPost(HttpServletRequest request, HttpServletResponse response)
static ILogWrapper info()
static WebLoggers severe(Object entity)
WebLoggers exception(Throwable throwable)
ILogWrapper comment(String comment)
ILogWrapper entityPath(String path)
ILogWrapper entityName(String name)