support h2-15 and h2-14
This commit is contained in:
parent
593cb39059
commit
5b60e0c98d
|
@ -43,7 +43,7 @@ public abstract class AbstractHTTP2ServerConnectionFactory extends AbstractConne
|
||||||
|
|
||||||
public AbstractHTTP2ServerConnectionFactory()
|
public AbstractHTTP2ServerConnectionFactory()
|
||||||
{
|
{
|
||||||
super("h2-14");
|
super("h2-15","h2-14");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDispatchIO()
|
public boolean isDispatchIO()
|
||||||
|
|
|
@ -18,6 +18,10 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.server;
|
package org.eclipse.jetty.server;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.jetty.io.AbstractConnection;
|
import org.eclipse.jetty.io.AbstractConnection;
|
||||||
import org.eclipse.jetty.io.Connection;
|
import org.eclipse.jetty.io.Connection;
|
||||||
import org.eclipse.jetty.io.EndPoint;
|
import org.eclipse.jetty.io.EndPoint;
|
||||||
|
@ -28,11 +32,19 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||||
public abstract class AbstractConnectionFactory extends ContainerLifeCycle implements ConnectionFactory
|
public abstract class AbstractConnectionFactory extends ContainerLifeCycle implements ConnectionFactory
|
||||||
{
|
{
|
||||||
private final String _protocol;
|
private final String _protocol;
|
||||||
|
private final List<String> _protocols;
|
||||||
private int _inputbufferSize = 8192;
|
private int _inputbufferSize = 8192;
|
||||||
|
|
||||||
protected AbstractConnectionFactory(String protocol)
|
protected AbstractConnectionFactory(String protocol)
|
||||||
{
|
{
|
||||||
_protocol=protocol;
|
_protocol=protocol;
|
||||||
|
_protocols=Collections.unmodifiableList(Arrays.asList(new String[]{protocol}));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AbstractConnectionFactory(String... protocols)
|
||||||
|
{
|
||||||
|
_protocol=protocols[0];
|
||||||
|
_protocols=Collections.unmodifiableList(Arrays.asList(protocols));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -41,6 +53,12 @@ public abstract class AbstractConnectionFactory extends ContainerLifeCycle imple
|
||||||
return _protocol;
|
return _protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getProtocols()
|
||||||
|
{
|
||||||
|
return _protocols;
|
||||||
|
}
|
||||||
|
|
||||||
public int getInputBufferSize()
|
public int getInputBufferSize()
|
||||||
{
|
{
|
||||||
return _inputbufferSize;
|
return _inputbufferSize;
|
||||||
|
@ -67,7 +85,7 @@ public abstract class AbstractConnectionFactory extends ContainerLifeCycle imple
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return String.format("%s@%x{%s}",this.getClass().getSimpleName(),hashCode(),getProtocol());
|
return String.format("%s@%x%s",this.getClass().getSimpleName(),hashCode(),getProtocols());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConnectionFactory[] getFactories(SslContextFactory sslContextFactory, ConnectionFactory... factories)
|
public static ConnectionFactory[] getFactories(SslContextFactory sslContextFactory, ConnectionFactory... factories)
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -358,17 +359,33 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
|
||||||
{
|
{
|
||||||
synchronized (_factories)
|
synchronized (_factories)
|
||||||
{
|
{
|
||||||
String key=StringUtil.asciiToLowerCase(factory.getProtocol());
|
Set<ConnectionFactory> to_remove = new HashSet<ConnectionFactory>();
|
||||||
ConnectionFactory old=_factories.remove(key);
|
for (String key:factory.getProtocols())
|
||||||
if (old!=null)
|
{
|
||||||
|
key=StringUtil.asciiToLowerCase(key);
|
||||||
|
ConnectionFactory old=_factories.remove(key);
|
||||||
|
if (old!=null)
|
||||||
|
{
|
||||||
|
if (old.getProtocol().equals(_defaultProtocol))
|
||||||
|
_defaultProtocol=null;
|
||||||
|
to_remove.add(old);
|
||||||
|
}
|
||||||
|
_factories.put(key, factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
// keep factories still referenced
|
||||||
|
for (ConnectionFactory f : _factories.values())
|
||||||
|
to_remove.remove(f);
|
||||||
|
|
||||||
|
// remove old factories
|
||||||
|
for (ConnectionFactory old: to_remove)
|
||||||
{
|
{
|
||||||
if (old.getProtocol().equals(_defaultProtocol))
|
|
||||||
_defaultProtocol=null;
|
|
||||||
removeBean(old);
|
removeBean(old);
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
LOG.debug("{} removed {}", this, old);
|
LOG.debug("{} removed {}", this, old);
|
||||||
}
|
}
|
||||||
_factories.put(key, factory);
|
|
||||||
|
// add new Bean
|
||||||
addBean(factory);
|
addBean(factory);
|
||||||
if (_defaultProtocol==null)
|
if (_defaultProtocol==null)
|
||||||
_defaultProtocol=factory.getProtocol();
|
_defaultProtocol=factory.getProtocol();
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
package org.eclipse.jetty.server;
|
package org.eclipse.jetty.server;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.jetty.io.Connection;
|
import org.eclipse.jetty.io.Connection;
|
||||||
import org.eclipse.jetty.io.EndPoint;
|
import org.eclipse.jetty.io.EndPoint;
|
||||||
|
|
||||||
|
@ -42,9 +44,15 @@ public interface ConnectionFactory
|
||||||
{
|
{
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
* @return A string representing the protocol name.
|
* @return A string representing the primary protocol name.
|
||||||
*/
|
*/
|
||||||
public String getProtocol();
|
public String getProtocol();
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
/**
|
||||||
|
* @return A list of alternative protocol names/versions including the primary protocol.
|
||||||
|
*/
|
||||||
|
public List<String> getProtocols();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Creates a new {@link Connection} with the given parameters</p>
|
* <p>Creates a new {@link Connection} with the given parameters</p>
|
||||||
|
|
|
@ -52,21 +52,21 @@ public abstract class NegotiatingServerConnectionFactory extends AbstractConnect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final List<String> protocols;
|
private final List<String> negotiatedProtocols;
|
||||||
private String defaultProtocol;
|
private String defaultProtocol;
|
||||||
|
|
||||||
public NegotiatingServerConnectionFactory(String protocol, String... protocols)
|
public NegotiatingServerConnectionFactory(String protocol, String... negotiatedProtocols)
|
||||||
{
|
{
|
||||||
super(protocol);
|
super(protocol);
|
||||||
this.protocols = new ArrayList<>();
|
this.negotiatedProtocols = new ArrayList<>();
|
||||||
if (protocols != null)
|
if (negotiatedProtocols != null)
|
||||||
{
|
{
|
||||||
// Trim the values, as they may come from XML configuration.
|
// Trim the values, as they may come from XML configuration.
|
||||||
for (String p : protocols)
|
for (String p : negotiatedProtocols)
|
||||||
{
|
{
|
||||||
p = p.trim();
|
p = p.trim();
|
||||||
if (!p.isEmpty())
|
if (!p.isEmpty())
|
||||||
this.protocols.add(p.trim());
|
this.negotiatedProtocols.add(p.trim());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,34 +83,37 @@ public abstract class NegotiatingServerConnectionFactory extends AbstractConnect
|
||||||
this.defaultProtocol = dft.isEmpty() ? null : dft;
|
this.defaultProtocol = dft.isEmpty() ? null : dft;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getProtocols()
|
public List<String> getNegotiatedProtocols()
|
||||||
{
|
{
|
||||||
return protocols;
|
return negotiatedProtocols;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection newConnection(Connector connector, EndPoint endPoint)
|
public Connection newConnection(Connector connector, EndPoint endPoint)
|
||||||
{
|
{
|
||||||
List<String> protocols = this.protocols;
|
List<String> negotiated = this.negotiatedProtocols;
|
||||||
if (protocols.isEmpty())
|
if (negotiated.isEmpty())
|
||||||
{
|
{
|
||||||
protocols = connector.getProtocols();
|
// Generate list of protocols that we can negotiate
|
||||||
Iterator<String> i = protocols.iterator();
|
negotiated = new ArrayList<>(connector.getProtocols());
|
||||||
while (i.hasNext())
|
for (Iterator<String> i = negotiated.iterator();i.hasNext();)
|
||||||
{
|
{
|
||||||
String protocol = i.next();
|
String protocol = i.next();
|
||||||
if ("ssl".equalsIgnoreCase(protocol) ||
|
// exclude SSL and negotiating protocols
|
||||||
"alpn".equalsIgnoreCase(protocol) ||
|
ConnectionFactory f = connector.getConnectionFactory(protocol);
|
||||||
"npn".equalsIgnoreCase(protocol))
|
|
||||||
|
if ((f instanceof SslConnectionFactory) ||
|
||||||
|
(f instanceof NegotiatingServerConnectionFactory))
|
||||||
{
|
{
|
||||||
i.remove();
|
i.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if default protocol is not set, then it is the first protocol given
|
||||||
String dft = defaultProtocol;
|
String dft = defaultProtocol;
|
||||||
if (dft == null && !protocols.isEmpty())
|
if (dft == null && !negotiated.isEmpty())
|
||||||
dft = protocols.get(0);
|
dft = negotiated.get(0);
|
||||||
|
|
||||||
SSLEngine engine = null;
|
SSLEngine engine = null;
|
||||||
EndPoint ep = endPoint;
|
EndPoint ep = endPoint;
|
||||||
|
@ -123,7 +126,7 @@ public abstract class NegotiatingServerConnectionFactory extends AbstractConnect
|
||||||
ep = null;
|
ep = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return configure(newServerConnection(connector, endPoint, engine, protocols, dft), connector, endPoint);
|
return configure(newServerConnection(connector, endPoint, engine, negotiated, dft), connector, endPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract AbstractConnection newServerConnection(Connector connector, EndPoint endPoint, SSLEngine engine, List<String> protocols, String defaultProtocol);
|
protected abstract AbstractConnection newServerConnection(Connector connector, EndPoint endPoint, SSLEngine engine, List<String> protocols, String defaultProtocol);
|
||||||
|
@ -131,6 +134,6 @@ public abstract class NegotiatingServerConnectionFactory extends AbstractConnect
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return String.format("%s@%x{%s,%s,%s}", getClass().getSimpleName(), hashCode(), getProtocol(), getDefaultProtocol(), getProtocols());
|
return String.format("%s@%x{%s,%s,%s}", getClass().getSimpleName(), hashCode(), getProtocols(), getDefaultProtocol(), getNegotiatedProtocols());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue