change the format of detector's generated protocol name

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2020-02-04 10:50:24 +01:00
parent 58b1db610c
commit 5df1ad9b66
6 changed files with 20 additions and 13 deletions

View File

@ -89,12 +89,17 @@ public abstract class AbstractConnectionFactory extends ContainerLifeCycle imple
}
protected String findNextProtocol(Connector connector)
{
return findNextProtocol(connector, getProtocol());
}
protected static String findNextProtocol(Connector connector, String currentProtocol)
{
String nextProtocol = null;
for (Iterator<String> it = connector.getProtocols().iterator(); it.hasNext(); )
{
String protocol = it.next();
if (getProtocol().equalsIgnoreCase(protocol))
if (currentProtocol.equalsIgnoreCase(protocol))
{
nextProtocol = it.hasNext() ? it.next() : null;
break;

View File

@ -36,6 +36,7 @@ import java.util.concurrent.Executor;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.stream.Collectors;
import org.eclipse.jetty.io.ArrayByteBufferPool;
import org.eclipse.jetty.io.ByteBufferPool;
@ -776,9 +777,9 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
@Override
public String toString()
{
return String.format("%s@%x{%s,%s}",
return String.format("%s@%x{%s, %s}",
_name == null ? getClass().getSimpleName() : _name,
hashCode(),
getDefaultProtocol(), getProtocols());
getDefaultProtocol(), getProtocols().stream().collect(Collectors.joining(", ", "(", ")")));
}
}

View File

@ -64,7 +64,7 @@ public class DetectorConnectionFactory extends AbstractConnectionFactory impleme
// remove protocol duplicates while keeping their ordering -> use LinkedHashSet
LinkedHashSet<String> protocols = Arrays.stream(detectingConnectionFactories).map(ConnectionFactory::getProtocol).collect(Collectors.toCollection(LinkedHashSet::new));
String protocol = String.join("|", protocols);
String protocol = protocols.stream().collect(Collectors.joining("|", "[", "]"));
if (LOG.isDebugEnabled())
LOG.debug("Detector generated protocol name : {}", protocol);
return protocol;

View File

@ -60,15 +60,16 @@ public class ProxyConnectionFactory extends DetectorConnectionFactory
super(new ProxyV1ConnectionFactory(nextProtocol), new ProxyV2ConnectionFactory(nextProtocol));
}
private static ConnectionFactory findNextConnectionFactory(String nextProtocol, Connector connector, AbstractConnectionFactory currentConnectionFactory, EndPoint endp)
private static ConnectionFactory findNextConnectionFactory(String nextProtocol, Connector connector, String currentProtocol, EndPoint endp)
{
currentProtocol = "[" + currentProtocol + "]";
if (LOG.isDebugEnabled())
LOG.debug("finding next connection factory for protocol {}", nextProtocol);
LOG.debug("finding connection factory following {} for protocol {}", currentProtocol, nextProtocol);
String nextProtocolToFind = nextProtocol;
if (nextProtocol == null)
nextProtocolToFind = currentConnectionFactory.findNextProtocol(connector);
nextProtocolToFind = AbstractConnectionFactory.findNextProtocol(connector, currentProtocol);
if (nextProtocolToFind == null)
throw new IllegalStateException("Cannot find protocol following '" + currentConnectionFactory.getProtocol() + "' in connector's protocol list " + connector.getProtocols() + " for " + endp);
throw new IllegalStateException("Cannot find protocol following '" + currentProtocol + "' in connector's protocol list " + connector.getProtocols() + " for " + endp);
ConnectionFactory connectionFactory = connector.getConnectionFactory(nextProtocolToFind);
if (connectionFactory == null)
throw new IllegalStateException("Cannot find protocol '" + nextProtocol + "' in connector's protocol list " + connector.getProtocols() + " for " + endp);
@ -133,7 +134,7 @@ public class ProxyConnectionFactory extends DetectorConnectionFactory
@Override
public Connection newConnection(Connector connector, EndPoint endp)
{
ConnectionFactory nextConnectionFactory = findNextConnectionFactory(_nextProtocol, connector, this, endp);
ConnectionFactory nextConnectionFactory = findNextConnectionFactory(_nextProtocol, connector, getProtocol(), endp);
return configure(new ProxyProtocolV1Connection(endp, connector, nextConnectionFactory), connector, endp);
}
@ -414,7 +415,7 @@ public class ProxyConnectionFactory extends DetectorConnectionFactory
@Override
public Connection newConnection(Connector connector, EndPoint endp)
{
ConnectionFactory nextConnectionFactory = findNextConnectionFactory(_nextProtocol, connector, this, endp);
ConnectionFactory nextConnectionFactory = findNextConnectionFactory(_nextProtocol, connector, getProtocol(), endp);
return configure(new ProxyProtocolV2Connection(endp, connector, nextConnectionFactory), connector, endp);
}

View File

@ -630,8 +630,8 @@ public class DetectorConnectionTest
ProxyConnectionFactory proxy = new ProxyConnectionFactory(HttpVersion.HTTP_1_1.asString());
SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString());
assertEquals("SSL|proxy", new DetectorConnectionFactory(ssl, proxy).getProtocol());
assertEquals("proxy|SSL", new DetectorConnectionFactory(proxy, ssl).getProtocol());
assertEquals("[SSL|[proxy]]", new DetectorConnectionFactory(ssl, proxy).getProtocol());
assertEquals("[[proxy]|SSL]", new DetectorConnectionFactory(proxy, ssl).getProtocol());
}
@Test

View File

@ -247,7 +247,7 @@ public class ProxyConnectionTest
{
p.customize((connector) ->
{
ProxyConnectionFactory factory = (ProxyConnectionFactory)connector.getConnectionFactory("proxy");
ProxyConnectionFactory factory = (ProxyConnectionFactory)connector.getConnectionFactory("[proxy]");
factory.setMaxProxyHeader(11); // just one byte short
});
String proxy =