fixed produces to MediaType.APPLICATION_JSON

This commit is contained in:
Francesco Mangiacrapa 2024-10-18 16:56:04 +02:00
parent 8cea8b9aea
commit 9e3549e410
2 changed files with 37 additions and 39 deletions

View File

@ -43,7 +43,7 @@ public class GeoportalHealth {
@GET @GET
@Path("/mongo") @Path("/mongo")
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public Response databaseCheck(@QueryParam("context") String context) throws JsonProcessingException { public Response databaseCheck(@QueryParam("context") String context) throws JsonProcessingException {
log.debug("databaseCheck called in the context {}", context); log.debug("databaseCheck called in the context {}", context);
if (context == null) { if (context == null) {
@ -62,7 +62,8 @@ public class GeoportalHealth {
} }
private String healthCheckSerializer(HealthCheckResponse response) throws JsonProcessingException { private String healthCheckSerializer(HealthCheckResponse response) throws JsonProcessingException {
// Serializes HealthCheckResponse in JSON with custom HealthCheckResponseSerializer // Serializes HealthCheckResponse in JSON with custom
// HealthCheckResponseSerializer
return mapper.writeValueAsString(response); return mapper.writeValueAsString(response);
} }

View File

@ -19,18 +19,15 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public abstract class GuardedMethod<T> { public abstract class GuardedMethod<T> {
private static List<Runnable> preoperations=new ArrayList<>(); private static List<Runnable> preoperations = new ArrayList<>();
public static void addPreoperation(Runnable preoperation){ public static void addPreoperation(Runnable preoperation) {
preoperations.add(preoperation); preoperations.add(preoperation);
} }
private T result = null;
public GuardedMethod<T> execute() throws WebApplicationException {
private T result=null;
public GuardedMethod<T> execute() throws WebApplicationException{
try { try {
if (!preoperations.isEmpty()) { if (!preoperations.isEmpty()) {
log.trace("Running preops (size : {} )", preoperations.size()); log.trace("Running preops (size : {} )", preoperations.size());
@ -40,33 +37,34 @@ public abstract class GuardedMethod<T> {
log.trace("Executing actual method.."); log.trace("Executing actual method..");
result = run(); result = run();
return this; return this;
}catch (InvalidUserRoleException e){ } catch (InvalidUserRoleException e) {
log.error("Returning exception ",e); log.error("Returning exception ", e);
throw new WebApplicationException("Invalid Step ID ", e,Status.FORBIDDEN); throw new WebApplicationException("Invalid Step ID ", e, Status.FORBIDDEN);
}catch (UnrecognizedStepException e){ } catch (UnrecognizedStepException e) {
log.error("Returning exception ",e); log.error("Returning exception ", e);
throw new WebApplicationException("Invalid Step ID ", e,Status.BAD_REQUEST); throw new WebApplicationException("Invalid Step ID ", e, Status.BAD_REQUEST);
}catch (ConfigurationException e){ } catch (ConfigurationException e) {
log.error("Returning exception ",e); log.error("Returning exception ", e);
throw new WebApplicationException("Environment is not properly configured", e,Status.EXPECTATION_FAILED); throw new WebApplicationException("Environment is not properly configured", e, Status.EXPECTATION_FAILED);
}catch (InsufficientPrivileges e){ } catch (InsufficientPrivileges e) {
log.error("Returning exception ",e); log.error("Returning exception ", e);
throw new WebApplicationException("User has insufficient privileges for requested action", e,Status.FORBIDDEN); throw new WebApplicationException("User has insufficient privileges for requested action", e,
}catch(WebApplicationException e) { Status.FORBIDDEN);
} catch (WebApplicationException e) {
log.error("Throwing Web Application Exception ", e); log.error("Throwing Web Application Exception ", e);
throw e; throw e;
}catch(ProjectNotFoundException e){ } catch (ProjectNotFoundException e) {
log.error("Returning exception ",e); log.error("Returning exception ", e);
throw new WebApplicationException("Project not found", e,Status.NOT_FOUND); throw new WebApplicationException("Project not found", e, Status.NOT_FOUND);
}catch(ProjectLockedException e){ } catch (ProjectLockedException e) {
log.error("Returning exception ",e); log.error("Returning exception ", e);
throw new WebApplicationException("Project is currently locked", e,Status.PRECONDITION_FAILED); throw new WebApplicationException("Project is currently locked", e, Status.PRECONDITION_FAILED);
}catch(InvalidLockException e){ } catch (InvalidLockException e) {
log.error("Lock exception ",e); log.error("Lock exception ", e);
throw new WebApplicationException("Conflicts found in locks", e,Status.CONFLICT); throw new WebApplicationException("Conflicts found in locks", e, Status.CONFLICT);
}catch(Throwable t) { } catch (Throwable t) {
log.error("Unexpected error ",t); log.error("Unexpected error ", t);
throw new WebApplicationException("Unexpected internal error", t,Status.INTERNAL_SERVER_ERROR); throw new WebApplicationException("Unexpected internal error", t, Status.INTERNAL_SERVER_ERROR);
} }
} }
@ -75,6 +73,5 @@ public abstract class GuardedMethod<T> {
return result; return result;
} }
protected abstract T run() throws Exception, WebApplicationException;
protected abstract T run() throws Exception,WebApplicationException;
} }