Deprecate /query
Long term the Gerrit project is going to move to a more REST-ful
API. Using /query to scan for changes doesn't make sense in that
world. It also has some issues with output formatting that doesn't
line up with what we want to process in the stock web UI, and does
not match the JSON or JSON_COMPACT formats used by the existing
REST APIs /projects/ and /accounts/self/capabilities.
Deprecate the /query API, leaving it on by default. Define a new
site configuration variable to allow the URL to be disabled if a
server admin wants to promote tools moving to the new API.
Leaving /query on by default is important right now as the new API
will be defined later, primarily because we may want the class name
ChangeQueryServlet for the new implementation.
Change-Id: I86af3f94f66948e6f45da71e9b8631a1c2d1d135
diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt
index 54f7752..e7cc9e4 100644
--- a/Documentation/config-gerrit.txt
+++ b/Documentation/config-gerrit.txt
@@ -1898,6 +1898,12 @@
updated versions. If false, a server restart is required to change
any of these resources. Default is true, allowing automatic reloads.
+[[site.enableDeprecatedQuery]]site.enableDeprecatedQuery::
++
+If true the deprecated `/query` URL is available to return JSON
+and text results for changes. If false, the URL is disabled and
+returns 404 to clients. Default is true, enabling `/query`.
+
[[sshd]] Section sshd
~~~~~~~~~~~~~~~~~~~~~
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/UrlModule.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/UrlModule.java
index c299a71..5c1eca2 100644
--- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/UrlModule.java
+++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/UrlModule.java
@@ -24,15 +24,20 @@
import com.google.gerrit.httpd.raw.StaticServlet;
import com.google.gerrit.httpd.raw.ToolServlet;
import com.google.gerrit.httpd.rpc.account.AccountCapabilitiesServlet;
+import com.google.gerrit.httpd.rpc.change.DeprecatedChangeQueryServlet;
import com.google.gerrit.httpd.rpc.project.ListProjectsServlet;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gwtexpui.server.CacheControlFilter;
+import com.google.inject.Inject;
import com.google.inject.Key;
import com.google.inject.Provider;
import com.google.inject.internal.UniqueAnnotations;
import com.google.inject.servlet.ServletModule;
+import org.eclipse.jgit.lib.Config;
+
import java.io.IOException;
import javax.servlet.http.HttpServlet;
@@ -40,6 +45,21 @@
import javax.servlet.http.HttpServletResponse;
class UrlModule extends ServletModule {
+ static class UrlConfig {
+ private final boolean deprecatedQuery;
+
+ @Inject
+ UrlConfig(@GerritServerConfig Config cfg) {
+ deprecatedQuery = cfg.getBoolean("site", "enableDeprecatedQuery", true);
+ }
+ }
+
+ private final UrlConfig cfg;
+
+ UrlModule(UrlConfig cfg) {
+ this.cfg = cfg;
+ }
+
@Override
protected void configureServlets() {
filter("/*").through(Key.get(CacheControlFilter.class));
@@ -50,7 +70,6 @@
serve("/Gerrit/*").with(legacyGerritScreen());
serve("/cat/*").with(CatServlet.class);
serve("/logout").with(HttpLogoutServlet.class);
- serve("/query").with(ChangeQueryServlet.class);
serve("/signout").with(HttpLogoutServlet.class);
serve("/ssh_info").with(SshInfoServlet.class);
serve("/static/*").with(StaticServlet.class);
@@ -75,6 +94,10 @@
filter("/a/*").through(RequireIdentifiedUserFilter.class);
serveRegex("^/(?:a/)?accounts/self/capabilities$").with(AccountCapabilitiesServlet.class);
serveRegex("^/(?:a/)?projects/(.*)?$").with(ListProjectsServlet.class);
+
+ if (cfg.deprecatedQuery) {
+ serve("/query").with(DeprecatedChangeQueryServlet.class);
+ }
}
private Key<HttpServlet> notFound() {
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/WebModule.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/WebModule.java
index 53dee84..0f223c9 100644
--- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/WebModule.java
+++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/WebModule.java
@@ -52,14 +52,17 @@
public class WebModule extends FactoryModule {
private final AuthConfig authConfig;
+ private final UrlModule.UrlConfig urlConfig;
private final boolean wantSSL;
private final GitWebConfig gitWebConfig;
@Inject
WebModule(final AuthConfig authConfig,
+ final UrlModule.UrlConfig urlConfig,
@CanonicalWebUrl @Nullable final String canonicalUrl,
final Injector creatingInjector) {
this.authConfig = authConfig;
+ this.urlConfig = urlConfig;
this.wantSSL = canonicalUrl != null && canonicalUrl.startsWith("https:");
this.gitWebConfig =
@@ -117,7 +120,7 @@
throw new ProvisionException("Unsupported loginType: " + authConfig.getAuthType());
}
- install(new UrlModule());
+ install(new UrlModule(urlConfig));
install(new UiRpcModule());
install(new GerritRequestModule());
install(new GitOverHttpServlet.Module());
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/ChangeQueryServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/change/DeprecatedChangeQueryServlet.java
similarity index 94%
rename from gerrit-httpd/src/main/java/com/google/gerrit/httpd/ChangeQueryServlet.java
rename to gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/change/DeprecatedChangeQueryServlet.java
index 9c4c598..cf443e7 100644
--- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/ChangeQueryServlet.java
+++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/change/DeprecatedChangeQueryServlet.java
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package com.google.gerrit.httpd;
+package com.google.gerrit.httpd.rpc.change;
import com.google.gerrit.server.query.change.QueryProcessor;
import com.google.gerrit.server.query.change.QueryProcessor.OutputFormat;
@@ -29,12 +29,12 @@
import javax.servlet.http.HttpServletResponse;
@Singleton
-public class ChangeQueryServlet extends HttpServlet {
+public class DeprecatedChangeQueryServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private final Provider<QueryProcessor> processor;
@Inject
- ChangeQueryServlet(Provider<QueryProcessor> processor) {
+ DeprecatedChangeQueryServlet(Provider<QueryProcessor> processor) {
this.processor = processor;
}