GitHub wizard to 2.12-SNAPSHOT behaviour
Starting from 2.12-SNAPSHOT, the RequestDispatcher wrapped for a plugin
servlet has a different behaviour (possibly more consistent than before)
Before 2.12-SNAPSHOT required the full URL whilst now only the path
relative to the plugin servlet.
Change-Id: I3673a57008b65b75ccc1112d36a3028d31729015
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/velocity/VelocityViewServlet.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/velocity/VelocityViewServlet.java
index cd1a202..75e3c47 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/velocity/VelocityViewServlet.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/velocity/VelocityViewServlet.java
@@ -19,8 +19,6 @@
import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
-
-import com.googlesource.gerrit.plugins.github.GitHubConfig.NextPage;
import com.googlesource.gerrit.plugins.github.oauth.GitHubLogin;
import com.googlesource.gerrit.plugins.github.oauth.ScopedProvider;
@@ -47,7 +45,7 @@
public class VelocityViewServlet extends HttpServlet {
private static final Logger log = LoggerFactory
.getLogger(VelocityViewServlet.class);
- private static final String STATIC_PREFIX = "/static";
+ private static final String STATIC_PREFIX = "/static/";
private static final long serialVersionUID = 529071287765413268L;
private final RuntimeInstance velocityRuntime;
private final Provider<PluginVelocityModel> modelProvider;
@@ -73,16 +71,11 @@
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
- String servletPath = req.getPathInfo();
- NextPage nextPage = (NextPage) req.getAttribute("destUrl");
- String destUrl = null;
- if (nextPage != null && !nextPage.uri.startsWith("/")) {
- destUrl =
- servletPath.substring(0, servletPath.lastIndexOf("/")) + "/"
- + nextPage.uri;
- }
-
- String pathInfo = STATIC_PREFIX + MoreObjects.firstNonNull(destUrl, servletPath);
+ String pathInfo =
+ STATIC_PREFIX
+ + MoreObjects.firstNonNull(
+ (String) req.getAttribute("destUrl"),
+ req.getPathInfo());
try {
Template template = velocityRuntime.getTemplate(pathInfo, "UTF-8");
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 1d7b65e..561fbd0 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
@@ -122,7 +122,7 @@
private void redirectToNextStep(HttpServletRequest req,
HttpServletResponse resp) throws IOException, ServletException {
- String sourceUri = req.getRequestURI();
+ String sourceUri = req.getPathInfo();
int pathPos = sourceUri.lastIndexOf('/') + 1;
String sourcePage = sourceUri.substring(pathPos);
String sourcePath = sourceUri.substring(0, pathPos);
@@ -137,7 +137,7 @@
} else {
RequestDispatcher requestDispatcher =
req.getRequestDispatcher(nextPageURL(sourcePath, nextPage));
- req.setAttribute("destUrl", nextPage);
+ req.setAttribute("destUrl", nextPage.uri);
requestDispatcher.forward(req, resp);
}
}