From 9e3549e4100d1e012b84358d95b6adad16c61041 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 18 Oct 2024 16:56:04 +0200 Subject: [PATCH] fixed produces to MediaType.APPLICATION_JSON --- .../service/rest/GeoportalHealth.java | 5 +- .../geoportal/service/rest/GuardedMethod.java | 71 +++++++++---------- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GeoportalHealth.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GeoportalHealth.java index b95ff0e..d66013b 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GeoportalHealth.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GeoportalHealth.java @@ -43,7 +43,7 @@ public class GeoportalHealth { @GET @Path("/mongo") - @Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) public Response databaseCheck(@QueryParam("context") String context) throws JsonProcessingException { log.debug("databaseCheck called in the context {}", context); if (context == null) { @@ -62,7 +62,8 @@ public class GeoportalHealth { } 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); } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GuardedMethod.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GuardedMethod.java index 49bb9ce..bffc3ca 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GuardedMethod.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GuardedMethod.java @@ -19,18 +19,15 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public abstract class GuardedMethod { - private static List preoperations=new ArrayList<>(); + private static List preoperations = new ArrayList<>(); - public static void addPreoperation(Runnable preoperation){ + public static void addPreoperation(Runnable preoperation) { preoperations.add(preoperation); } + private T result = null; - - - private T result=null; - - public GuardedMethod execute() throws WebApplicationException{ + public GuardedMethod execute() throws WebApplicationException { try { if (!preoperations.isEmpty()) { log.trace("Running preops (size : {} )", preoperations.size()); @@ -40,41 +37,41 @@ public abstract class GuardedMethod { log.trace("Executing actual method.."); result = run(); return this; - }catch (InvalidUserRoleException e){ - log.error("Returning exception ",e); - throw new WebApplicationException("Invalid Step ID ", e,Status.FORBIDDEN); - }catch (UnrecognizedStepException e){ - log.error("Returning exception ",e); - throw new WebApplicationException("Invalid Step ID ", e,Status.BAD_REQUEST); - }catch (ConfigurationException e){ - log.error("Returning exception ",e); - throw new WebApplicationException("Environment is not properly configured", e,Status.EXPECTATION_FAILED); - }catch (InsufficientPrivileges e){ - log.error("Returning exception ",e); - throw new WebApplicationException("User has insufficient privileges for requested action", e,Status.FORBIDDEN); - }catch(WebApplicationException e) { + } catch (InvalidUserRoleException e) { + log.error("Returning exception ", e); + throw new WebApplicationException("Invalid Step ID ", e, Status.FORBIDDEN); + } catch (UnrecognizedStepException e) { + log.error("Returning exception ", e); + throw new WebApplicationException("Invalid Step ID ", e, Status.BAD_REQUEST); + } catch (ConfigurationException e) { + log.error("Returning exception ", e); + throw new WebApplicationException("Environment is not properly configured", e, Status.EXPECTATION_FAILED); + } catch (InsufficientPrivileges e) { + log.error("Returning exception ", e); + throw new WebApplicationException("User has insufficient privileges for requested action", e, + Status.FORBIDDEN); + } catch (WebApplicationException e) { log.error("Throwing Web Application Exception ", e); throw e; - }catch(ProjectNotFoundException e){ - log.error("Returning exception ",e); - throw new WebApplicationException("Project not found", e,Status.NOT_FOUND); - }catch(ProjectLockedException e){ - log.error("Returning exception ",e); - throw new WebApplicationException("Project is currently locked", e,Status.PRECONDITION_FAILED); - }catch(InvalidLockException e){ - log.error("Lock exception ",e); - throw new WebApplicationException("Conflicts found in locks", e,Status.CONFLICT); - }catch(Throwable t) { - log.error("Unexpected error ",t); - throw new WebApplicationException("Unexpected internal error", t,Status.INTERNAL_SERVER_ERROR); + } catch (ProjectNotFoundException e) { + log.error("Returning exception ", e); + throw new WebApplicationException("Project not found", e, Status.NOT_FOUND); + } catch (ProjectLockedException e) { + log.error("Returning exception ", e); + throw new WebApplicationException("Project is currently locked", e, Status.PRECONDITION_FAILED); + } catch (InvalidLockException e) { + log.error("Lock exception ", e); + throw new WebApplicationException("Conflicts found in locks", e, Status.CONFLICT); + } catch (Throwable t) { + log.error("Unexpected error ", t); + throw new WebApplicationException("Unexpected internal error", t, Status.INTERNAL_SERVER_ERROR); } - + } - + public T getResult() { return result; } - - - protected abstract T run() throws Exception,WebApplicationException; + + protected abstract T run() throws Exception, WebApplicationException; }