fix #605 move site plugin to WEB-INF/site

This commit is contained in:
Shinsuke Sugaya 2016-12-31 23:09:21 +09:00
parent f9e7f38a62
commit fd30f0f436
5 changed files with 57 additions and 3 deletions

2
.gitignore vendored
View file

@ -5,6 +5,8 @@
/solr/data/
/src/main/webapp/WEB-INF/classes/
/src/main/webapp/WEB-INF/lib/
/src/main/webapp/WEB-INF/site/
/src/main/webapp/WEB-INF/thumbnails/
/src/main/webapp/jar/
/dbflute_fess/log/*.log
/dbflute_h2/log/*.log

View file

@ -2,6 +2,8 @@
<project name="plugin" basedir=".">
<property name="plugins.dir" value="${basedir}/plugins" />
<property name="target.dir" value="${basedir}/target/plugins" />
<property name="site.dir" value="${basedir}/src/main/webapp/WEB-INF/site" />
<property name="kopf.branch" value="fess-5.0" />
<!-- Maven Repository -->
<property name="maven.snapshot.repo.url" value="https://oss.sonatype.org/content/repositories/snapshots" />
@ -65,6 +67,17 @@
<param name="plugin.version" value="5.0.0-SNAPSHOT" />
<param name="plugin.zip.version" value="5.0.0-20161222.135357-2" />
</antcall>
<!-- kopf -->
<get dest="${target.dir}/kopf.zip">
<url url="https://github.com/codelibs/elasticsearch-kopf/archive/${kopf.branch}.zip" />
</get>
<delete dir="${site.dir}/kopf" />
<unzip dest="${site.dir}/kopf" src="${target.dir}/kopf.zip">
<patternset>
<include name="elasticsearch-kopf-${kopf.branch}/_site/**" />
</patternset>
<cutdirsmapper dirs="2" />
</unzip>
<antcall target="remove.jars" />
</target>

View file

@ -226,6 +226,7 @@
<excludes>
<exclude>**/*min.js</exclude>
<exclude>**/form-validator/**/*.js</exclude>
<exclude>**/WEB-INF/site/**</exclude>
</excludes>
</configuration>
</plugin>

View file

@ -18,6 +18,8 @@ package org.codelibs.fess.api.es;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
import java.util.UUID;
@ -95,9 +97,6 @@ public class EsApiManager extends BaseApiManager {
}
protected void processRequest(final HttpServletRequest request, final HttpServletResponse response, final String path) {
final Method httpMethod = Method.valueOf(request.getMethod().toUpperCase(Locale.ROOT));
final CurlRequest curlRequest = new CurlRequest(httpMethod, ResourceUtil.getElasticsearchHttpUrl() + path);
if (StringUtil.isNotBlank(path)) {
final String lowerPath = path.toLowerCase(Locale.ROOT);
if (lowerPath.endsWith(".html")) {
@ -109,6 +108,14 @@ public class EsApiManager extends BaseApiManager {
}
}
if (path.startsWith("/_plugin/") || path.equals("/_plugin")) {
processPluginRequest(request, response, path.replaceFirst("^/_plugin", StringUtil.EMPTY));
return;
}
final Method httpMethod = Method.valueOf(request.getMethod().toUpperCase(Locale.ROOT));
final CurlRequest curlRequest = new CurlRequest(httpMethod, ResourceUtil.getElasticsearchHttpUrl() + path);
request.getParameterMap().entrySet().stream().forEach(entry -> {
if (entry.getValue().length > 1) {
curlRequest.param(entry.getKey(), String.join(",", entry.getValue()));
@ -146,6 +153,33 @@ public class EsApiManager extends BaseApiManager {
} );
}
private void processPluginRequest(HttpServletRequest request, HttpServletResponse response, String path) {
Path filePath = ResourceUtil.getSitePath(path.replaceAll("\\.\\.+", StringUtil.EMPTY).replaceAll("/+", "/").split("/"));
if (Files.isDirectory(filePath)) {
filePath = filePath.resolve("index.html");
}
if (Files.exists(filePath)) {
try (InputStream in = Files.newInputStream(filePath); ServletOutputStream out = response.getOutputStream()) {
response.setStatus(HttpServletResponse.SC_OK);
CopyUtil.copy(in, out);
} catch (final ClientAbortException e) {
logger.debug("Client aborts this request.", e);
} catch (IOException e) {
logger.error("Failed to read " + path + " from " + filePath);
throw new WebApiException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
}
} else {
try {
response.sendError(HttpServletResponse.SC_NOT_FOUND, path + " is not found.");
} catch (final ClientAbortException e) {
logger.debug("Client aborts this request.", e);
} catch (IOException e) {
logger.error("Failed to read " + path + " from " + filePath);
throw new WebApiException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
}
}
}
public void setAcceptedRoles(final String[] acceptedRoles) {
this.acceptedRoles = acceptedRoles;
}

View file

@ -76,6 +76,10 @@ public class ResourceUtil {
return getPath("thumbnails", names);
}
public static Path getSitePath(final String... names) {
return getPath("site", names);
}
protected static Path getPath(final String base, final String... names) {
try {