FIX IndexOutOfBound in redirection / forwarding

When redirecting to the next step in the GitHub
import wizard an IndexOutOfBound exception was 
thrown when using relative URL in gerrit.config
for the wizard steps.

Example:
[github]
wizardFlow = repositories-next.gh => pullrequests.html

This was due to the inconsistence of requestURI 
vs. contextPath. Target URI needs always to be 
absolute and have contextPath as prefix of requestURI. 

Change-Id: Ib5ef32378f9b351bf568aaf615b67cf864904a32
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/VelocityControllerServlet.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/VelocityControllerServlet.java
index 1e311b3..ff121ae 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/VelocityControllerServlet.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/VelocityControllerServlet.java
@@ -121,8 +121,10 @@
 
   private void redirectToNextStep(HttpServletRequest req,
       HttpServletResponse resp) throws IOException, ServletException {
-    String sourcePath = req.getRequestURI();
-    String sourcePage = sourcePath.substring(sourcePath.lastIndexOf('/') + 1);
+    String sourceUri = req.getRequestURI();
+    int pathPos = sourceUri.lastIndexOf('/') + 1;
+    String sourcePage = sourceUri.substring(pathPos);
+    String sourcePath = sourceUri.substring(0, pathPos);
     int queryStringStart = sourcePage.indexOf('?');
     if (queryStringStart > 0) {
       sourcePage = sourcePage.substring(0, queryStringStart);
@@ -130,14 +132,18 @@
     NextPage nextPage = githubConfig.getNextPage(sourcePage);
     if (nextPage != null) {
       if (nextPage.redirect) {
-        resp.sendRedirect(nextPage.uri);
+        resp.sendRedirect(nextPageURL(sourcePath, nextPage));
       } else {
         RequestDispatcher requestDispatcher =
-            req.getRequestDispatcher(nextPage.uri);
+            req.getRequestDispatcher(nextPageURL(sourcePath, nextPage));
         req.setAttribute("destUrl", nextPage);
         requestDispatcher.forward(req, resp);
       }
     }
   }
 
+  private String nextPageURL(String sourcePath, NextPage nextPage) {
+    return nextPage.uri.startsWith("/") ? nextPage.uri
+        : sourcePath + nextPage.uri;
+  }
 }