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
No related branches found
No related tags found
No related merge requests found
...@@ -4,22 +4,14 @@ import jakarta.ws.rs.GET; ...@@ -4,22 +4,14 @@ import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path; import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam; import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; 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 * @author bba1792 Dr. Herbert Lange
* @version 20211004 * @version 20220405
* Class handling static files * Class handling static files
*/ */
@Path("/static/{staticFile}") @Path("/static/{staticFile}")
...@@ -35,26 +27,6 @@ public class Static { ...@@ -35,26 +27,6 @@ public class Static {
@GET @GET
public Response getStatic(@PathParam("staticFile") String fileName) { public Response getStatic(@PathParam("staticFile") String fileName) {
logger.info("Loading file " + 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 { try {
return Response.ok(this.getClass().getModule().getResourceAsStream("static/" + fileName).readAllBytes()).build(); 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