update some logs

This commit is contained in:
Edouard DUPIN 2023-05-27 19:02:38 +02:00
parent f510537964
commit 3a4217391a
5 changed files with 52 additions and 35 deletions

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>kangaroo-and-rabbit</groupId> <groupId>kangaroo-and-rabbit</groupId>
<artifactId>archidata</artifactId> <artifactId>archidata</artifactId>
<version>0.3.6</version> <version>0.3.7</version>
<properties> <properties>
<jersey.version>3.1.1</jersey.version> <jersey.version>3.1.1</jersey.version>
<jaxb.version>2.3.1</jaxb.version> <jaxb.version>2.3.1</jaxb.version>

View File

@ -8,6 +8,8 @@ import org.kar.archidata.SqlWrapper;
import org.kar.archidata.annotation.security.PermitTokenInURI; import org.kar.archidata.annotation.security.PermitTokenInURI;
import org.kar.archidata.annotation.security.RolesAllowed; import org.kar.archidata.annotation.security.RolesAllowed;
import org.kar.archidata.util.ConfigBaseVariable; import org.kar.archidata.util.ConfigBaseVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.ws.rs.Consumes; import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET; import jakarta.ws.rs.GET;
@ -44,6 +46,7 @@ import java.util.Date;
@Path("/data") @Path("/data")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public class DataResource { public class DataResource {
static final Logger logger = LoggerFactory.getLogger(MediaType.class);
private final static int CHUNK_SIZE = 1024 * 1024; // 1MB chunks private final static int CHUNK_SIZE = 1024 * 1024; // 1MB chunks
private final static int CHUNK_SIZE_IN = 50 * 1024 * 1024; // 1MB chunks private final static int CHUNK_SIZE_IN = 50 * 1024 * 1024; // 1MB chunks
/** /**
@ -83,7 +86,7 @@ public class DataResource {
} }
public static Data getWithSha512(String sha512) { public static Data getWithSha512(String sha512) {
System.out.println("find sha512 = " + sha512); logger.info("find sha512 = {}", sha512);
try { try {
return SqlWrapper.getWhere(Data.class, "sha512", "=", sha512); return SqlWrapper.getWhere(Data.class, "sha512", "=", sha512);
} catch (Exception e) { } catch (Exception e) {
@ -94,7 +97,7 @@ public class DataResource {
} }
public static Data getWithId(long id) { public static Data getWithId(long id) {
System.out.println("find id = " + id); logger.info("find id = {}", id);
try { try {
return SqlWrapper.get(Data.class, id); return SqlWrapper.get(Data.class, id);
} catch (Exception e) { } catch (Exception e) {
@ -145,10 +148,10 @@ public class DataResource {
return null; return null;
} }
String mediaPath = getFileData(injectedData.id); String mediaPath = getFileData(injectedData.id);
System.out.println("src = " + tmpPath); logger.info("src = {}", tmpPath);
System.out.println("dst = " + mediaPath); logger.info("dst = {}", mediaPath);
Files.move(Paths.get(tmpPath), Paths.get(mediaPath), StandardCopyOption.ATOMIC_MOVE); Files.move(Paths.get(tmpPath), Paths.get(mediaPath), StandardCopyOption.ATOMIC_MOVE);
System.out.println("Move done"); logger.info("Move done");
return injectedData; return injectedData;
} }
@ -162,7 +165,7 @@ public class DataResource {
try { try {
Files.delete(Paths.get(filepath)); Files.delete(Paths.get(filepath));
} catch (IOException e) { } catch (IOException e) {
System.out.println("can not delete temporary file : " + Paths.get(filepath)); logger.info("can not delete temporary file : {}", Paths.get(filepath));
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -180,11 +183,11 @@ public class DataResource {
outpuStream = new FileOutputStream(new File(serverLocation)); outpuStream = new FileOutputStream(new File(serverLocation));
while ((read = uploadedInputStream.read(bytes)) != -1) { while ((read = uploadedInputStream.read(bytes)) != -1) {
//System.out.println("write " + read); //logger.info("write {}", read);
md.update(bytes, 0, read); md.update(bytes, 0, read);
outpuStream.write(bytes, 0, read); outpuStream.write(bytes, 0, read);
} }
System.out.println("Flush input stream ... " + serverLocation); logger.info("Flush input stream ... {}", serverLocation);
System.out.flush(); System.out.flush();
outpuStream.flush(); outpuStream.flush();
outpuStream.close(); outpuStream.close();
@ -194,10 +197,10 @@ public class DataResource {
out = bytesToHex(sha512Digest); out = bytesToHex(sha512Digest);
uploadedInputStream.close(); uploadedInputStream.close();
} catch (IOException ex) { } catch (IOException ex) {
System.out.println("Can not write in temporary file ... "); logger.info("Can not write in temporary file ... ");
ex.printStackTrace(); ex.printStackTrace();
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
System.out.println("Can not find sha512 algorithms"); logger.info("Can not find sha512 algorithms");
ex.printStackTrace(); ex.printStackTrace();
} }
return out; return out;
@ -228,11 +231,11 @@ public class DataResource {
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
public Response uploadFile(@Context SecurityContext sc, @FormDataParam("file") InputStream fileInputStream, @FormDataParam("file") FormDataContentDisposition fileMetaData) { public Response uploadFile(@Context SecurityContext sc, @FormDataParam("file") InputStream fileInputStream, @FormDataParam("file") FormDataContentDisposition fileMetaData) {
GenericContext gc = (GenericContext) sc.getUserPrincipal(); GenericContext gc = (GenericContext) sc.getUserPrincipal();
System.out.println("==================================================="); logger.info("===================================================");
System.out.println("== DATA uploadFile " + (gc==null?"null":gc.userByToken)); logger.info("== DATA uploadFile {}", (gc==null?"null":gc.userByToken));
System.out.println("==================================================="); logger.info("===================================================");
//public NodeSmall uploadFile(final FormDataMultiPart form) { //public NodeSmall uploadFile(final FormDataMultiPart form) {
System.out.println("Upload file: "); logger.info("Upload file: ");
String filePath = ConfigBaseVariable.getTmpDataFolder() + File.separator + tmpFolderId++; String filePath = ConfigBaseVariable.getTmpDataFolder() + File.separator + tmpFolderId++;
try { try {
createFolder(ConfigBaseVariable.getTmpDataFolder() + File.separator); createFolder(ConfigBaseVariable.getTmpDataFolder() + File.separator);
@ -251,9 +254,9 @@ public class DataResource {
@Produces(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response retriveDataId(@Context SecurityContext sc, @QueryParam(HttpHeaders.AUTHORIZATION) String token, @HeaderParam("Range") String range, @PathParam("id") Long id) throws Exception { public Response retriveDataId(@Context SecurityContext sc, @QueryParam(HttpHeaders.AUTHORIZATION) String token, @HeaderParam("Range") String range, @PathParam("id") Long id) throws Exception {
GenericContext gc = (GenericContext) sc.getUserPrincipal(); GenericContext gc = (GenericContext) sc.getUserPrincipal();
//System.out.println("==================================================="); //logger.info("===================================================");
System.out.println("== DATA retriveDataId ? id=" + id + " user=" + (gc==null?"null":gc.userByToken)); logger.info("== DATA retriveDataId ? id={} user={}", id, (gc==null?"null":gc.userByToken));
//System.out.println("==================================================="); //logger.info("===================================================");
Data value = getSmall(id); Data value = getSmall(id);
if (value == null) { if (value == null) {
Response.status(404). Response.status(404).
@ -275,9 +278,9 @@ public class DataResource {
@HeaderParam("Range") String range, @HeaderParam("Range") String range,
@PathParam("id") Long id) throws Exception { @PathParam("id") Long id) throws Exception {
//GenericContext gc = (GenericContext) sc.getUserPrincipal(); //GenericContext gc = (GenericContext) sc.getUserPrincipal();
//System.out.println("==================================================="); //logger.info("===================================================");
//System.out.println("== DATA retriveDataThumbnailId ? " + (gc==null?"null":gc.user)); //logger.info("== DATA retriveDataThumbnailId ? {}", (gc==null?"null":gc.user));
//System.out.println("==================================================="); //logger.info("===================================================");
Data value = getSmall(id); Data value = getSmall(id);
if (value == null) { if (value == null) {
return Response.status(404). return Response.status(404).
@ -343,9 +346,9 @@ public class DataResource {
@Produces(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response retriveDataFull(@Context SecurityContext sc, @QueryParam(HttpHeaders.AUTHORIZATION) String token, @HeaderParam("Range") String range, @PathParam("id") Long id, @PathParam("name") String name) throws Exception { public Response retriveDataFull(@Context SecurityContext sc, @QueryParam(HttpHeaders.AUTHORIZATION) String token, @HeaderParam("Range") String range, @PathParam("id") Long id, @PathParam("name") String name) throws Exception {
GenericContext gc = (GenericContext) sc.getUserPrincipal(); GenericContext gc = (GenericContext) sc.getUserPrincipal();
//System.out.println("==================================================="); //logger.info("===================================================");
System.out.println("== DATA retriveDataFull ? id=" + id + " user=" + (gc==null?"null":gc.userByToken)); logger.info("== DATA retriveDataFull ? id={} user={}", id, (gc==null?"null":gc.userByToken));
//System.out.println("==================================================="); //logger.info("===================================================");
Data value = getSmall(id); Data value = getSmall(id);
if (value == null) { if (value == null) {
Response.status(404). Response.status(404).
@ -365,7 +368,7 @@ public class DataResource {
*/ */
private Response buildStream(final String filename, final String range, String mimeType) throws Exception { private Response buildStream(final String filename, final String range, String mimeType) throws Exception {
File file = new File(filename); File file = new File(filename);
//System.out.println("request range : " + range); //logger.info("request range : {}", range);
// range not requested : Firefox does not send range headers // range not requested : Firefox does not send range headers
if (range == null) { if (range == null) {
final StreamingOutput output = new StreamingOutput() { final StreamingOutput output = new StreamingOutput() {
@ -378,9 +381,9 @@ public class DataResource {
try { try {
out.write(buf, 0, len); out.write(buf, 0, len);
out.flush(); out.flush();
//System.out.println("---- wrote " + len + " bytes file ----"); //logger.info("---- wrote {} bytes file ----", len);
} catch (IOException ex) { } catch (IOException ex) {
System.out.println("remote close connection"); logger.info("remote close connection");
break; break;
} }
} }
@ -401,7 +404,7 @@ public class DataResource {
String[] ranges = range.split("=")[1].split("-"); String[] ranges = range.split("=")[1].split("-");
final long from = Long.parseLong(ranges[0]); final long from = Long.parseLong(ranges[0]);
//System.out.println("request range : " + ranges.length); //logger.info("request range : {}", ranges.length);
//Chunk media if the range upper bound is unspecified. Chrome, Opera sends "bytes=0-" //Chunk media if the range upper bound is unspecified. Chrome, Opera sends "bytes=0-"
long to = CHUNK_SIZE + from; long to = CHUNK_SIZE + from;
if (ranges.length == 1) { if (ranges.length == 1) {
@ -412,7 +415,7 @@ public class DataResource {
} }
} }
final String responseRange = String.format("bytes %d-%d/%d", from, to, file.length()); final String responseRange = String.format("bytes %d-%d/%d", from, to, file.length());
//System.out.println("responseRange : " + responseRange); //logger.info("responseRange: {}", responseRange);
final RandomAccessFile raf = new RandomAccessFile(file, "r"); final RandomAccessFile raf = new RandomAccessFile(file, "r");
raf.seek(from); raf.seek(from);

View File

@ -10,9 +10,12 @@ import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.ResponseBuilder; import jakarta.ws.rs.core.Response.ResponseBuilder;
import org.kar.archidata.annotation.security.PermitAll; import org.kar.archidata.annotation.security.PermitAll;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FrontGeneric { public class FrontGeneric {
static final Logger logger = LoggerFactory.getLogger(FrontGeneric.class);
protected String baseFrontFolder = "/data/front"; protected String baseFrontFolder = "/data/front";
@ -26,7 +29,7 @@ public class FrontGeneric {
String filePathName = baseFrontFolder + File.separator + fileName; String filePathName = baseFrontFolder + File.separator + fileName;
String extention = getExtension(filePathName); String extention = getExtension(filePathName);
String mineType = null; String mineType = null;
System.out.println("try retrive : '" + filePathName + "' '" + extention + "'"); logger.debug("try retrive : '{}' '{}'", filePathName, extention);
if (extention.length() !=0 && extention.length() <= 5) { if (extention.length() !=0 && extention.length() <= 5) {
if (extention.equalsIgnoreCase("jpg") || extention.equalsIgnoreCase("jpeg")) { if (extention.equalsIgnoreCase("jpg") || extention.equalsIgnoreCase("jpeg")) {
mineType = "image/jpeg"; mineType = "image/jpeg";
@ -55,7 +58,7 @@ public class FrontGeneric {
mineType = "text/html"; mineType = "text/html";
filePathName = baseFrontFolder + File.separator + "index.html"; filePathName = baseFrontFolder + File.separator + "index.html";
} }
System.out.println(" ==> '" + filePathName + "'"); logger.debug(" ==> '[}'", filePathName);
// reads input image // reads input image
File download = new File(filePathName); File download = new File(filePathName);
if (!download.exists()) { if (!download.exists()) {

View File

@ -7,14 +7,18 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MediaStreamer implements StreamingOutput { public class MediaStreamer implements StreamingOutput {
static final Logger logger = LoggerFactory.getLogger(MediaStreamer.class);
private final int CHUNK_SIZE = 1024 * 1024; // 1MB chunks private final int CHUNK_SIZE = 1024 * 1024; // 1MB chunks
final byte[] buf = new byte[CHUNK_SIZE]; final byte[] buf = new byte[CHUNK_SIZE];
private long length; private long length;
private RandomAccessFile raf; private RandomAccessFile raf;
public MediaStreamer(long length, RandomAccessFile raf) throws IOException { public MediaStreamer(long length, RandomAccessFile raf) throws IOException {
//System.out.println("request stream of " + length / 1024 + " data"); //logger.info("request stream of {} data", length / 1024);
if (length<0) { if (length<0) {
throw new IOException("Wrong size of the file to stream: " + length); throw new IOException("Wrong size of the file to stream: " + length);
} }
@ -30,7 +34,7 @@ public class MediaStreamer implements StreamingOutput {
try { try {
outputStream.write(buf, 0, read); outputStream.write(buf, 0, read);
} catch (IOException ex) { } catch (IOException ex) {
System.out.println("remote close connection"); logger.info("remote close connection");
break; break;
} }
length -= read; length -= read;

View File

@ -147,13 +147,20 @@ public class JWTWrapper {
try { try {
// Create RSA-signer with the private key // Create RSA-signer with the private key
JWSSigner signer = new RSASSASigner(rsaJWK); JWSSigner signer = new RSASSASigner(rsaJWK);
logger.warn("timeOutInMunites= {}", timeOutInMunites);
Date now = new Date();
logger.warn("now = {}", now);
Date expiration = new Date(new Date().getTime() - 60 * timeOutInMunites * 1000 /* millisecond */);
logger.warn("expiration= {}", expiration);
JWTClaimsSet.Builder builder = new JWTClaimsSet.Builder() JWTClaimsSet.Builder builder = new JWTClaimsSet.Builder()
.subject(Long.toString(userID)) .subject(Long.toString(userID))
.claim("login", userLogin) .claim("login", userLogin)
.claim("application", application) .claim("application", application)
.issuer(isuer) .issuer(isuer)
.issueTime(new Date()) .issueTime(now)
.expirationTime(new Date(new Date().getTime() - 60 * timeOutInMunites * 1000 /* millisecond */)); // Do not ask why we need a "-" here ... this have no meaning .expirationTime(expiration); // Do not ask why we need a "-" here ... this have no meaning
// add right if needed: // add right if needed:
if (rights != null && !rights.isEmpty()) { if (rights != null && !rights.isEmpty()) {
builder.claim("right", rights); builder.claim("right", rights);