fix #1394 add virtualhosthelper
This commit is contained in:
parent
cee97ebb2e
commit
a6afe7f2de
17 changed files with 85 additions and 62 deletions
|
@ -389,7 +389,7 @@ public class JsonApiManager extends BaseJsonApiManager {
|
|||
if (tags != null) {
|
||||
tagList.addAll(Arrays.asList(tags));
|
||||
}
|
||||
final String key = ComponentUtil.getFessConfig().getVirtualHostKey();
|
||||
final String key = ComponentUtil.getVirtualHostHelper().getVirtualHostKey();
|
||||
if (StringUtil.isNotBlank(key)) {
|
||||
tagList.add(key);
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ public class SuggestApiManager extends BaseJsonApiManager {
|
|||
stream(langs).of(stream -> stream.forEach(builder::addLang));
|
||||
|
||||
stream(parameter.getTags()).of(stream -> stream.forEach(builder::addTag));
|
||||
final String key = ComponentUtil.getFessConfig().getVirtualHostKey();
|
||||
final String key = ComponentUtil.getVirtualHostHelper().getVirtualHostKey();
|
||||
if (StringUtil.isNotBlank(key)) {
|
||||
builder.addTag(key);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.codelibs.core.misc.Pair;
|
|||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.app.web.base.FessAdminAction;
|
||||
import org.codelibs.fess.exception.FessSystemException;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.dbflute.optional.OptionalEntity;
|
||||
import org.lastaflute.web.Execute;
|
||||
import org.lastaflute.web.response.ActionResponse;
|
||||
|
@ -85,7 +86,7 @@ public class AdminDesignAction extends FessAdminAction {
|
|||
for (final Pair<String, String> p : systemHelper.getDesignJspFileNames()) {
|
||||
jspItems.add(new Pair<>(":" + p.getFirst(), "/" + p.getSecond()));
|
||||
}
|
||||
for (String key : fessConfig.getVirtualHostPaths()) {
|
||||
for (String key : ComponentUtil.getVirtualHostHelper().getVirtualHostPaths()) {
|
||||
if (StringUtil.isBlank(key)) {
|
||||
key = "/";
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ public abstract class FessSearchAction extends FessBaseAction {
|
|||
runtime.registerData("thumbnailSupport", thumbnailSupport);
|
||||
if (fessConfig.isWebApiPopularWord()) {
|
||||
final List<String> tagList = new ArrayList<>();
|
||||
final String key = ComponentUtil.getFessConfig().getVirtualHostKey();
|
||||
final String key = ComponentUtil.getVirtualHostHelper().getVirtualHostKey();
|
||||
if (StringUtil.isNotBlank(key)) {
|
||||
tagList.add(key);
|
||||
}
|
||||
|
@ -222,6 +222,6 @@ public abstract class FessSearchAction extends FessBaseAction {
|
|||
}
|
||||
|
||||
protected HtmlNext virtualHost(final HtmlNext path) {
|
||||
return fessConfig.getVirtualHostPath(path);
|
||||
return ComponentUtil.getVirtualHostHelper().getVirtualHostPath(path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ public class KeyMatchHelper {
|
|||
}
|
||||
|
||||
protected Map<String, Pair<QueryBuilder, ScoreFunctionBuilder<?>>> getQueryMap() {
|
||||
final String key = ComponentUtil.getFessConfig().getVirtualHostKey();
|
||||
final String key = ComponentUtil.getVirtualHostHelper().getVirtualHostKey();
|
||||
final Map<String, Pair<QueryBuilder, ScoreFunctionBuilder<?>>> map = keyMatchQueryMap.get(key);
|
||||
if (map != null) {
|
||||
return map;
|
||||
|
|
|
@ -82,7 +82,7 @@ public class LabelTypeHelper {
|
|||
init();
|
||||
}
|
||||
|
||||
final String virtualHostKey = ComponentUtil.getFessConfig().getVirtualHostKey();
|
||||
final String virtualHostKey = ComponentUtil.getVirtualHostHelper().getVirtualHostKey();
|
||||
final List<LabelTypeItem> labelList;
|
||||
if (StringUtil.isBlank(virtualHostKey)) {
|
||||
labelList = labelTypeItemList;
|
||||
|
|
|
@ -93,6 +93,9 @@ public class QueryHelper {
|
|||
@Resource
|
||||
protected KeyMatchHelper keyMatchHelper;
|
||||
|
||||
@Resource
|
||||
protected VirtualHostHelper virtualHostHelper;
|
||||
|
||||
protected Set<String> apiResponseFieldSet;
|
||||
|
||||
protected Set<String> highlightFieldSet = new HashSet<>();
|
||||
|
@ -307,7 +310,7 @@ public class QueryHelper {
|
|||
// nothing to do
|
||||
break;
|
||||
default:
|
||||
final String key = fessConfig.getVirtualHostKey();
|
||||
final String key = virtualHostHelper.getVirtualHostKey();
|
||||
if (StringUtil.isNotBlank(key)) {
|
||||
queryContext.addQuery(boolQuery -> {
|
||||
boolQuery.filter(QueryBuilders.termQuery(fessConfig.getIndexFieldVirtualHost(), key));
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.codelibs.core.lang.StringUtil;
|
|||
import org.codelibs.core.misc.Pair;
|
||||
import org.codelibs.fess.es.config.exbhv.RelatedContentBhv;
|
||||
import org.codelibs.fess.es.config.exentity.RelatedContent;
|
||||
import org.codelibs.fess.mylasta.direction.FessConfig;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -93,8 +92,7 @@ public class RelatedContentHelper {
|
|||
}
|
||||
|
||||
public String[] getRelatedContents(final String query) {
|
||||
final FessConfig fessConfig = ComponentUtil.getFessConfig();
|
||||
final String key = fessConfig.getVirtualHostKey();
|
||||
final String key = ComponentUtil.getVirtualHostHelper().getVirtualHostKey();
|
||||
final Pair<Map<String, String>, List<Pair<Pattern, String>>> pair = relatedContentMap.get(key);
|
||||
if (pair != null) {
|
||||
final List<String> contentList = new ArrayList<>();
|
||||
|
|
|
@ -26,7 +26,6 @@ import javax.annotation.PostConstruct;
|
|||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.fess.es.config.exbhv.RelatedQueryBhv;
|
||||
import org.codelibs.fess.es.config.exentity.RelatedQuery;
|
||||
import org.codelibs.fess.mylasta.direction.FessConfig;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
|
||||
public class RelatedQueryHelper {
|
||||
|
@ -72,8 +71,7 @@ public class RelatedQueryHelper {
|
|||
}
|
||||
|
||||
public String[] getRelatedQueries(final String query) {
|
||||
final FessConfig fessConfig = ComponentUtil.getFessConfig();
|
||||
final String key = fessConfig.getVirtualHostKey();
|
||||
final String key = ComponentUtil.getVirtualHostHelper().getVirtualHostKey();
|
||||
final Map<String, String[]> map = relatedQueryMap.get(key);
|
||||
if (map != null) {
|
||||
final String[] queries = map.get(toLowerCase(query));
|
||||
|
|
|
@ -120,7 +120,7 @@ public class SearchLogHelper {
|
|||
} else {
|
||||
searchLog.setLanguages(StringUtil.EMPTY);
|
||||
}
|
||||
final String virtualHostKey = ComponentUtil.getFessConfig().getVirtualHostKey();
|
||||
final String virtualHostKey = ComponentUtil.getVirtualHostHelper().getVirtualHostKey();
|
||||
if (virtualHostKey != null) {
|
||||
searchLog.setVirtualHost(virtualHostKey);
|
||||
} else {
|
||||
|
|
|
@ -58,7 +58,6 @@ import org.codelibs.fess.util.ComponentUtil;
|
|||
import org.codelibs.fess.validation.FessActionValidator;
|
||||
import org.lastaflute.core.message.supplier.UserMessagesCreator;
|
||||
import org.lastaflute.web.TypicalAction;
|
||||
import org.lastaflute.web.response.next.HtmlNext;
|
||||
import org.lastaflute.web.ruts.process.ActionRuntime;
|
||||
import org.lastaflute.web.servlet.request.RequestManager;
|
||||
import org.lastaflute.web.util.LaServletContextUtil;
|
||||
|
@ -222,7 +221,7 @@ public class SystemHelper {
|
|||
|
||||
public void refreshDesignJspFiles() {
|
||||
final ServletContext servletContext = LaServletContextUtil.getServletContext();
|
||||
stream(ComponentUtil.getFessConfig().getVirtualHostPaths()).of(
|
||||
stream(ComponentUtil.getVirtualHostHelper().getVirtualHostPaths()).of(
|
||||
stream -> stream.filter(s -> s != null && !s.equals("/")).forEach(
|
||||
key -> {
|
||||
designJspFileNameMap
|
||||
|
@ -383,8 +382,4 @@ public class SystemHelper {
|
|||
return new FessActionValidator<>(requestManager, messagesCreator, runtimeGroups);
|
||||
}
|
||||
|
||||
public String getVirtualHostBasePath(final String s, final HtmlNext page) {
|
||||
return StringUtil.isBlank(s) ? StringUtil.EMPTY : "/" + s;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package org.codelibs.fess.helper;
|
||||
|
||||
import static org.codelibs.core.stream.StreamUtil.stream;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.core.misc.Tuple3;
|
||||
import org.codelibs.fess.mylasta.direction.FessConfig;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.lastaflute.web.response.next.HtmlNext;
|
||||
import org.lastaflute.web.util.LaRequestUtil;
|
||||
|
||||
public class VirtualHostHelper {
|
||||
|
||||
public HtmlNext getVirtualHostPath(final HtmlNext page) {
|
||||
return processVirtualHost(s -> {
|
||||
final String basePath = getVirtualHostBasePath(s, page);
|
||||
return new HtmlNext(basePath + page.getRoutingPath());
|
||||
}, page);
|
||||
}
|
||||
|
||||
protected String getVirtualHostBasePath(final String s, final HtmlNext page) {
|
||||
return StringUtil.isBlank(s) ? StringUtil.EMPTY : "/" + s;
|
||||
}
|
||||
|
||||
public String getVirtualHostKey() {
|
||||
return LaRequestUtil.getOptionalRequest().map(req -> (String) req.getAttribute(FessConfig.VIRTUAL_HOST_VALUE)).orElseGet(() -> {
|
||||
final String value = processVirtualHost(s -> s, StringUtil.EMPTY);
|
||||
LaRequestUtil.getOptionalRequest().ifPresent(req -> req.setAttribute(FessConfig.VIRTUAL_HOST_VALUE, value));
|
||||
return value;
|
||||
});
|
||||
}
|
||||
|
||||
protected <T> T processVirtualHost(final Function<String, T> func, final T defaultValue) {
|
||||
final Tuple3<String, String, String>[] vHosts = ComponentUtil.getFessConfig().getVirtualHosts();
|
||||
return LaRequestUtil.getOptionalRequest().map(req -> {
|
||||
for (final Tuple3<String, String, String> host : vHosts) {
|
||||
final String headerValue = req.getHeader(host.getValue1());
|
||||
if (host.getValue2().equalsIgnoreCase(headerValue)) {
|
||||
return func.apply(host.getValue3());
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
}).orElse(defaultValue);
|
||||
}
|
||||
|
||||
public String[] getVirtualHostPaths() {
|
||||
return stream(ComponentUtil.getFessConfig().getVirtualHosts()).get(
|
||||
stream -> stream.map(h -> "/" + h.getValue3()).toArray(n -> new String[n]));
|
||||
}
|
||||
}
|
|
@ -36,7 +36,6 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -64,7 +63,6 @@ import org.elasticsearch.search.sort.SortBuilders;
|
|||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.lastaflute.job.LaJob;
|
||||
import org.lastaflute.job.subsidiary.JobConcurrentExec;
|
||||
import org.lastaflute.web.response.next.HtmlNext;
|
||||
import org.lastaflute.web.util.LaRequestUtil;
|
||||
import org.lastaflute.web.validation.RequiredValidator;
|
||||
import org.lastaflute.web.validation.theme.typed.DoubleTypeValidator;
|
||||
|
@ -1616,21 +1614,6 @@ public interface FessProp {
|
|||
|
||||
String getVirtualHostHeaders();
|
||||
|
||||
public default HtmlNext getVirtualHostPath(final HtmlNext page) {
|
||||
return processVirtualHost(s -> {
|
||||
final String basePath = ComponentUtil.getSystemHelper().getVirtualHostBasePath(s, page);
|
||||
return new HtmlNext(basePath + page.getRoutingPath());
|
||||
}, page);
|
||||
}
|
||||
|
||||
public default String getVirtualHostKey() {
|
||||
return LaRequestUtil.getOptionalRequest().map(req -> (String) req.getAttribute(VIRTUAL_HOST_VALUE)).orElseGet(() -> {
|
||||
final String value = processVirtualHost(s -> s, StringUtil.EMPTY);
|
||||
LaRequestUtil.getOptionalRequest().ifPresent(req -> req.setAttribute(VIRTUAL_HOST_VALUE, value));
|
||||
return value;
|
||||
});
|
||||
}
|
||||
|
||||
public default String getVirtualHostHeaderValue() {
|
||||
final String value = getVirtualHostValue();
|
||||
if (StringUtil.isNotBlank(value)) {
|
||||
|
@ -1639,27 +1622,6 @@ public interface FessProp {
|
|||
return getVirtualHostHeaders();
|
||||
}
|
||||
|
||||
public default <T> T processVirtualHost(final Function<String, T> func, final T defaultValue) {
|
||||
final Tuple3<String, String, String>[] vHosts = getVirtualHosts();
|
||||
return LaRequestUtil.getOptionalRequest().map(req -> {
|
||||
for (final Tuple3<String, String, String> host : vHosts) {
|
||||
final String headerValue = req.getHeader(host.getValue1());
|
||||
if (host.getValue2().equalsIgnoreCase(headerValue)) {
|
||||
return func.apply(host.getValue3());
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
}).orElse(defaultValue);
|
||||
}
|
||||
|
||||
public default String[] getVirtualHostKeys() {
|
||||
return stream(getVirtualHosts()).get(stream -> stream.map(h -> h.getValue3()).toArray(n -> new String[n]));
|
||||
}
|
||||
|
||||
public default String[] getVirtualHostPaths() {
|
||||
return stream(getVirtualHosts()).get(stream -> stream.map(h -> "/" + h.getValue3()).toArray(n -> new String[n]));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public default Tuple3<String, String, String>[] getVirtualHosts() {
|
||||
Tuple3<String, String, String>[] hosts = (Tuple3<String, String, String>[]) propMap.get(VIRTUAL_HOST_HEADERS);
|
||||
|
|
|
@ -43,7 +43,7 @@ public class FessActionAdjustmentProvider implements ActionAdjustmentProvider {
|
|||
if (StringUtil.isBlank(requestPath)) {
|
||||
return null;
|
||||
}
|
||||
final String virtualHostKey = ComponentUtil.getFessConfig().getVirtualHostKey();
|
||||
final String virtualHostKey = ComponentUtil.getVirtualHostHelper().getVirtualHostKey();
|
||||
if (StringUtil.isBlank(virtualHostKey)) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ import org.codelibs.fess.helper.SystemHelper;
|
|||
import org.codelibs.fess.helper.UserAgentHelper;
|
||||
import org.codelibs.fess.helper.UserInfoHelper;
|
||||
import org.codelibs.fess.helper.ViewHelper;
|
||||
import org.codelibs.fess.helper.VirtualHostHelper;
|
||||
import org.codelibs.fess.indexer.IndexUpdater;
|
||||
import org.codelibs.fess.job.JobExecutor;
|
||||
import org.codelibs.fess.ldap.LdapManager;
|
||||
|
@ -162,6 +163,12 @@ public final class ComponentUtil {
|
|||
|
||||
private static final String INDEXING_HELPER = "indexingHelper";
|
||||
|
||||
private static final String VIRTUAL_HOST_HELPER = "virtualHostHelper";
|
||||
|
||||
private static final String RELATED_CONTENT_HELPER = "relatedContentHelper";
|
||||
|
||||
private static final String RELATED_QUERY_HELPER = "relatedQueryHelper";
|
||||
|
||||
private static IndexingHelper indexingHelper;
|
||||
|
||||
private static CrawlingConfigHelper crawlingConfigHelper;
|
||||
|
@ -396,11 +403,15 @@ public final class ComponentUtil {
|
|||
}
|
||||
|
||||
public static RelatedQueryHelper getRelatedQueryHelper() {
|
||||
return getComponent(RelatedQueryHelper.class);
|
||||
return getComponent(RELATED_QUERY_HELPER);
|
||||
}
|
||||
|
||||
public static RelatedContentHelper getRelatedContentHelper() {
|
||||
return getComponent(RelatedContentHelper.class);
|
||||
return getComponent(RELATED_CONTENT_HELPER);
|
||||
}
|
||||
|
||||
public static VirtualHostHelper getVirtualHostHelper() {
|
||||
return getComponent(VIRTUAL_HOST_HELPER);
|
||||
}
|
||||
|
||||
public static <T> T getComponent(final Class<T> clazz) {
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
</component>
|
||||
<component name="sambaHelper" class="org.codelibs.fess.helper.SambaHelper">
|
||||
</component>
|
||||
<component name="virtualHostHelper" class="org.codelibs.fess.helper.VirtualHostHelper">
|
||||
</component>
|
||||
<component name="systemHelper" class="org.codelibs.fess.helper.SystemHelper">
|
||||
<postConstruct name="addDesignJspFileName">
|
||||
<arg>"index"</arg>
|
||||
|
|
|
@ -59,6 +59,7 @@ public class QueryHelperTest extends UnitFessTestCase {
|
|||
final FessConfig fessConfig = ComponentUtil.getFessConfig();
|
||||
registerMock(fessConfig);
|
||||
registerMock(new SystemHelper());
|
||||
registerMock(new VirtualHostHelper());
|
||||
inject(queryHelper);
|
||||
queryHelper.init();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue