Skip to content
Snippets Groups Projects
Commit a18b65b8 authored by Lange, Dr. Herbert's avatar Lange, Dr. Herbert
Browse files

cleanup static file handler

parent ba273481
Branches
No related tags found
No related merge requests found
......@@ -4,22 +4,14 @@ import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.core.Response;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
/**
* @author bba1792 Dr. Herbert Lange
* @version 20211004
* @version 20220405
* Class handling static files
*/
@Path("/static/{staticFile}")
......@@ -35,26 +27,6 @@ public class Static {
@GET
public Response getStatic(@PathParam("staticFile") String fileName) {
logger.info("Loading file " + fileName);
// // Get file from resource
// URL resource = this.getClass().getClassLoader().getResource("static/"+ fileName);
// if (resource == null) {
// logger.info("Resource is null");
// return Response.status(404,"Invalid static file").build();
// }
// else {
// try {
// logger.info("Resource is " + resource.toURI());
// File staticFile = new File(resource.toURI());
// return Response.ok(new FileInputStream(staticFile),Files.probeContentType(staticFile.toPath())).build();
// } catch (URISyntaxException | IOException e) {
// return Response.status(500, "Error loading file").build();
// }
// }
StringWriter result = new StringWriter();
VelocityContext context = new VelocityContext();
// Velocity.mergeTemplate("static/" + fileName, "UTF-8",context,result) ;
// return Response.ok(result.toString()).build() ;
//return Response.ok(Velocity.getTemplate("static/" + fileName).toString()).build();
try {
return Response.ok(this.getClass().getModule().getResourceAsStream("static/" + fileName).readAllBytes()).build();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment