Loading src/main/java/it/inaf/ia2/transfer/controller/FileController.java 0 → 100644 +21 −0 Original line number Diff line number Diff line package it.inaf.ia2.transfer.controller; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; public abstract class FileController { @Autowired protected HttpServletRequest request; public String getPath() { String[] parts = request.getRequestURI().split("/"); return String.join("/", Arrays.stream(parts) .map(p -> URLDecoder.decode(p, StandardCharsets.UTF_8)) .collect(Collectors.toList())); } } src/main/java/it/inaf/ia2/transfer/controller/GetFileController.java +5 −6 Original line number Diff line number Diff line Loading @@ -10,7 +10,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.UncheckedIOException; import java.util.Optional; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; Loading @@ -23,7 +22,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class GetFileController { public class GetFileController extends FileController { private static final Logger LOG = LoggerFactory.getLogger(GetFileController.class); Loading @@ -33,16 +32,16 @@ public class GetFileController { @Autowired private GmsClient gmsClient; @Autowired private HttpServletRequest request; @Autowired private HttpServletResponse response; @GetMapping("/**") public ResponseEntity<?> getFile() { String path = request.getServletPath(); String path = getPath(); LOG.debug("getFile called for path {}", path); Optional<FileInfo> optFileInfo = fileDAO.getFileInfo(path); if (optFileInfo.isPresent()) { Loading src/main/java/it/inaf/ia2/transfer/controller/PutFileController.java +9 −7 Original line number Diff line number Diff line Loading @@ -11,7 +11,8 @@ import java.nio.file.Files; import java.util.ArrayList; import java.util.List; import java.util.Optional; import javax.servlet.http.HttpServletRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import static org.springframework.http.HttpStatus.NOT_FOUND; import org.springframework.http.ResponseEntity; Loading @@ -21,7 +22,9 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @RestController public class PutFileController { public class PutFileController extends FileController { private static final Logger LOG = LoggerFactory.getLogger(PutFileController.class); @Autowired private FileDAO fileDAO; Loading @@ -29,13 +32,12 @@ public class PutFileController { @Autowired private ListOfFilesDAO listOfFilesDAO; @Autowired private HttpServletRequest request; @PutMapping("/**") public ResponseEntity<?> putFile(@RequestParam("file") MultipartFile file) throws IOException { String path = request.getServletPath(); String path = getPath(); LOG.debug("putFile called for path {}", path); Optional<FileInfo> optFileInfo = fileDAO.getFileInfo(path); if (optFileInfo.isPresent()) { Loading src/main/resources/application.properties +2 −0 Original line number Diff line number Diff line Loading @@ -14,3 +14,5 @@ cors.allowed.origin=http://localhost:8080,http://localhost:8085 spring.servlet.multipart.max-file-size=10GB spring.servlet.multipart.max-request-size=10GB logging.level.it.inaf=TRACE Loading
src/main/java/it/inaf/ia2/transfer/controller/FileController.java 0 → 100644 +21 −0 Original line number Diff line number Diff line package it.inaf.ia2.transfer.controller; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; public abstract class FileController { @Autowired protected HttpServletRequest request; public String getPath() { String[] parts = request.getRequestURI().split("/"); return String.join("/", Arrays.stream(parts) .map(p -> URLDecoder.decode(p, StandardCharsets.UTF_8)) .collect(Collectors.toList())); } }
src/main/java/it/inaf/ia2/transfer/controller/GetFileController.java +5 −6 Original line number Diff line number Diff line Loading @@ -10,7 +10,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.UncheckedIOException; import java.util.Optional; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; Loading @@ -23,7 +22,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class GetFileController { public class GetFileController extends FileController { private static final Logger LOG = LoggerFactory.getLogger(GetFileController.class); Loading @@ -33,16 +32,16 @@ public class GetFileController { @Autowired private GmsClient gmsClient; @Autowired private HttpServletRequest request; @Autowired private HttpServletResponse response; @GetMapping("/**") public ResponseEntity<?> getFile() { String path = request.getServletPath(); String path = getPath(); LOG.debug("getFile called for path {}", path); Optional<FileInfo> optFileInfo = fileDAO.getFileInfo(path); if (optFileInfo.isPresent()) { Loading
src/main/java/it/inaf/ia2/transfer/controller/PutFileController.java +9 −7 Original line number Diff line number Diff line Loading @@ -11,7 +11,8 @@ import java.nio.file.Files; import java.util.ArrayList; import java.util.List; import java.util.Optional; import javax.servlet.http.HttpServletRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import static org.springframework.http.HttpStatus.NOT_FOUND; import org.springframework.http.ResponseEntity; Loading @@ -21,7 +22,9 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @RestController public class PutFileController { public class PutFileController extends FileController { private static final Logger LOG = LoggerFactory.getLogger(PutFileController.class); @Autowired private FileDAO fileDAO; Loading @@ -29,13 +32,12 @@ public class PutFileController { @Autowired private ListOfFilesDAO listOfFilesDAO; @Autowired private HttpServletRequest request; @PutMapping("/**") public ResponseEntity<?> putFile(@RequestParam("file") MultipartFile file) throws IOException { String path = request.getServletPath(); String path = getPath(); LOG.debug("putFile called for path {}", path); Optional<FileInfo> optFileInfo = fileDAO.getFileInfo(path); if (optFileInfo.isPresent()) { Loading
src/main/resources/application.properties +2 −0 Original line number Diff line number Diff line Loading @@ -14,3 +14,5 @@ cors.allowed.origin=http://localhost:8080,http://localhost:8085 spring.servlet.multipart.max-file-size=10GB spring.servlet.multipart.max-request-size=10GB logging.level.it.inaf=TRACE