[DEV] error path

This commit is contained in:
Edouard DUPIN 2022-06-01 00:15:21 +02:00
parent 9c8cdc2b50
commit 6ecaed9e5f
2 changed files with 86 additions and 86 deletions

View File

@ -1,10 +1,12 @@
package org.kar.oauth.api;
import java.io.File;
import java.util.List;
import javax.annotation.security.PermitAll;
import javax.ws.rs.*;
import javax.ws.rs.core.CacheControl;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
@ -19,9 +21,10 @@ public class Front {
return "";
}
private Response retrive(String fileName) throws Exception {
String filePathName = ConfigVariable.getFrontFolder() + File.separator + fileName;
String filePathName = ConfigVariable.getSsoFolder() + File.separator + fileName;
String extention = getExtension(filePathName);
String mineType = null;
if (!extention.isEmpty()) {
if (extention.equalsIgnoreCase("jpg") || extention.equalsIgnoreCase("jpeg")) {
mineType = "image/jpeg";
} else if (extention.equalsIgnoreCase("gif")) {
@ -48,6 +51,10 @@ public class Front {
type("text/plain").
build();
}
} else {
mineType = "text/html";
filePathName = "index.html";
}
// reads input image
File download = new File(filePathName);
if (!download.exists()) {
@ -71,31 +78,24 @@ public class Front {
@GET
@PermitAll()
//@Produces(MediaType.APPLICATION_OCTET_STREAM)
//@CacheMaxAge(time = 10, unit = TimeUnit.DAYS)
//@CacheMaxAge(time = 1, unit = TimeUnit.DAYS)
public Response retrive0() throws Exception {
return retrive("index.html");
}
@GET
@Path("{baseA}")
@Path("{any: .*}")
@PermitAll()
//@Produces(MediaType.APPLICATION_OCTET_STREAM)
//@CacheMaxAge(time = 10, unit = TimeUnit.DAYS)
public Response retrive1(@PathParam("baseA") String baseA) throws Exception {
return retrive(baseA);
public Response retrive1(@PathParam("any") List<PathSegment> segments) throws Exception {
String filename = "";
for (PathSegment elem: segments) {
if (!filename.isEmpty()) {
filename += File.separator;
}
@GET
@Path("assets/images/{baseB}")
@PermitAll()
public Response retrive2(@PathParam("baseB") String baseB) throws Exception {
return retrive("assets" + File.separator + "images" + File.separator + baseB);
filename += elem.getPath();
}
@GET
@Path("assets/js_3rd_party/{baseB}")
@PermitAll()
public Response retrive3(@PathParam("baseB") String baseB) throws Exception {
return retrive("assets" + File.separator + "js_3rd_party" + File.separator + baseB);
return retrive(filename);
}
}

View File

@ -1,11 +1,13 @@
package org.kar.oauth.api;
import java.io.File;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.annotation.security.PermitAll;
import javax.ws.rs.*;
import javax.ws.rs.core.CacheControl;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
@ -24,6 +26,7 @@ public class FrontSSO {
String filePathName = ConfigVariable.getSsoFolder() + File.separator + fileName;
String extention = getExtension(filePathName);
String mineType = null;
if (!extention.isEmpty()) {
if (extention.equalsIgnoreCase("jpg") || extention.equalsIgnoreCase("jpeg")) {
mineType = "image/jpeg";
} else if (extention.equalsIgnoreCase("gif")) {
@ -50,6 +53,10 @@ public class FrontSSO {
type("text/plain").
build();
}
} else {
mineType = "text/html";
filePathName = "index.html";
}
// reads input image
File download = new File(filePathName);
if (!download.exists()) {
@ -79,25 +86,18 @@ public class FrontSSO {
}
@GET
@Path("{baseA}")
@Path("{any: .*}")
@PermitAll()
//@Produces(MediaType.APPLICATION_OCTET_STREAM)
//@CacheMaxAge(time = 10, unit = TimeUnit.DAYS)
public Response retrive1(@PathParam("baseA") String baseA) throws Exception {
return retrive(baseA);
public Response retrive1(@PathParam("any") List<PathSegment> segments) throws Exception {
String filename = "";
for (PathSegment elem: segments) {
if (!filename.isEmpty()) {
filename += File.separator;
}
@GET
@Path("assets/images/{baseB}")
@PermitAll()
public Response retrive2(@PathParam("baseB") String baseB) throws Exception {
return retrive("assets" + File.separator + "images" + File.separator + baseB);
filename += elem.getPath();
}
@GET
@Path("assets/js_3rd_party/{baseB}")
@PermitAll()
public Response retrive3(@PathParam("baseB") String baseB) throws Exception {
return retrive("assets" + File.separator + "js_3rd_party" + File.separator + baseB);
return retrive(filename);
}
}