dsmiley commented on code in PR #4119: URL: https://github.com/apache/solr/pull/4119#discussion_r3007037321
########## solr/core/src/java/org/apache/solr/servlet/SolrServlet.java: ########## @@ -0,0 +1,163 @@ +/* + * 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 static org.apache.solr.util.tracing.TraceUtils.getSpan; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.UnavailableException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.lang.invoke.MethodHandles; +import org.apache.solr.api.V2HttpCall; +import org.apache.solr.common.SolrException; +import org.apache.solr.common.SolrException.ErrorCode; +import org.apache.solr.common.util.ExecutorUtil; +import org.apache.solr.core.CoreContainer; +import org.apache.solr.core.NodeRoles; +import org.apache.solr.handler.api.V2ApiUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** Solr's interface to Jetty. Formerly known as {@code SolrDispatchFilter}. */ +public class SolrServlet extends HttpServlet { + private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + private HttpSolrCallFactory solrCallFactory; + private CoreContainerProvider containerProvider; + + @Override + public void init(ServletConfig config) throws ServletException { + try { + super.init(config); + containerProvider = CoreContainerProvider.serviceForContext(config.getServletContext()); + boolean isCoordinator = + NodeRoles.MODE_ON.equals(getCores().nodeRoles.getRoleMode(NodeRoles.Role.COORDINATOR)); + solrCallFactory = + isCoordinator ? new CoordinatorHttpSolrCall.Factory() : new HttpSolrCallFactory() {}; + if (log.isTraceEnabled()) { + log.trace("init(): {}", this.getClass().getClassLoader()); + } + } catch (Throwable t) { + // catch this so our servlet still works + log.error("Could not start Servlet.", t); + if (t instanceof Error) { + throw (Error) t; + } + } finally { + log.trace("init() done"); + } + } + + /** + * The CoreContainer. It's guaranteed to be constructed before this servlet is initialized, but + * could have been shut down. Never null. + */ + public CoreContainer getCores() throws UnavailableException { + return containerProvider.getCoreContainer(); + } + + @Override + protected void service(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + // Handle root path specially - forward to index.html to trigger welcome-file mechanism Review Comment: > Ideally we would eventually move the UI to the root +1 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
