View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.alpn.server;
20  
21  import java.util.List;
22  
23  import javax.net.ssl.SSLEngine;
24  
25  import org.eclipse.jetty.alpn.ALPN;
26  import org.eclipse.jetty.io.AbstractConnection;
27  import org.eclipse.jetty.io.EndPoint;
28  import org.eclipse.jetty.server.Connector;
29  import org.eclipse.jetty.server.NegotiatingServerConnectionFactory;
30  import org.eclipse.jetty.util.annotation.Name;
31  import org.eclipse.jetty.util.log.Log;
32  import org.eclipse.jetty.util.log.Logger;
33  
34  public class ALPNServerConnectionFactory extends NegotiatingServerConnectionFactory
35  {
36      private static final Logger LOG = Log.getLogger(ALPNServerConnectionFactory.class);
37  
38      public ALPNServerConnectionFactory(String protocols)
39      {
40          this(protocols.trim().split(",", 0));
41      }
42  
43      public ALPNServerConnectionFactory(@Name("protocols") String... protocols)
44      {
45          super("alpn", protocols);
46          try
47          {
48              ClassLoader alpnClassLoader = ALPN.class.getClassLoader();
49              if (alpnClassLoader != null)
50              {
51                  LOG.warn("ALPN must be in the boot classloader, not in: " + alpnClassLoader);
52                  throw new IllegalStateException("ALPN must be in the boot classloader");
53              }
54          }
55          catch (Throwable x)
56          {
57              LOG.warn("ALPN not available", x);
58              throw new IllegalStateException("ALPN not available", x);
59          }
60      }
61  
62      @Override
63      protected AbstractConnection newServerConnection(Connector connector, EndPoint endPoint, SSLEngine engine, List<String> protocols, String defaultProtocol)
64      {
65          return new ALPNServerConnection(connector, endPoint, engine, protocols, defaultProtocol);
66      }
67  }