Fix retrieval of path from URL

The XDocServlet needs the endcoded URL path, but it used
HttpServletRequest.getPathInfo() to retrieve it which returns the
decoded path. So far this worked because there was a bug in Guice [1]
that made HttpServletRequest.getPathInfo() return the encoded path.
Now this bug was fixed in Guice and Gerrit was updated to use the new
Guice version. Hence the XDocServlet started to fail and needs to be
adapted.

[1] https://github.com/google/guice/issues/745

Change-Id: Ia14908ed0970e9e5eda0569e345c14fb5f255709
Signed-off-by: Edwin Kempin <ekempin@google.com>
(cherry picked from commit 10c5263d7e50c50de91234252bca36df8e81ca81)
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocServlet.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocServlet.java
index bf0927b..d63502d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocServlet.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocServlet.java
@@ -24,6 +24,7 @@
 import com.google.common.hash.Hashing;
 import com.google.common.net.HttpHeaders;
 import com.google.gerrit.common.data.PatchScript.FileMode;
+import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.restapi.AuthException;
 import com.google.gerrit.extensions.restapi.IdString;
 import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
@@ -76,6 +77,7 @@
 
   public  static final String PATH_PREFIX = "/project/";
 
+  private final String pluginName;
   private final Provider<ReviewDb> db;
   private final ProjectControl.Factory projectControlFactory;
   private final ProjectCache projectCache;
@@ -88,6 +90,7 @@
 
   @Inject
   XDocServlet(
+      @PluginName String pluginName,
       Provider<ReviewDb> db,
       ProjectControl.Factory projectControlFactory,
       ProjectCache projectCache,
@@ -97,6 +100,7 @@
       FileTypeRegistry fileTypeRegistry,
       XDocProjectConfig.Factory cfgFactory,
       Formatters formatters) {
+    this.pluginName = pluginName;
     this.db = db;
     this.projectControlFactory = projectControlFactory;
     this.projectCache = projectCache;
@@ -114,7 +118,7 @@
     try {
       validateRequestMethod(req);
 
-      ResourceKey key = ResourceKey.fromPath(req.getPathInfo());
+      ResourceKey key = ResourceKey.fromPath(getEncodedPath(req));
       ProjectState state = getProject(key);
       XDocProjectConfig cfg = cfgFactory.create(state);
 
@@ -193,6 +197,15 @@
     }
   }
 
+  private String getEncodedPath(HttpServletRequest req) {
+    String path = req.getRequestURI();
+    String prefix = "/plugins/" + pluginName;
+    if (path.startsWith(prefix)) {
+      path = path.substring(prefix.length());
+    }
+    return path;
+  }
+
   private Resource getImageResource(Repository repo, DiffMode diffMode,
       ObjectId revId, ObjectId revIdB, String file) {
     ObjectId id = diffMode == DiffMode.NO_DIFF || diffMode == DiffMode.SIDEBYSIDE_A