[DEV] update UUID error in ObjectId to be simple
This commit is contained in:
parent
4adc097c6b
commit
1e05e8361a
@ -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 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();
|
||||
|
@ -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 UUID={}", ret.uuid);
|
||||
LOGGER.error("Error OID={}", ret.oid);
|
||||
if (exception.exception != null) {
|
||||
exception.exception.printStackTrace();
|
||||
}
|
||||
|
@ -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 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();
|
||||
|
@ -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 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();
|
||||
|
@ -1,10 +1,9 @@
|
||||
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;
|
||||
@ -12,7 +11,7 @@ import jakarta.ws.rs.core.Response;
|
||||
|
||||
@NoWriteSpecificMode
|
||||
public class RestErrorResponse {
|
||||
public UUID uuid = UuidUtils.nextUUID();
|
||||
public ObjectId oid = new ObjectId();
|
||||
@NotNull
|
||||
@Column(length = 0)
|
||||
public String name; // Mandatory for TS generic error
|
||||
|
@ -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 UUID={}", ret.uuid);
|
||||
LOGGER.error("Error OID={}", ret.oid);
|
||||
exception.printStackTrace();
|
||||
return Response.status(exception.status).entity(ret).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
|
@ -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 UUID={}", ret.uuid);
|
||||
LOGGER.error("Error OID={}", ret.oid);
|
||||
return Response.status(exception.getResponse().getStatusInfo().toEnum()).entity(ret)
|
||||
.type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
|
@ -1,17 +1,18 @@
|
||||
package org.kar.archidata.exception;
|
||||
|
||||
import java.util.UUID;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
public class RESTErrorResponseExeption extends Exception {
|
||||
public UUID uuid;
|
||||
public class RESTErrorResponseException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
||||
public ObjectId oid;
|
||||
public String time;
|
||||
public String name;
|
||||
public String message;
|
||||
public int status;
|
||||
public String statusMessage;
|
||||
|
||||
public RESTErrorResponseExeption() {
|
||||
this.uuid = null;
|
||||
public RESTErrorResponseException() {
|
||||
this.oid = new ObjectId();
|
||||
this.time = null;
|
||||
this.name = null;
|
||||
this.message = null;
|
||||
@ -19,9 +20,9 @@ public class RESTErrorResponseExeption extends Exception {
|
||||
this.statusMessage = null;
|
||||
}
|
||||
|
||||
public RESTErrorResponseExeption(final UUID uuid, final String time, final String name, final String message,
|
||||
public RESTErrorResponseException(final ObjectId oid, final String time, final String name, final String message,
|
||||
final int status, final String statusMessage) {
|
||||
this.uuid = uuid;
|
||||
this.oid = oid;
|
||||
this.time = time;
|
||||
this.name = name;
|
||||
this.message = message;
|
||||
@ -31,7 +32,7 @@ public class RESTErrorResponseExeption extends Exception {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RESTErrorResponseExeption [uuid=" + this.uuid + ", time=" + this.time + ", name=" + this.name
|
||||
return "RESTErrorResponseExeption [oid=" + this.oid + ", time=" + this.time + ", name=" + this.name
|
||||
+ ", message=" + this.message + ", status=" + this.status + ", statusMessage=" + this.statusMessage
|
||||
+ "]";
|
||||
}
|
||||
|
@ -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 UUID={}", ret.uuid);
|
||||
LOGGER.error("Error OID={}", ret.oid);
|
||||
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 UUID={}", ret.uuid);
|
||||
LOGGER.error("Error OID={}", ret.oid);
|
||||
requestContext.abortWith(Response.status(ret.status).header(HttpHeaders.WWW_AUTHENTICATE, message).entity(ret)
|
||||
.type(MediaType.APPLICATION_JSON).build());
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import java.net.http.HttpResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.kar.archidata.exception.RESTErrorResponseExeption;
|
||||
import org.kar.archidata.exception.RESTErrorResponseException;
|
||||
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 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<String> 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> T get(final Class<T> clazz, final String urlOffset)
|
||||
throws RESTErrorResponseExeption, IOException, InterruptedException {
|
||||
throws RESTErrorResponseException, IOException, InterruptedException {
|
||||
return modelSendJson("GET", clazz, urlOffset, null);
|
||||
}
|
||||
|
||||
public <T, U> T post(final Class<T> clazz, final String urlOffset, final U data)
|
||||
throws RESTErrorResponseExeption, IOException, InterruptedException {
|
||||
throws RESTErrorResponseException, IOException, InterruptedException {
|
||||
return modelSend("POST", clazz, urlOffset, data);
|
||||
}
|
||||
|
||||
public <T, U> T postJson(final Class<T> clazz, final String urlOffset, final String body)
|
||||
throws RESTErrorResponseExeption, IOException, InterruptedException {
|
||||
throws RESTErrorResponseException, 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 RESTErrorResponseExeption, IOException, InterruptedException {
|
||||
throws RESTErrorResponseException, IOException, InterruptedException {
|
||||
return modelSendMap("POST", clazz, urlOffset, data);
|
||||
}
|
||||
|
||||
public <T, U> T put(final Class<T> clazz, final String urlOffset, final U data)
|
||||
throws RESTErrorResponseExeption, IOException, InterruptedException {
|
||||
throws RESTErrorResponseException, IOException, InterruptedException {
|
||||
return modelSend("PUT", clazz, urlOffset, data);
|
||||
}
|
||||
|
||||
public <T, U> T putJson(final Class<T> clazz, final String urlOffset, final String body)
|
||||
throws RESTErrorResponseExeption, IOException, InterruptedException {
|
||||
throws RESTErrorResponseException, 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 RESTErrorResponseExeption, IOException, InterruptedException {
|
||||
throws RESTErrorResponseException, IOException, InterruptedException {
|
||||
return modelSendMap("PUT", clazz, urlOffset, data);
|
||||
}
|
||||
|
||||
public <T, U> T patch(final Class<T> clazz, final String urlOffset, final U data)
|
||||
throws RESTErrorResponseExeption, IOException, InterruptedException {
|
||||
throws RESTErrorResponseException, IOException, InterruptedException {
|
||||
return modelSend("PATCH", clazz, urlOffset, data);
|
||||
}
|
||||
|
||||
public <T, U> T patchJson(final Class<T> clazz, final String urlOffset, final String body)
|
||||
throws RESTErrorResponseExeption, IOException, InterruptedException {
|
||||
throws RESTErrorResponseException, 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 RESTErrorResponseExeption, IOException, InterruptedException {
|
||||
throws RESTErrorResponseException, 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 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, U> T modelSendJson(final String model, final Class<T> 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<String> 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<T> clazz,
|
||||
final String urlOffset,
|
||||
final Map<String, Object> data) throws RESTErrorResponseExeption, IOException, InterruptedException {
|
||||
final Map<String, Object> 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<String> 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> T delete(final Class<T> 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> T archive(final Class<T> 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> T restore(final Class<T> 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> T simpleRequest(final String model, final Class<T> 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<String> 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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user