Michael Blow has submitted this change and it was merged. Change subject: Add sendError() to AbstractServlet ......................................................................
Add sendError() to AbstractServlet Change-Id: I24a1d5a6d06f37a9a02056b829541ce96a38b197 Reviewed-on: https://asterix-gerrit.ics.uci.edu/1827 Sonar-Qube: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> BAD: Jenkins <[email protected]> Integration-Tests: Jenkins <[email protected]> Reviewed-by: Till Westmann <[email protected]> --- M hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/AbstractServlet.java 1 file changed, 19 insertions(+), 3 deletions(-) Approvals: Till Westmann: Looks good to me, approved Jenkins: Verified; No violations found; No violations found; Verified diff --git a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/AbstractServlet.java b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/AbstractServlet.java index 1030686..3c41165 100644 --- a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/AbstractServlet.java +++ b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/AbstractServlet.java @@ -91,10 +91,25 @@ } } - protected void notAllowed(HttpMethod method, IServletResponse response) throws IOException { - response.setStatus(HttpResponseStatus.METHOD_NOT_ALLOWED); + protected void sendError(IServletResponse response, HttpResponseStatus status, String message) + throws IOException { + response.setStatus(status); HttpUtil.setContentType(response, HttpUtil.ContentType.TEXT_PLAIN, HttpUtil.Encoding.UTF8); - response.writer().write("Method " + method + " not allowed for the requested resource.\n"); + if (message != null) { + response.writer().println(message); + } + if (LOGGER.isLoggable(Level.INFO)) { + LOGGER.info("sendError: status=" + status + ", message=" + message); + } + } + + protected void sendError(IServletResponse response, HttpResponseStatus status) throws IOException { + sendError(response, status, null); + } + + protected void notAllowed(HttpMethod method, IServletResponse response) throws IOException { + sendError(response, HttpResponseStatus.METHOD_NOT_ALLOWED, + "Method " + method + " not allowed for the requested resource."); } @SuppressWarnings("squid:S1172") @@ -168,4 +183,5 @@ public String toString() { return this.getClass().getSimpleName() + Arrays.toString(paths); } + } -- To view, visit https://asterix-gerrit.ics.uci.edu/1827 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: merged Gerrit-Change-Id: I24a1d5a6d06f37a9a02056b829541ce96a38b197 Gerrit-PatchSet: 2 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Michael Blow <[email protected]> Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Michael Blow <[email protected]> Gerrit-Reviewer: Till Westmann <[email protected]>
