diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/StaticModule.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/StaticModule.java index f92beb6273..f8ac26dd61 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/StaticModule.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/StaticModule.java @@ -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 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() { diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/WarDocServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/WarDocServlet.java new file mode 100644 index 0000000000..ad233140b4 --- /dev/null +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/WarDocServlet.java @@ -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 cache, FileSystem warFs) { + super(cache, false); + this.warFs = warFs; + } + + @Override + protected Path getResourcePath(String pathInfo) { + return warFs.getPath("/Documentation/" + pathInfo); + } +}