Discontinue deprecated /query servlet
Change-Id: Ibcf6ab76548eaa9e05ff6f35011b8024f015bcb9
This commit is contained in:

committed by
David Pursehouse

parent
16570463ab
commit
922bbf10fb
@@ -2990,12 +2990,6 @@ If true the server checks the site header, footer and CSS files for
|
|||||||
updated versions. If false, a server restart is required to change
|
updated versions. If false, a server restart is required to change
|
||||||
any of these resources. Default is true, allowing automatic reloads.
|
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 false, disabling `/query`.
|
|
||||||
|
|
||||||
[[ssh-alias]]
|
[[ssh-alias]]
|
||||||
=== Section ssh-alias
|
=== Section ssh-alias
|
||||||
|
|
||||||
|
@@ -28,22 +28,18 @@ import com.google.gerrit.httpd.raw.ToolServlet;
|
|||||||
import com.google.gerrit.httpd.rpc.access.AccessRestApiServlet;
|
import com.google.gerrit.httpd.rpc.access.AccessRestApiServlet;
|
||||||
import com.google.gerrit.httpd.rpc.account.AccountsRestApiServlet;
|
import com.google.gerrit.httpd.rpc.account.AccountsRestApiServlet;
|
||||||
import com.google.gerrit.httpd.rpc.change.ChangesRestApiServlet;
|
import com.google.gerrit.httpd.rpc.change.ChangesRestApiServlet;
|
||||||
import com.google.gerrit.httpd.rpc.change.DeprecatedChangeQueryServlet;
|
|
||||||
import com.google.gerrit.httpd.rpc.config.ConfigRestApiServlet;
|
import com.google.gerrit.httpd.rpc.config.ConfigRestApiServlet;
|
||||||
import com.google.gerrit.httpd.rpc.doc.QueryDocumentationFilter;
|
import com.google.gerrit.httpd.rpc.doc.QueryDocumentationFilter;
|
||||||
import com.google.gerrit.httpd.rpc.group.GroupsRestApiServlet;
|
import com.google.gerrit.httpd.rpc.group.GroupsRestApiServlet;
|
||||||
import com.google.gerrit.httpd.rpc.project.ProjectsRestApiServlet;
|
import com.google.gerrit.httpd.rpc.project.ProjectsRestApiServlet;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.server.config.GerritServerConfig;
|
|
||||||
import com.google.gwtexpui.server.CacheControlFilter;
|
import com.google.gwtexpui.server.CacheControlFilter;
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.internal.UniqueAnnotations;
|
import com.google.inject.internal.UniqueAnnotations;
|
||||||
import com.google.inject.servlet.ServletModule;
|
import com.google.inject.servlet.ServletModule;
|
||||||
|
|
||||||
import org.eclipse.jgit.lib.Config;
|
|
||||||
import org.eclipse.jgit.lib.Constants;
|
import org.eclipse.jgit.lib.Constants;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -53,20 +49,9 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
class UrlModule extends ServletModule {
|
class UrlModule extends ServletModule {
|
||||||
static class UrlConfig {
|
|
||||||
private final boolean deprecatedQuery;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
UrlConfig(@GerritServerConfig Config cfg) {
|
|
||||||
deprecatedQuery = cfg.getBoolean("site", "enableDeprecatedQuery", false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final UrlConfig cfg;
|
|
||||||
private GerritOptions options;
|
private GerritOptions options;
|
||||||
|
|
||||||
UrlModule(UrlConfig cfg, GerritOptions options) {
|
UrlModule(GerritOptions options) {
|
||||||
this.cfg = cfg;
|
|
||||||
this.options = options;
|
this.options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,10 +98,6 @@ class UrlModule extends ServletModule {
|
|||||||
|
|
||||||
filter("/Documentation/").through(QueryDocumentationFilter.class);
|
filter("/Documentation/").through(QueryDocumentationFilter.class);
|
||||||
|
|
||||||
if (cfg.deprecatedQuery) {
|
|
||||||
serve("/query").with(DeprecatedChangeQueryServlet.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
serve("/robots.txt").with(RobotsServlet.class);
|
serve("/robots.txt").with(RobotsServlet.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -44,19 +44,16 @@ import java.net.SocketAddress;
|
|||||||
|
|
||||||
public class WebModule extends LifecycleModule {
|
public class WebModule extends LifecycleModule {
|
||||||
private final AuthConfig authConfig;
|
private final AuthConfig authConfig;
|
||||||
private final UrlModule.UrlConfig urlConfig;
|
|
||||||
private final boolean wantSSL;
|
private final boolean wantSSL;
|
||||||
private final GitWebConfig gitWebConfig;
|
private final GitWebConfig gitWebConfig;
|
||||||
private final GerritOptions options;
|
private final GerritOptions options;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
WebModule(final AuthConfig authConfig,
|
WebModule(final AuthConfig authConfig,
|
||||||
final UrlModule.UrlConfig urlConfig,
|
|
||||||
@CanonicalWebUrl @Nullable final String canonicalUrl,
|
@CanonicalWebUrl @Nullable final String canonicalUrl,
|
||||||
GerritOptions options,
|
GerritOptions options,
|
||||||
final Injector creatingInjector) {
|
final Injector creatingInjector) {
|
||||||
this.authConfig = authConfig;
|
this.authConfig = authConfig;
|
||||||
this.urlConfig = urlConfig;
|
|
||||||
this.wantSSL = canonicalUrl != null && canonicalUrl.startsWith("https:");
|
this.wantSSL = canonicalUrl != null && canonicalUrl.startsWith("https:");
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
|
||||||
@@ -81,7 +78,7 @@ public class WebModule extends LifecycleModule {
|
|||||||
|
|
||||||
if (options.enableMasterFeatures()) {
|
if (options.enableMasterFeatures()) {
|
||||||
installAuthModule();
|
installAuthModule();
|
||||||
install(new UrlModule(urlConfig, options));
|
install(new UrlModule(options));
|
||||||
install(new UiRpcModule());
|
install(new UiRpcModule());
|
||||||
}
|
}
|
||||||
install(new GerritRequestModule());
|
install(new GerritRequestModule());
|
||||||
|
@@ -1,116 +0,0 @@
|
|||||||
// Copyright (C) 2010 The Android Open Source Project
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package com.google.gerrit.httpd.rpc.change;
|
|
||||||
|
|
||||||
import com.google.gerrit.server.query.change.OutputStreamQuery;
|
|
||||||
import com.google.gerrit.server.query.change.OutputStreamQuery.OutputFormat;
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.google.inject.Provider;
|
|
||||||
import com.google.inject.Singleton;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import javax.servlet.ServletOutputStream;
|
|
||||||
import javax.servlet.http.HttpServlet;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
public class DeprecatedChangeQueryServlet extends HttpServlet {
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
private final Provider<OutputStreamQuery> queryProvider;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
DeprecatedChangeQueryServlet(Provider<OutputStreamQuery> queryProvider) {
|
|
||||||
this.queryProvider = queryProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse rsp)
|
|
||||||
throws IOException {
|
|
||||||
rsp.setContentType("text/json");
|
|
||||||
rsp.setCharacterEncoding("UTF-8");
|
|
||||||
|
|
||||||
OutputStreamQuery p = queryProvider.get();
|
|
||||||
OutputFormat format = OutputFormat.JSON;
|
|
||||||
try {
|
|
||||||
format = OutputFormat.valueOf(get(req, "format", format.toString()));
|
|
||||||
} catch (IllegalArgumentException err) {
|
|
||||||
error(rsp, "invalid format");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (format) {
|
|
||||||
case JSON:
|
|
||||||
rsp.setContentType("text/json");
|
|
||||||
rsp.setCharacterEncoding("UTF-8");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TEXT:
|
|
||||||
rsp.setContentType("text/plain");
|
|
||||||
rsp.setCharacterEncoding("UTF-8");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
error(rsp, "invalid format");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
p.setIncludeComments(get(req, "comments", false));
|
|
||||||
p.setIncludeCurrentPatchSet(get(req, "current-patch-set", false));
|
|
||||||
p.setIncludePatchSets(get(req, "patch-sets", false));
|
|
||||||
p.setIncludeApprovals(get(req, "all-approvals", false));
|
|
||||||
p.setIncludeFiles(get(req, "files", false));
|
|
||||||
p.setOutput(rsp.getOutputStream(), format);
|
|
||||||
p.query(get(req, "q", "status:open"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void error(HttpServletResponse rsp, String message)
|
|
||||||
throws IOException {
|
|
||||||
ErrorMessage em = new ErrorMessage();
|
|
||||||
em.message = message;
|
|
||||||
|
|
||||||
ServletOutputStream out = rsp.getOutputStream();
|
|
||||||
try {
|
|
||||||
out.write(new Gson().toJson(em).getBytes("UTF-8"));
|
|
||||||
out.write('\n');
|
|
||||||
out.flush();
|
|
||||||
} finally {
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String get(HttpServletRequest req, String name, String val) {
|
|
||||||
String v = req.getParameter(name);
|
|
||||||
if (v == null || v.isEmpty()) {
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean get(HttpServletRequest req, String name, boolean val) {
|
|
||||||
String v = req.getParameter(name);
|
|
||||||
if (v == null || v.isEmpty()) {
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
return "true".equalsIgnoreCase(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ErrorMessage {
|
|
||||||
public final String type = "error";
|
|
||||||
public String message;
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user