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
This commit is contained in:
Shawn O. Pearce
2012-04-05 14:39:22 -07:00
parent 8ed6c1532a
commit 6bd04fd28b
4 changed files with 37 additions and 5 deletions

View File

@@ -1898,6 +1898,12 @@ If true the server checks the site header, footer and CSS files for
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
~~~~~~~~~~~~~~~~~~~~~

View File

@@ -24,15 +24,20 @@ import com.google.gerrit.httpd.raw.SshInfoServlet;
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.HttpServletRequest;
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 @@ class UrlModule extends ServletModule {
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 @@ class UrlModule extends ServletModule {
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() {

View File

@@ -52,14 +52,17 @@ import javax.annotation.Nullable;
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 @@ public class WebModule extends FactoryModule {
throw new ProvisionException("Unsupported loginType: " + authConfig.getAuthType());
}
install(new UrlModule());
install(new UrlModule(urlConfig));
install(new UiRpcModule());
install(new GerritRequestModule());
install(new GitOverHttpServlet.Module());

View File

@@ -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.HttpServletRequest;
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;
}