From 3f54c600f684ebd3b1ab0c87ff27cdc99eba40f7 Mon Sep 17 00:00:00 2001 From: Patrick Dowler Date: Thu, 19 Sep 2024 08:07:44 -0700 Subject: [PATCH] avail: fix handling of IllegalArgumentException from setState --- cadc-vosi/build.gradle | 2 +- .../java/ca/nrc/cadc/vosi/AvailabilityServlet.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cadc-vosi/build.gradle b/cadc-vosi/build.gradle index 6f8392e..aefef56 100644 --- a/cadc-vosi/build.gradle +++ b/cadc-vosi/build.gradle @@ -16,7 +16,7 @@ sourceCompatibility = 1.8 group = 'org.opencadc' -version = '1.4.7' +version = '1.4.8' description = 'OpenCADC VOSI server library' def git_url = 'https://github.com/opencadc/reg' diff --git a/cadc-vosi/src/main/java/ca/nrc/cadc/vosi/AvailabilityServlet.java b/cadc-vosi/src/main/java/ca/nrc/cadc/vosi/AvailabilityServlet.java index 93a5780..19b03e7 100644 --- a/cadc-vosi/src/main/java/ca/nrc/cadc/vosi/AvailabilityServlet.java +++ b/cadc-vosi/src/main/java/ca/nrc/cadc/vosi/AvailabilityServlet.java @@ -79,6 +79,7 @@ import ca.nrc.cadc.util.PropertiesReader; import ca.nrc.cadc.util.StringUtil; import java.io.IOException; +import java.io.PrintWriter; import java.lang.reflect.InvocationTargetException; import java.security.Principal; import java.util.HashSet; @@ -202,6 +203,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) String caller = im.toDisplayString(subject); if (authorized(subject)) { String state = request.getParameter("state"); + log.warn("state=" + state + " by " + caller); ap.setState(state); log.info("WebService state change by " + caller + " [OK]"); } else { @@ -211,6 +213,14 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) response.sendRedirect(request.getRequestURL().toString()); logInfo.setSuccess(true); + } catch (IllegalArgumentException ex) { + response.setStatus(400); + response.setHeader("content-type", "text/plain"); + PrintWriter w = response.getWriter(); + w.println(ex.getMessage()); + w.close(); + logInfo.setSuccess(true); + logInfo.setMessage(ex.toString()); } catch (Throwable t) { log.error("BUG", t); response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, t.getMessage());