Compare commits

..

No commits in common. "1e05e8361a193d4a9188f9db03566c56f83d56f5" and "69e076e991c3de300727164443d7ab0073578cf5" have entirely different histories.

10 changed files with 49 additions and 50 deletions

View File

@ -14,7 +14,7 @@ public class ExceptionCatcher implements ExceptionMapper<Exception> {
public Response toResponse(final Exception exception) {
LOGGER.warn("Catch exception (not managed...):");
final RestErrorResponse ret = build(exception);
LOGGER.error("Error OID={}", ret.oid);
LOGGER.error("Error UUID={}", ret.uuid);
exception.printStackTrace();
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ret).type(MediaType.APPLICATION_JSON)
.build();

View File

@ -15,7 +15,7 @@ public class FailExceptionCatcher implements ExceptionMapper<FailException> {
public Response toResponse(final FailException exception) {
LOGGER.warn("Catch FailException: {}", exception.getLocalizedMessage());
final RestErrorResponse ret = build(exception);
LOGGER.error("Error OID={}", ret.oid);
LOGGER.error("Error UUID={}", ret.uuid);
if (exception.exception != null) {
exception.exception.printStackTrace();
}

View File

@ -15,7 +15,7 @@ public class InputExceptionCatcher implements ExceptionMapper<InputException> {
public Response toResponse(final InputException exception) {
LOGGER.warn("Catch InputException:");
final RestErrorResponse ret = build(exception);
LOGGER.error("Error OID={} ==> '{}'=>'{}'", ret.oid, exception.missingVariable,
LOGGER.error("Error UUID={} ==> '{}'=>'{}'", ret.uuid, exception.missingVariable,
exception.getLocalizedMessage());
// exception.printStackTrace();
return Response.status(exception.status).entity(ret).type(MediaType.APPLICATION_JSON).build();

View File

@ -16,7 +16,7 @@ public class JacksonExceptionCatcher implements ExceptionMapper<JacksonException
public Response toResponse(final JacksonException exception) {
LOGGER.warn("Catch exception Input data parsing:");
final RestErrorResponse ret = build(exception);
LOGGER.error("Error OID={}", ret.oid);
LOGGER.error("Error UUID={}", ret.uuid);
exception.printStackTrace();
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ret).type(MediaType.APPLICATION_JSON)
.build();

View File

@ -1,9 +1,10 @@
package org.kar.archidata.catcher;
import java.time.Instant;
import java.util.UUID;
import org.bson.types.ObjectId;
import org.kar.archidata.annotation.NoWriteSpecificMode;
import org.kar.archidata.tools.UuidUtils;
import jakarta.persistence.Column;
import jakarta.validation.constraints.NotNull;
@ -11,7 +12,7 @@ import jakarta.ws.rs.core.Response;
@NoWriteSpecificMode
public class RestErrorResponse {
public ObjectId oid = new ObjectId();
public UUID uuid = UuidUtils.nextUUID();
@NotNull
@Column(length = 0)
public String name; // Mandatory for TS generic error

View File

@ -15,7 +15,7 @@ public class SystemExceptionCatcher implements ExceptionMapper<SystemException>
public Response toResponse(final SystemException exception) {
LOGGER.warn("Catch SystemException:");
final RestErrorResponse ret = build(exception);
LOGGER.error("Error OID={}", ret.oid);
LOGGER.error("Error UUID={}", ret.uuid);
exception.printStackTrace();
return Response.status(exception.status).entity(ret).type(MediaType.APPLICATION_JSON).build();
}

View File

@ -14,7 +14,7 @@ public class WebApplicationExceptionCatcher implements ExceptionMapper<WebApplic
@Override
public Response toResponse(final WebApplicationException exception) {
final RestErrorResponse ret = build(exception);
LOGGER.error("Error OID={}", ret.oid);
LOGGER.error("Error UUID={}", ret.uuid);
return Response.status(exception.getResponse().getStatusInfo().toEnum()).entity(ret)
.type(MediaType.APPLICATION_JSON).build();
}

View File

@ -1,18 +1,17 @@
package org.kar.archidata.exception;
import org.bson.types.ObjectId;
import java.util.UUID;
public class RESTErrorResponseException extends Exception {
private static final long serialVersionUID = 1L;
public ObjectId oid;
public class RESTErrorResponseExeption extends Exception {
public UUID uuid;
public String time;
public String name;
public String message;
public int status;
public String statusMessage;
public RESTErrorResponseException() {
this.oid = new ObjectId();
public RESTErrorResponseExeption() {
this.uuid = null;
this.time = null;
this.name = null;
this.message = null;
@ -20,9 +19,9 @@ public class RESTErrorResponseException extends Exception {
this.statusMessage = null;
}
public RESTErrorResponseException(final ObjectId oid, final String time, final String name, final String message,
public RESTErrorResponseExeption(final UUID uuid, final String time, final String name, final String message,
final int status, final String statusMessage) {
this.oid = oid;
this.uuid = uuid;
this.time = time;
this.name = name;
this.message = message;
@ -32,7 +31,7 @@ public class RESTErrorResponseException extends Exception {
@Override
public String toString() {
return "RESTErrorResponseExeption [oid=" + this.oid + ", time=" + this.time + ", name=" + this.name
return "RESTErrorResponseExeption [uuid=" + this.uuid + ", time=" + this.time + ", name=" + this.name
+ ", message=" + this.message + ", status=" + this.status + ", statusMessage=" + this.statusMessage
+ "]";
}

View File

@ -208,7 +208,7 @@ public class AuthenticationFilter implements ContainerRequestFilter {
// The WWW-Authenticate header is sent along with the response
LOGGER.warn("abortWithUnauthorized:");
final RestErrorResponse ret = new RestErrorResponse(Response.Status.UNAUTHORIZED, "Unauthorized", message);
LOGGER.error("Error OID={}", ret.oid);
LOGGER.error("Error UUID={}", ret.uuid);
requestContext.abortWith(Response.status(ret.status)
.header(HttpHeaders.WWW_AUTHENTICATE,
AUTHENTICATION_SCHEME + " base64(HEADER).base64(CONTENT).base64(KEY)")
@ -217,7 +217,7 @@ public class AuthenticationFilter implements ContainerRequestFilter {
private void abortWithForbidden(final ContainerRequestContext requestContext, final String message) {
final RestErrorResponse ret = new RestErrorResponse(Response.Status.FORBIDDEN, "FORBIDDEN", message);
LOGGER.error("Error OID={}", ret.oid);
LOGGER.error("Error UUID={}", ret.uuid);
requestContext.abortWith(Response.status(ret.status).header(HttpHeaders.WWW_AUTHENTICATE, message).entity(ret)
.type(MediaType.APPLICATION_JSON).build());
}

View File

@ -11,7 +11,7 @@ import java.net.http.HttpResponse;
import java.util.List;
import java.util.Map;
import org.kar.archidata.exception.RESTErrorResponseException;
import org.kar.archidata.exception.RESTErrorResponseExeption;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -37,7 +37,7 @@ public class RESTApi {
}
public <T> List<T> gets(final Class<T> clazz, final String urlOffset)
throws RESTErrorResponseException, IOException, InterruptedException {
throws RESTErrorResponseExeption, 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<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
try {
final RESTErrorResponseException out = this.mapper.readValue(httpResponse.body(),
RESTErrorResponseException.class);
final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(),
RESTErrorResponseExeption.class);
throw out;
} catch (final MismatchedInputException ex) {
throw new IOException(
@ -62,57 +62,57 @@ public class RESTApi {
}
public <T> T get(final Class<T> clazz, final String urlOffset)
throws RESTErrorResponseException, IOException, InterruptedException {
throws RESTErrorResponseExeption, IOException, InterruptedException {
return modelSendJson("GET", clazz, urlOffset, null);
}
public <T, U> T post(final Class<T> clazz, final String urlOffset, final U data)
throws RESTErrorResponseException, IOException, InterruptedException {
throws RESTErrorResponseExeption, IOException, InterruptedException {
return modelSend("POST", clazz, urlOffset, data);
}
public <T, U> T postJson(final Class<T> clazz, final String urlOffset, final String body)
throws RESTErrorResponseException, IOException, InterruptedException {
throws RESTErrorResponseExeption, IOException, InterruptedException {
return modelSendJson("POST", clazz, urlOffset, body);
}
public <T> T postMap(final Class<T> clazz, final String urlOffset, final Map<String, Object> data)
throws RESTErrorResponseException, IOException, InterruptedException {
throws RESTErrorResponseExeption, IOException, InterruptedException {
return modelSendMap("POST", clazz, urlOffset, data);
}
public <T, U> T put(final Class<T> clazz, final String urlOffset, final U data)
throws RESTErrorResponseException, IOException, InterruptedException {
throws RESTErrorResponseExeption, IOException, InterruptedException {
return modelSend("PUT", clazz, urlOffset, data);
}
public <T, U> T putJson(final Class<T> clazz, final String urlOffset, final String body)
throws RESTErrorResponseException, IOException, InterruptedException {
throws RESTErrorResponseExeption, IOException, InterruptedException {
return modelSendJson("PUT", clazz, urlOffset, body);
}
public <T> T putMap(final Class<T> clazz, final String urlOffset, final Map<String, Object> data)
throws RESTErrorResponseException, IOException, InterruptedException {
throws RESTErrorResponseExeption, IOException, InterruptedException {
return modelSendMap("PUT", clazz, urlOffset, data);
}
public <T, U> T patch(final Class<T> clazz, final String urlOffset, final U data)
throws RESTErrorResponseException, IOException, InterruptedException {
throws RESTErrorResponseExeption, IOException, InterruptedException {
return modelSend("PATCH", clazz, urlOffset, data);
}
public <T, U> T patchJson(final Class<T> clazz, final String urlOffset, final String body)
throws RESTErrorResponseException, IOException, InterruptedException {
throws RESTErrorResponseExeption, IOException, InterruptedException {
return modelSendJson("PATCH", clazz, urlOffset, body);
}
public <T> T patchMap(final Class<T> clazz, final String urlOffset, final Map<String, Object> data)
throws RESTErrorResponseException, IOException, InterruptedException {
throws RESTErrorResponseExeption, IOException, InterruptedException {
return modelSendMap("PATCH", clazz, urlOffset, data);
}
protected <T, U> T modelSend(final String model, final Class<T> clazz, final String urlOffset, final U data)
throws RESTErrorResponseException, IOException, InterruptedException {
throws RESTErrorResponseExeption, IOException, InterruptedException {
if (data == null) {
return modelSendJson(model, clazz, urlOffset, null);
} else {
@ -123,7 +123,7 @@ public class RESTApi {
@SuppressWarnings("unchecked")
public <T, U> T modelSendJson(final String model, final Class<T> clazz, final String urlOffset, String body)
throws RESTErrorResponseException, IOException, InterruptedException {
throws RESTErrorResponseExeption, IOException, InterruptedException {
final HttpClient client = HttpClient.newHttpClient();
// client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1)
@ -138,14 +138,13 @@ 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<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
LOGGER.trace("Receive Error: {}", httpResponse.body());
try {
final RESTErrorResponseException out = this.mapper.readValue(httpResponse.body(),
RESTErrorResponseException.class);
final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(),
RESTErrorResponseExeption.class);
throw out;
} catch (final MismatchedInputException ex) {
throw new IOException(
@ -172,7 +171,7 @@ public class RESTApi {
final String model,
final Class<T> clazz,
final String urlOffset,
final Map<String, Object> data) throws RESTErrorResponseException, IOException, InterruptedException {
final Map<String, Object> data) throws RESTErrorResponseExeption, IOException, InterruptedException {
final HttpClient client = HttpClient.newHttpClient();
String body = null;
Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1)
@ -190,8 +189,8 @@ public class RESTApi {
final HttpResponse<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
try {
final RESTErrorResponseException out = this.mapper.readValue(httpResponse.body(),
RESTErrorResponseException.class);
final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(),
RESTErrorResponseExeption.class);
throw out;
} catch (final MismatchedInputException ex) {
throw new IOException(
@ -211,7 +210,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 RESTErrorResponseException, IOException, InterruptedException {
public void delete(final String urlOffset) throws RESTErrorResponseExeption, IOException, InterruptedException {
delete(Void.class, urlOffset);
}
@ -223,7 +222,7 @@ public class RESTApi {
* @return The parsed object received.
*/
public <T> T delete(final Class<T> clazz, final String urlOffset)
throws RESTErrorResponseException, IOException, InterruptedException {
throws RESTErrorResponseExeption, IOException, InterruptedException {
return simpleRequest("DELETE", clazz, urlOffset);
}
@ -231,7 +230,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 RESTErrorResponseException, IOException, InterruptedException {
public void archive(final String urlOffset) throws RESTErrorResponseExeption, IOException, InterruptedException {
archive(Void.class, urlOffset);
}
@ -243,7 +242,7 @@ public class RESTApi {
* @return The parsed object received.
*/
public <T> T archive(final Class<T> clazz, final String urlOffset)
throws RESTErrorResponseException, IOException, InterruptedException {
throws RESTErrorResponseExeption, IOException, InterruptedException {
return simpleRequest("ARCHIVE", clazz, urlOffset);
}
@ -251,7 +250,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 RESTErrorResponseException, IOException, InterruptedException {
public void restore(final String urlOffset) throws RESTErrorResponseExeption, IOException, InterruptedException {
restore(Void.class, urlOffset);
}
@ -263,7 +262,7 @@ public class RESTApi {
* @return The parsed object received.
*/
public <T> T restore(final Class<T> clazz, final String urlOffset)
throws RESTErrorResponseException, IOException, InterruptedException {
throws RESTErrorResponseExeption, IOException, InterruptedException {
return simpleRequest("RESTORE", clazz, urlOffset);
}
@ -276,7 +275,7 @@ public class RESTApi {
* @return The parsed object received.
*/
public <T> T simpleRequest(final String model, final Class<T> clazz, final String urlOffset)
throws RESTErrorResponseException, IOException, InterruptedException {
throws RESTErrorResponseExeption, IOException, InterruptedException {
final HttpClient client = HttpClient.newHttpClient();
Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1)
.uri(URI.create(this.baseUrl + urlOffset));
@ -287,8 +286,8 @@ public class RESTApi {
final HttpResponse<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
try {
final RESTErrorResponseException out = this.mapper.readValue(httpResponse.body(),
RESTErrorResponseException.class);
final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(),
RESTErrorResponseExeption.class);
throw out;
} catch (final MismatchedInputException ex) {
throw new IOException(