Brings Gerrit docs back to life

After the regression introduced by [1] the Gerrit static
documentation was not available anymore in the standard Jetty embedded
server scenario. This change is the ideal completion of the refactoring
of the Jetty-controlled static resources serving legacy logic into
the new Gerrit-driven ResourceServlet mechanism.

[1] https://gerrit-review.googlesource.com/#/c/72085/

Change-Id: If0a52a34a2e1ae1030541b8a2c0d041eafe32af7
This commit is contained in:
Luca Milanesio 2015-11-25 11:42:19 +00:00
parent 821754e71a
commit 1d1a12a776
2 changed files with 61 additions and 0 deletions

View File

@ -38,6 +38,8 @@ import java.nio.file.FileSystem;
import java.nio.file.Path;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class StaticModule extends ServletModule {
public static final String CACHE = "static_content";
@ -57,6 +59,7 @@ public class StaticModule extends ServletModule {
"/projects/*");
private static final String GWT_UI_SERVLET = "GwtUiServlet";
private static final String DOC_SERVLET = "DocServlet";
private final GerritOptions options;
private Paths paths;
@ -75,6 +78,8 @@ public class StaticModule extends ServletModule {
@Override
protected void configureServlets() {
serveRegex("^/Documentation/(.+)$").with(
Key.get(HttpServlet.class, Names.named(DOC_SERVLET)));
serve("/static/*").with(SiteStaticDirectoryServlet.class);
install(new CacheModule() {
@Override
@ -91,6 +96,26 @@ public class StaticModule extends ServletModule {
}
}
@Provides
@Singleton
@Named(DOC_SERVLET)
HttpServlet getDocServlet(@Named(CACHE) Cache<Path, Resource> cache) {
Paths p = getPaths();
if (p.warFs != null) {
return new WarDocServlet(cache, p.warFs);
} else {
return new HttpServlet() {
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest req,
HttpServletResponse resp) throws IOException {
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
}
};
}
}
private class GwtUiModule extends ServletModule {
@Override
public void configureServlets() {

View File

@ -0,0 +1,36 @@
// Copyright (C) 2015 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.raw;
import com.google.common.cache.Cache;
import java.nio.file.FileSystem;
import java.nio.file.Path;
class WarDocServlet extends ResourceServlet {
private static final long serialVersionUID = 1L;
private final FileSystem warFs;
WarDocServlet(Cache<Path, Resource> cache, FileSystem warFs) {
super(cache, false);
this.warFs = warFs;
}
@Override
protected Path getResourcePath(String pathInfo) {
return warFs.getPath("/Documentation/" + pathInfo);
}
}