lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elyog...@apache.org
Subject [1/4] lucene-solr:solr-6733: SOLR-6733: A beginning.
Date Wed, 06 Jun 2018 05:43:53 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/solr-6733 [created] d3cc745b8
  refs/heads/solr-6773 [deleted] d3cc745b8


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d3cc745b/solr/start/ivy.xml
----------------------------------------------------------------------
diff --git a/solr/start/ivy.xml b/solr/start/ivy.xml
new file mode 100644
index 0000000..ed9823c
--- /dev/null
+++ b/solr/start/ivy.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+   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.    
+-->
+<ivy-module version="2.0">
+  <info organisation="org.apache.solr" module="solrj"/>
+
+  <configurations defaultconfmapping="compile->master;test->master">
+    <!-- artifacts in the "compile" configuration will go into solr/solrj/lib/ -->
+    <conf name="compile" transitive="false"/>
+    <!-- artifacts in the "test" configuration will go into solr/solrj/test-lib/ -->
+    <conf name="test" transitive="false"/>
+  </configurations>
+
+  <dependencies>
+    <dependency org="org.slf4j" name="slf4j-api" rev="${/org.slf4j/slf4j-api}" conf="compile"/>
+    <exclude org="*" ext="*" matcher="regexp" type="${ivy.exclude.types}"/>
+  </dependencies>
+</ivy-module>

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d3cc745b/solr/start/src/java/org/apache/solr/start/Main.java
----------------------------------------------------------------------
diff --git a/solr/start/src/java/org/apache/solr/start/Main.java b/solr/start/src/java/org/apache/solr/start/Main.java
new file mode 100644
index 0000000..cec908f
--- /dev/null
+++ b/solr/start/src/java/org/apache/solr/start/Main.java
@@ -0,0 +1,159 @@
+package org.apache.solr.start;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory;
+import org.eclipse.jetty.http2.HTTP2Cipher;
+import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory;
+import org.eclipse.jetty.server.AsyncNCSARequestLog;
+import org.eclipse.jetty.server.HttpConfiguration;
+import org.eclipse.jetty.server.HttpConnectionFactory;
+import org.eclipse.jetty.server.NegotiatingServerConnectionFactory;
+import org.eclipse.jetty.server.SecureRequestCustomizer;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.server.SslConnectionFactory;
+import org.eclipse.jetty.server.handler.HandlerWrapper;
+import org.eclipse.jetty.server.handler.gzip.GzipHandler;
+import org.eclipse.jetty.servlet.FilterHolder;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlets.PushCacheFilter;
+import org.eclipse.jetty.util.log.Log;
+import org.eclipse.jetty.util.log.Logger;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
+
+public class Main {
+
+    private static final Logger LOG = Log.getLogger(Main.class);
+
+    public static void main(String[] args) throws Exception {
+        try (JettyStarter starter = new JettyStarter();) {
+            starter.start();
+            LOG.info("Press any key to stop Jetty.");
+            System.in.read();
+        }
+    }
+
+    public static class NoopServlet extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+            resp.setContentType("text/html;charset=UTF-8");
+            resp.getWriter().append("OK+");
+        }
+
+    }
+
+    private static class JettyStarter implements AutoCloseable {
+
+        private static final int SSL_PORT = 8443;
+        private final Server server;
+        private final HttpConfiguration config = createHttpConfiguration();
+
+        public JettyStarter() {
+            HttpConnectionFactory httpFactory = new HttpConnectionFactory(config);
+            HTTP2ServerConnectionFactory http2Factory = new HTTP2ServerConnectionFactory(
+                    config);
+            ALPNServerConnectionFactory alpn = createAlpnProtocolFactory(httpFactory);
+            Server server = createServer(httpFactory, http2Factory, alpn);
+
+            HandlerWrapper servletHandler = createServletHandlerWithServlet();
+            HandlerWrapper gzipHandler = createGzipHandler();
+            gzipHandler.setHandler(servletHandler);
+            server.setHandler(gzipHandler);
+
+            this.server = server;
+        }
+
+        private Server createServer(HttpConnectionFactory httpConnectionFactory,
+                HTTP2ServerConnectionFactory http2ConnectionFactory,
+                ALPNServerConnectionFactory alpn) {
+            Server server = new Server();
+            server.setRequestLog(new AsyncNCSARequestLog());
+
+            ServerConnector connector = new ServerConnector(server, prepareSsl(alpn),
+                    alpn, http2ConnectionFactory, httpConnectionFactory);
+            connector.setPort(SSL_PORT);
+            server.addConnector(connector);
+
+            return server;
+        }
+
+        private GzipHandler createGzipHandler() {
+            GzipHandler gzipHandler = new GzipHandler();
+            gzipHandler.setIncludedPaths("/*");
+            gzipHandler.setMinGzipSize(0);
+            gzipHandler.setIncludedMimeTypes("text/plain", "text/html");
+            return gzipHandler;
+        }
+
+        private ServletContextHandler createServletHandlerWithServlet() {
+            ServletContextHandler context = new ServletContextHandler(
+                    ServletContextHandler.SESSIONS);
+
+            FilterHolder pushCacheFilter = context.addFilter(PushCacheFilter.class, "/*",
+                    null);
+            Map<String, String> config = new HashMap<>();
+            config.put("maxAssociations", "32");
+            config.put("ports", Objects.toString(SSL_PORT));
+            pushCacheFilter.setInitParameters(config);
+
+            context.addServlet(NoopServlet.class, "/*");
+            context.setContextPath("/");
+
+            return context;
+        }
+
+        private ALPNServerConnectionFactory createAlpnProtocolFactory(
+                HttpConnectionFactory httpConnectionFactory) {
+            NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable();
+            ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
+            alpn.setDefaultProtocol(httpConnectionFactory.getProtocol());
+            return alpn;
+        }
+
+        private SslConnectionFactory prepareSsl(ALPNServerConnectionFactory alpn) {
+            SslContextFactory sslContextFactory = new SslContextFactory();
+            sslContextFactory.setKeyStorePath(
+                    Main.class.getResource("/keystore").toExternalForm());
+            sslContextFactory.setKeyStorePassword("changeit");
+            sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
+            sslContextFactory.setUseCipherSuitesOrder(true);
+            SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory,
+                    alpn.getProtocol());
+            return ssl;
+        }
+
+        private static HttpConfiguration createHttpConfiguration() {
+            HttpConfiguration config = new HttpConfiguration();
+            config.setSecureScheme("https");
+            config.setSecurePort(SSL_PORT);
+            config.setSendXPoweredBy(false);
+            config.setSendServerVersion(false);
+            config.addCustomizer(new SecureRequestCustomizer());
+            return config;
+        }
+
+        public void start() throws Exception {
+            server.start();
+        }
+
+        @Override
+        public void close() throws Exception {
+            server.stop();
+        }
+
+    }
+
+}
\ No newline at end of file


Mime
View raw message