Apache Lucene open-source search software
SOLR-5951: Fixed SolrDispatchFilter to throw useful exception on startup if SLF4j logging jars are missing
Uwe Schindler21b6d9890eac
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 6e5219fcf73..a201b8c1d00 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -188,6 +188,9 @@ Bug Fixes* SOLR-5943: SolrCmdDistributor does not distribute the openSearcher parameter.(ludovic Boutros via shalin)+* SOLR-5951: Fixed SolrDispatchFilter to throw useful exception on startup if+ SLF4j logging jars are missing. (Uwe Schindler, Hossman, Shawn Heisey)+Optimizations----------------------* SOLR-1880: Distributed Search skips GET_FIELDS stage if EXECUTE_QUERYdiff --git a/solr/core/src/java/org/apache/solr/servlet/BaseSolrFilter.java b/solr/core/src/java/org/apache/solr/servlet/BaseSolrFilter.javanew file mode 100644index 00000000000..966bad2916f--- /dev/null+++ b/solr/core/src/java/org/apache/solr/servlet/BaseSolrFilter.java@@ -0,0 +1,34 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You 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 org.apache.solr.servlet;++import javax.servlet.Filter;++/**+ * All Solr filters available to the user's webapp should+ * extend this class and not just implement {@link Filter}.+ * This class ensures that the logging configuration is correct+ * before any Solr specific code is executed.+ */+abstract class BaseSolrFilter implements Filter {++ static {+ CheckLoggingConfiguration.check();+ }++}diff --git a/solr/core/src/java/org/apache/solr/servlet/BaseSolrServlet.java b/solr/core/src/java/org/apache/solr/servlet/BaseSolrServlet.javanew file mode 100644index 00000000000..3a1f88ac333--- /dev/null+++ b/solr/core/src/java/org/apache/solr/servlet/BaseSolrServlet.java@@ -0,0 +1,35 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You 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 org.apache.solr.servlet;++import javax.servlet.http.HttpServlet;++/**+ * All Solr servlets available to the user's webapp should+ * extend this class and not {@link HttpServlet}.+ * This class ensures that the logging configuration is correct+ * before any Solr specific code is executed.+ */+@SuppressWarnings("serial")+abstract class BaseSolrServlet extends HttpServlet {++ static {+ CheckLoggingConfiguration.check();+ }++}diff --git a/solr/core/src/java/org/apache/solr/servlet/CheckLoggingConfiguration.java b/solr/core/src/java/org/apache/solr/servlet/CheckLoggingConfiguration.javanew file mode 100644index 00000000000..bd8842cfc74--- /dev/null+++ b/solr/core/src/java/org/apache/solr/servlet/CheckLoggingConfiguration.java@@ -0,0 +1,37 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You 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 org.apache.solr.servlet;++import org.slf4j.LoggerFactory;++final class CheckLoggingConfiguration {++ static void check() {+ try {+ LoggerFactory.getLogger(CheckLoggingConfiguration.class);+ } catch (NoClassDefFoundError e) {+ throw new NoClassDefFoundError("Failed to initialize Apache Solr: "+ +"Could not find necessary SLF4j logging jars. If using Jetty, the SLF4j logging jars need to go in "+ +"the jetty lib/ext directory. For other containers, the corresponding directory should be used. "+ +"For more information, see: http://wiki.apache.org/solr/SolrLogging");+ }+ }++ private CheckLoggingConfiguration() {}++}diff --git a/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java b/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.javaindex 196e9f3fb25..157209737dc 100644--- a/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java+++ b/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java@@ -23,7 +23,6 @@ import java.io.OutputStreamWriter;import java.io.Writer;import java.nio.charset.StandardCharsets;-import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;@@ -38,7 +37,7 @@ import org.apache.solr.core.SolrCore;** @since solr 4.0*/-public final class LoadAdminUiServlet extends HttpServlet {+public final class LoadAdminUiServlet extends BaseSolrServlet {@Overridepublic void doGet(HttpServletRequest request,diff --git a/solr/core/src/java/org/apache/solr/servlet/RedirectServlet.java b/solr/core/src/java/org/apache/solr/servlet/RedirectServlet.javaindex bc497461760..4661f82b3c6 100644--- a/solr/core/src/java/org/apache/solr/servlet/RedirectServlet.java+++ b/solr/core/src/java/org/apache/solr/servlet/RedirectServlet.java@@ -21,14 +21,13 @@ import java.io.IOException;import javax.servlet.ServletConfig;import javax.servlet.ServletException;-import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;/*** A Simple redirection servlet to help us deprecate old UI elements*/-public class RedirectServlet extends HttpServlet{+public class RedirectServlet extends BaseSolrServlet {static final String CONTEXT_KEY = "${context}";diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.javaindex a0b4f1dcadc..efee05ea3c0 100644--- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java+++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java@@ -73,7 +73,6 @@ import org.apache.solr.util.FastWriter;import org.slf4j.Logger;import org.slf4j.LoggerFactory;-import javax.servlet.Filter;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import javax.servlet.ServletException;@@ -107,13 +106,12 @@ import java.util.Set;** @since solr 1.2*/-public class SolrDispatchFilter implements Filter-{+public class SolrDispatchFilter extends BaseSolrFilter {private static final String CONNECTION_HEADER = "Connection";private static final String TRANSFER_ENCODING_HEADER = "Transfer-Encoding";private static final String CONTENT_LENGTH_HEADER = "Content-Length";- final Logger log;+ static final Logger log = LoggerFactory.getLogger(SolrDispatchFilter.class);protected volatile CoreContainer cores;@@ -124,16 +122,6 @@ public class SolrDispatchFilter implements Filterprivate static final Charset UTF8 = StandardCharsets.UTF_8;public SolrDispatchFilter() {- try {- log = LoggerFactory.getLogger(SolrDispatchFilter.class);- } catch (NoClassDefFoundError e) {- throw new SolrException(- ErrorCode.SERVER_ERROR,- "Could not find necessary SLF4j logging jars. If using Jetty, the SLF4j logging jars need to go in "- +"the jetty lib/ext directory. For other containers, the corresponding directory should be used. "- +"For more information, see: http://wiki.apache.org/solr/SolrLogging",- e);- }}@Overridediff --git a/solr/core/src/java/org/apache/solr/servlet/ZookeeperInfoServlet.java b/solr/core/src/java/org/apache/solr/servlet/ZookeeperInfoServlet.javaindex 710160fbb8a..06718c32410 100644--- a/solr/core/src/java/org/apache/solr/servlet/ZookeeperInfoServlet.java+++ b/solr/core/src/java/org/apache/solr/servlet/ZookeeperInfoServlet.java@@ -26,7 +26,6 @@ import java.util.Date;import java.util.List;import javax.servlet.ServletException;-import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;@@ -50,7 +49,7 @@ import org.slf4j.LoggerFactory;** @since solr 4.0*/-public final class ZookeeperInfoServlet extends HttpServlet {+public final class ZookeeperInfoServlet extends BaseSolrServlet {static final Logger log = LoggerFactory.getLogger(ZookeeperInfoServlet.class);@Override