Skip to content

Commit

Permalink
Issue #1350 - Dynamic selection of the transport to use based on ALPN…
Browse files Browse the repository at this point in the history
… on the client side.

Introduced `HttpClientTransportDynamic` to be able to switch transport dynamically.
Refactored other transports and HttpDestination, removing now unnecessary classes.

Introduced ProxyProtocolClientConnectionFactory and used it for testing.
Updated OSGi tests now that jetty-client depends on jetty-alpn-client.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Feb 13, 2019
1 parent b9797b0 commit cab0f2d
Show file tree
Hide file tree
Showing 59 changed files with 1,605 additions and 974 deletions.
Expand Up @@ -48,6 +48,6 @@ public void selected(String protocol)
if (protocol == null || !protocols.contains(protocol))
close();
else
completed();
completed(protocol);
}
}
Expand Up @@ -111,4 +111,12 @@ public Connection newConnection(EndPoint endPoint, Map<String, Object> context)
}
throw new IllegalStateException("No ALPNProcessor for " + engine);
}

public static class ALPN extends Info
{
public ALPN(Executor executor, ClientConnectionFactory factory, List<String> protocols)
{
super(List.of("alpn"), new ALPNClientConnectionFactory(executor, factory, protocols));
}
}
}

This file was deleted.

Expand Up @@ -78,7 +78,6 @@ private SslContextFactory newSslContextFactory()
sslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
sslContextFactory.setIncludeProtocols("TLSv1.2");
// The mandatory HTTP/2 cipher.
sslContextFactory.setIncludeCipherSuites("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256");
return sslContextFactory;
Expand Down
6 changes: 6 additions & 0 deletions jetty-client/pom.xml
Expand Up @@ -112,6 +112,12 @@
<artifactId>jetty-io</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-client</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jmx</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions jetty-client/src/main/java/module-info.java
Expand Up @@ -20,8 +20,10 @@
{
exports org.eclipse.jetty.client;
exports org.eclipse.jetty.client.api;
exports org.eclipse.jetty.client.dynamic;
exports org.eclipse.jetty.client.http;
exports org.eclipse.jetty.client.jmx to org.eclipse.jetty.jmx;
exports org.eclipse.jetty.client.proxy;
exports org.eclipse.jetty.client.util;

requires org.eclipse.jetty.http;
Expand All @@ -30,6 +32,8 @@

// Only required if using SPNEGO.
requires static java.security.jgss;
// Only required if using the dynamic transport.
requires static org.eclipse.jetty.alpn.client;
// Only required if using JMX.
requires static org.eclipse.jetty.jmx;
}
Expand Up @@ -119,14 +119,14 @@ protected void tryCreate(int maxPending)
if (LOG.isDebugEnabled())
LOG.debug("newConnection {}/{} connections {}/{} pending", total+1, maxConnections, pending+1, maxPending);

destination.newConnection(new Promise<Connection>()
destination.newConnection(new Promise<>()
{
@Override
public void succeeded(Connection connection)
{
if (LOG.isDebugEnabled())
LOG.debug("Connection {}/{} creation succeeded {}", total+1, maxConnections, connection);
connections.add(-1,0);
LOG.debug("Connection {}/{} creation succeeded {}", total + 1, maxConnections, connection);
connections.add(-1, 0);
onCreated(connection);
proceed();
}
Expand All @@ -135,8 +135,8 @@ public void succeeded(Connection connection)
public void failed(Throwable x)
{
if (LOG.isDebugEnabled())
LOG.debug("Connection " + (total+1) + "/" + maxConnections + " creation failed", x);
connections.add(-1,-1);
LOG.debug("Connection " + (total + 1) + "/" + maxConnections + " creation failed", x);
connections.add(-1, -1);
requester.failed(x);
}
});
Expand Down
Expand Up @@ -16,25 +16,17 @@
// ========================================================================
//

package org.eclipse.jetty.client.http;
package org.eclipse.jetty.client;

import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.HttpExchange;
import org.eclipse.jetty.client.Origin;
import org.eclipse.jetty.client.PoolingHttpDestination;
import org.eclipse.jetty.client.SendFailure;
import org.eclipse.jetty.client.api.Connection;

public class HttpDestinationOverHTTP extends PoolingHttpDestination
public class DuplexHttpDestination extends HttpDestination
{
public HttpDestinationOverHTTP(HttpClient client, Origin origin)
public DuplexHttpDestination(HttpClient client, Origin origin)
{
super(client, origin);
this(client, new Info(origin, null));
}

@Override
protected SendFailure send(Connection connection, HttpExchange exchange)
public DuplexHttpDestination(HttpClient client, Info info)
{
return ((HttpConnectionOverHTTP)connection).send(exchange);
super(client, info);
}
}

0 comments on commit cab0f2d

Please sign in to comment.