From 1e05e8361a193d4a9188f9db03566c56f83d56f5 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 8 Jan 2025 19:54:08 +0100 Subject: [PATCH] [DEV] update UUID error in ObjectId to be simple --- .../archidata/catcher/ExceptionCatcher.java | 2 +- .../catcher/FailExceptionCatcher.java | 2 +- .../catcher/InputExceptionCatcher.java | 2 +- .../catcher/JacksonExceptionCatcher.java | 2 +- .../archidata/catcher/RestErrorResponse.java | 5 +- .../catcher/SystemExceptionCatcher.java | 2 +- .../WebApplicationExceptionCatcher.java | 2 +- .../exception/RESTErrorResponseException.java | 17 +++--- .../filter/AuthenticationFilter.java | 4 +- src/org/kar/archidata/tools/RESTApi.java | 61 ++++++++++--------- 10 files changed, 50 insertions(+), 49 deletions(-) diff --git a/src/org/kar/archidata/catcher/ExceptionCatcher.java b/src/org/kar/archidata/catcher/ExceptionCatcher.java index c732efa..91529ee 100644 --- a/src/org/kar/archidata/catcher/ExceptionCatcher.java +++ b/src/org/kar/archidata/catcher/ExceptionCatcher.java @@ -14,7 +14,7 @@ public class ExceptionCatcher implements ExceptionMapper { public Response toResponse(final Exception exception) { LOGGER.warn("Catch exception (not managed...):"); final RestErrorResponse ret = build(exception); - LOGGER.error("Error UUID={}", ret.uuid); + LOGGER.error("Error OID={}", ret.oid); exception.printStackTrace(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ret).type(MediaType.APPLICATION_JSON) .build(); diff --git a/src/org/kar/archidata/catcher/FailExceptionCatcher.java b/src/org/kar/archidata/catcher/FailExceptionCatcher.java index ceaa08e..8aba13c 100644 --- a/src/org/kar/archidata/catcher/FailExceptionCatcher.java +++ b/src/org/kar/archidata/catcher/FailExceptionCatcher.java @@ -15,7 +15,7 @@ public class FailExceptionCatcher implements ExceptionMapper { public Response toResponse(final FailException exception) { LOGGER.warn("Catch FailException: {}", exception.getLocalizedMessage()); final RestErrorResponse ret = build(exception); - LOGGER.error("Error UUID={}", ret.uuid); + LOGGER.error("Error OID={}", ret.oid); if (exception.exception != null) { exception.exception.printStackTrace(); } diff --git a/src/org/kar/archidata/catcher/InputExceptionCatcher.java b/src/org/kar/archidata/catcher/InputExceptionCatcher.java index 730bcc9..1f62204 100644 --- a/src/org/kar/archidata/catcher/InputExceptionCatcher.java +++ b/src/org/kar/archidata/catcher/InputExceptionCatcher.java @@ -15,7 +15,7 @@ public class InputExceptionCatcher implements ExceptionMapper { public Response toResponse(final InputException exception) { LOGGER.warn("Catch InputException:"); final RestErrorResponse ret = build(exception); - LOGGER.error("Error UUID={} ==> '{}'=>'{}'", ret.uuid, exception.missingVariable, + LOGGER.error("Error OID={} ==> '{}'=>'{}'", ret.oid, exception.missingVariable, exception.getLocalizedMessage()); // exception.printStackTrace(); return Response.status(exception.status).entity(ret).type(MediaType.APPLICATION_JSON).build(); diff --git a/src/org/kar/archidata/catcher/JacksonExceptionCatcher.java b/src/org/kar/archidata/catcher/JacksonExceptionCatcher.java index 21a5b40..2b46aff 100644 --- a/src/org/kar/archidata/catcher/JacksonExceptionCatcher.java +++ b/src/org/kar/archidata/catcher/JacksonExceptionCatcher.java @@ -16,7 +16,7 @@ public class JacksonExceptionCatcher implements ExceptionMapper public Response toResponse(final SystemException exception) { LOGGER.warn("Catch SystemException:"); final RestErrorResponse ret = build(exception); - LOGGER.error("Error UUID={}", ret.uuid); + LOGGER.error("Error OID={}", ret.oid); exception.printStackTrace(); return Response.status(exception.status).entity(ret).type(MediaType.APPLICATION_JSON).build(); } diff --git a/src/org/kar/archidata/catcher/WebApplicationExceptionCatcher.java b/src/org/kar/archidata/catcher/WebApplicationExceptionCatcher.java index d22efd4..7b052ca 100644 --- a/src/org/kar/archidata/catcher/WebApplicationExceptionCatcher.java +++ b/src/org/kar/archidata/catcher/WebApplicationExceptionCatcher.java @@ -14,7 +14,7 @@ public class WebApplicationExceptionCatcher implements ExceptionMapper List gets(final Class clazz, final String urlOffset) - throws RESTErrorResponseExeption, IOException, InterruptedException { + throws RESTErrorResponseException, IOException, InterruptedException { final HttpClient client = HttpClient.newHttpClient(); Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1) .uri(URI.create(this.baseUrl + urlOffset)); @@ -48,8 +48,8 @@ public class RESTApi { final HttpResponse httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString()); if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) { try { - final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(), - RESTErrorResponseExeption.class); + final RESTErrorResponseException out = this.mapper.readValue(httpResponse.body(), + RESTErrorResponseException.class); throw out; } catch (final MismatchedInputException ex) { throw new IOException( @@ -62,57 +62,57 @@ public class RESTApi { } public T get(final Class clazz, final String urlOffset) - throws RESTErrorResponseExeption, IOException, InterruptedException { + throws RESTErrorResponseException, IOException, InterruptedException { return modelSendJson("GET", clazz, urlOffset, null); } public T post(final Class clazz, final String urlOffset, final U data) - throws RESTErrorResponseExeption, IOException, InterruptedException { + throws RESTErrorResponseException, IOException, InterruptedException { return modelSend("POST", clazz, urlOffset, data); } public T postJson(final Class clazz, final String urlOffset, final String body) - throws RESTErrorResponseExeption, IOException, InterruptedException { + throws RESTErrorResponseException, IOException, InterruptedException { return modelSendJson("POST", clazz, urlOffset, body); } public T postMap(final Class clazz, final String urlOffset, final Map data) - throws RESTErrorResponseExeption, IOException, InterruptedException { + throws RESTErrorResponseException, IOException, InterruptedException { return modelSendMap("POST", clazz, urlOffset, data); } public T put(final Class clazz, final String urlOffset, final U data) - throws RESTErrorResponseExeption, IOException, InterruptedException { + throws RESTErrorResponseException, IOException, InterruptedException { return modelSend("PUT", clazz, urlOffset, data); } public T putJson(final Class clazz, final String urlOffset, final String body) - throws RESTErrorResponseExeption, IOException, InterruptedException { + throws RESTErrorResponseException, IOException, InterruptedException { return modelSendJson("PUT", clazz, urlOffset, body); } public T putMap(final Class clazz, final String urlOffset, final Map data) - throws RESTErrorResponseExeption, IOException, InterruptedException { + throws RESTErrorResponseException, IOException, InterruptedException { return modelSendMap("PUT", clazz, urlOffset, data); } public T patch(final Class clazz, final String urlOffset, final U data) - throws RESTErrorResponseExeption, IOException, InterruptedException { + throws RESTErrorResponseException, IOException, InterruptedException { return modelSend("PATCH", clazz, urlOffset, data); } public T patchJson(final Class clazz, final String urlOffset, final String body) - throws RESTErrorResponseExeption, IOException, InterruptedException { + throws RESTErrorResponseException, IOException, InterruptedException { return modelSendJson("PATCH", clazz, urlOffset, body); } public T patchMap(final Class clazz, final String urlOffset, final Map data) - throws RESTErrorResponseExeption, IOException, InterruptedException { + throws RESTErrorResponseException, IOException, InterruptedException { return modelSendMap("PATCH", clazz, urlOffset, data); } protected T modelSend(final String model, final Class clazz, final String urlOffset, final U data) - throws RESTErrorResponseExeption, IOException, InterruptedException { + throws RESTErrorResponseException, IOException, InterruptedException { if (data == null) { return modelSendJson(model, clazz, urlOffset, null); } else { @@ -123,7 +123,7 @@ public class RESTApi { @SuppressWarnings("unchecked") public T modelSendJson(final String model, final Class clazz, final String urlOffset, String body) - throws RESTErrorResponseExeption, IOException, InterruptedException { + throws RESTErrorResponseException, IOException, InterruptedException { final HttpClient client = HttpClient.newHttpClient(); // client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true); Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1) @@ -138,13 +138,14 @@ public class RESTApi { } else { requestBuilding = requestBuilding.header("Content-Type", "application/json"); } + LOGGER.trace("publish body: {}", body); final HttpRequest request = requestBuilding.method(model, BodyPublishers.ofString(body)).build(); final HttpResponse httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString()); if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) { LOGGER.trace("Receive Error: {}", httpResponse.body()); try { - final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(), - RESTErrorResponseExeption.class); + final RESTErrorResponseException out = this.mapper.readValue(httpResponse.body(), + RESTErrorResponseException.class); throw out; } catch (final MismatchedInputException ex) { throw new IOException( @@ -171,7 +172,7 @@ public class RESTApi { final String model, final Class clazz, final String urlOffset, - final Map data) throws RESTErrorResponseExeption, IOException, InterruptedException { + final Map data) throws RESTErrorResponseException, IOException, InterruptedException { final HttpClient client = HttpClient.newHttpClient(); String body = null; Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1) @@ -189,8 +190,8 @@ public class RESTApi { final HttpResponse httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString()); if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) { try { - final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(), - RESTErrorResponseExeption.class); + final RESTErrorResponseException out = this.mapper.readValue(httpResponse.body(), + RESTErrorResponseException.class); throw out; } catch (final MismatchedInputException ex) { throw new IOException( @@ -210,7 +211,7 @@ public class RESTApi { * Call a DELETE on a REST API * @param urlOffset Offset to call the API */ - public void delete(final String urlOffset) throws RESTErrorResponseExeption, IOException, InterruptedException { + public void delete(final String urlOffset) throws RESTErrorResponseException, IOException, InterruptedException { delete(Void.class, urlOffset); } @@ -222,7 +223,7 @@ public class RESTApi { * @return The parsed object received. */ public T delete(final Class clazz, final String urlOffset) - throws RESTErrorResponseExeption, IOException, InterruptedException { + throws RESTErrorResponseException, IOException, InterruptedException { return simpleRequest("DELETE", clazz, urlOffset); } @@ -230,7 +231,7 @@ public class RESTApi { * Call an ARCHIVE on a REST API * @param urlOffset Offset to call the API */ - public void archive(final String urlOffset) throws RESTErrorResponseExeption, IOException, InterruptedException { + public void archive(final String urlOffset) throws RESTErrorResponseException, IOException, InterruptedException { archive(Void.class, urlOffset); } @@ -242,7 +243,7 @@ public class RESTApi { * @return The parsed object received. */ public T archive(final Class clazz, final String urlOffset) - throws RESTErrorResponseExeption, IOException, InterruptedException { + throws RESTErrorResponseException, IOException, InterruptedException { return simpleRequest("ARCHIVE", clazz, urlOffset); } @@ -250,7 +251,7 @@ public class RESTApi { * Call an RESTORE on a REST API * @param urlOffset Offset to call the API */ - public void restore(final String urlOffset) throws RESTErrorResponseExeption, IOException, InterruptedException { + public void restore(final String urlOffset) throws RESTErrorResponseException, IOException, InterruptedException { restore(Void.class, urlOffset); } @@ -262,7 +263,7 @@ public class RESTApi { * @return The parsed object received. */ public T restore(final Class clazz, final String urlOffset) - throws RESTErrorResponseExeption, IOException, InterruptedException { + throws RESTErrorResponseException, IOException, InterruptedException { return simpleRequest("RESTORE", clazz, urlOffset); } @@ -275,7 +276,7 @@ public class RESTApi { * @return The parsed object received. */ public T simpleRequest(final String model, final Class clazz, final String urlOffset) - throws RESTErrorResponseExeption, IOException, InterruptedException { + throws RESTErrorResponseException, IOException, InterruptedException { final HttpClient client = HttpClient.newHttpClient(); Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1) .uri(URI.create(this.baseUrl + urlOffset)); @@ -286,8 +287,8 @@ public class RESTApi { final HttpResponse httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString()); if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) { try { - final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(), - RESTErrorResponseExeption.class); + final RESTErrorResponseException out = this.mapper.readValue(httpResponse.body(), + RESTErrorResponseException.class); throw out; } catch (final MismatchedInputException ex) { throw new IOException(