Serve reindexing simulating a GET request for /meta ref caching

Since [1] the change notes /meta refs are cached for all the incoming GET/HEAD
REST APIs; however, the high-availability indexing API is a POST served by a regular
servlet and therefore won't have any caching, which is problematic because of the high
number of associated refs lookups generated.

Simulate an incoming GET request for allowing caching of the /meta refs lookups.

[1] https://gerrit-review.googlesource.com/c/gerrit/+/334539/17

Depends-On: https://gerrit-review.googlesource.com/c/gerrit/+/334539/17
Change-Id: Ife8b18b40bc4600709b0d06867f9c0d3a7512f7a
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/AbstractIndexRestApiServlet.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/AbstractIndexRestApiServlet.java
index 410aa23..5e25d88 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/AbstractIndexRestApiServlet.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/AbstractIndexRestApiServlet.java
@@ -23,6 +23,7 @@
 import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedIndexingHandler.Operation;
 import com.ericsson.gerrit.plugins.highavailability.forwarder.IndexEvent;
 import com.google.common.base.Charsets;
+import com.google.gerrit.server.cache.PerThreadCache;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import com.google.gwtorm.server.OrmException;
@@ -30,6 +31,7 @@
 import java.io.InputStreamReader;
 import java.util.Optional;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
 import javax.servlet.http.HttpServletResponse;
 
 public abstract class AbstractIndexRestApiServlet<T> extends AbstractRestApiServlet {
@@ -87,7 +89,26 @@
     setHeaders(rsp);
     String path = req.getRequestURI();
     T id = parse(path.substring(path.lastIndexOf('/') + 1));
-    try {
+
+    /**
+     * Since [1] the change notes /meta refs are cached for all the incoming GET/HEAD REST APIs;
+     * however, the high-availability indexing API is a POST served by a regular servlet and
+     * therefore won't have any caching, which is problematic because of the high number of
+     * associated refs lookups generated.
+     *
+     * <p>Simulate an incoming GET request for allowing caching of the /meta refs lookups.
+     *
+     * <p>[1] https://gerrit-review.googlesource.com/c/gerrit/+/334539/17
+     */
+    HttpServletRequestWrapper simulatedGetRequestForCaching =
+        new HttpServletRequestWrapper(req) {
+          @Override
+          public String getMethod() {
+            return "GET";
+          }
+        };
+
+    try (PerThreadCache unused = PerThreadCache.create(simulatedGetRequestForCaching)) {
       forwardedIndexingHandler.index(id, operation, parseBody(req));
       rsp.setStatus(SC_NO_CONTENT);
     } catch (IOException e) {