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:
@@ -38,6 +38,8 @@ import java.nio.file.FileSystem;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
public class StaticModule extends ServletModule {
|
public class StaticModule extends ServletModule {
|
||||||
public static final String CACHE = "static_content";
|
public static final String CACHE = "static_content";
|
||||||
@@ -57,6 +59,7 @@ public class StaticModule extends ServletModule {
|
|||||||
"/projects/*");
|
"/projects/*");
|
||||||
|
|
||||||
private static final String GWT_UI_SERVLET = "GwtUiServlet";
|
private static final String GWT_UI_SERVLET = "GwtUiServlet";
|
||||||
|
private static final String DOC_SERVLET = "DocServlet";
|
||||||
|
|
||||||
private final GerritOptions options;
|
private final GerritOptions options;
|
||||||
private Paths paths;
|
private Paths paths;
|
||||||
@@ -75,6 +78,8 @@ public class StaticModule extends ServletModule {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureServlets() {
|
protected void configureServlets() {
|
||||||
|
serveRegex("^/Documentation/(.+)$").with(
|
||||||
|
Key.get(HttpServlet.class, Names.named(DOC_SERVLET)));
|
||||||
serve("/static/*").with(SiteStaticDirectoryServlet.class);
|
serve("/static/*").with(SiteStaticDirectoryServlet.class);
|
||||||
install(new CacheModule() {
|
install(new CacheModule() {
|
||||||
@Override
|
@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 {
|
private class GwtUiModule extends ServletModule {
|
||||||
@Override
|
@Override
|
||||||
public void configureServlets() {
|
public void configureServlets() {
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user