Merge branch 'stable-3.0' into stable-3.1

* stable-3.0:
  Http: fix generation of the custom readonly message
  Upgrade bazlets to latest stable-2.16 to build with 2.16.18 API
  Bump Bazel version to 3.1.0

Change-Id: Ie36732f7dab5a111b89b661eeed1f8bc94bdc46e
diff --git a/.bazelversion b/.bazelversion
index 4a36342..fd2a018 100644
--- a/.bazelversion
+++ b/.bazelversion
@@ -1 +1 @@
-3.0.0
+3.1.0
diff --git a/src/main/java/com/googlesource/gerrit/plugins/readonly/ReadOnly.java b/src/main/java/com/googlesource/gerrit/plugins/readonly/ReadOnly.java
index f0ffbbd..30f8904 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/readonly/ReadOnly.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/readonly/ReadOnly.java
@@ -71,7 +71,9 @@
         && request instanceof HttpServletRequest
         && response instanceof HttpServletResponse
         && shouldBlock((HttpServletRequest) request)) {
-      ((HttpServletResponse) response).sendError(SC_SERVICE_UNAVAILABLE, config.message());
+      HttpServletResponse httpResponse = (HttpServletResponse) response;
+      httpResponse.setStatus(SC_SERVICE_UNAVAILABLE);
+      httpResponse.getWriter().println(config.message());
       return;
     }
     chain.doFilter(request, response);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/readonly/AbstractReadOnlyTest.java b/src/test/java/com/googlesource/gerrit/plugins/readonly/AbstractReadOnlyTest.java
index ce8d081..b14bcce 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/readonly/AbstractReadOnlyTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/readonly/AbstractReadOnlyTest.java
@@ -123,16 +123,16 @@
   @UseLocalDisk
   @UseSsh
   public void pushBySshIsRejectedWhenReadOnly() throws Exception {
-    pushForReview(true);
+    pushForReview(true, "READ ONLY");
   }
 
   @Test
   @UseLocalDisk
   public void pushByHttpIsRejectedWhenReadOnly() throws Exception {
-    pushForReview(false);
+    pushForReview(false, "Service Unavailable");
   }
 
-  private void pushForReview(boolean ssh) throws Exception {
+  private void pushForReview(boolean ssh, String expectedMessage) throws Exception {
     String url = ssh ? adminSshSession.getUrl() : admin.getHttpUrl(server);
     if (!ssh) {
       CredentialsProvider.setDefault(
@@ -149,7 +149,7 @@
     // Push should fail
     TransportException thrown =
         assertThrows(TransportException.class, () -> pushTo("refs/for/master"));
-    assertThat(thrown).hasMessageThat().contains("READ ONLY");
+    assertThat(thrown).hasMessageThat().contains(expectedMessage);
 
     // Disable read-only
     setReadOnly(false);