jetty-9 - HTTP client: updated to work also with SSL.

This commit is contained in:
Simone Bordet 2012-09-14 00:31:52 +02:00
parent b264f20dc9
commit fb2ca29364
16 changed files with 289 additions and 147 deletions

View File

@ -102,12 +102,11 @@ public class HttpClient extends AggregateLifeCycle
private final List<Request.Listener> requestListeners = new CopyOnWriteArrayList<>();
private final CookieStore cookieStore = new HttpCookieStore();
private final AuthenticationStore authenticationStore = new HttpAuthenticationStore();
private final SslContextFactory sslContextFactory;
private volatile Executor executor;
private volatile ByteBufferPool byteBufferPool;
private volatile Scheduler scheduler;
private volatile SelectorManager selectorManager;
private volatile SslContextFactory sslContextFactory;
private volatile String agent = "Jetty/" + Jetty.VERSION;
private volatile boolean followRedirects = true;
private volatile int maxConnectionsPerAddress = 8;
@ -123,14 +122,10 @@ public class HttpClient extends AggregateLifeCycle
this(null);
}
public HttpClient(Executor executor)
public HttpClient(SslContextFactory sslContextFactory)
{
this.executor = executor;
}
public ByteBufferPool getByteBufferPool()
{
return byteBufferPool;
this.sslContextFactory = sslContextFactory;
addBean(sslContextFactory);
}
public SslContextFactory getSslContextFactory()
@ -201,34 +196,6 @@ public class HttpClient extends AggregateLifeCycle
return authenticationStore;
}
public long getIdleTimeout()
{
return idleTimeout;
}
public void setIdleTimeout(long idleTimeout)
{
this.idleTimeout = idleTimeout;
}
/**
* @return the address to bind socket channels to
* @see #setBindAddress(SocketAddress)
*/
public SocketAddress getBindAddress()
{
return bindAddress;
}
/**
* @param bindAddress the address to bind socket channels to
* @see #getBindAddress()
*/
public void setBindAddress(SocketAddress bindAddress)
{
this.bindAddress = bindAddress;
}
public Future<ContentResponse> GET(String uri)
{
return GET(URI.create(uri));
@ -296,26 +263,6 @@ public class HttpClient extends AggregateLifeCycle
return new ArrayList<Destination>(destinations.values());
}
public String getUserAgent()
{
return agent;
}
public void setUserAgent(String agent)
{
this.agent = agent;
}
public boolean isFollowRedirects()
{
return followRedirects;
}
public void setFollowRedirects(boolean follow)
{
this.followRedirects = follow;
}
public void send(Request request, Response.Listener listener)
{
String scheme = request.scheme().toLowerCase();
@ -330,61 +277,6 @@ public class HttpClient extends AggregateLifeCycle
provideDestination(scheme, host, port).send(request, listener);
}
public Executor getExecutor()
{
return executor;
}
public int getMaxConnectionsPerAddress()
{
return maxConnectionsPerAddress;
}
public void setMaxConnectionsPerAddress(int maxConnectionsPerAddress)
{
this.maxConnectionsPerAddress = maxConnectionsPerAddress;
}
public int getMaxQueueSizePerAddress()
{
return maxQueueSizePerAddress;
}
public void setMaxQueueSizePerAddress(int maxQueueSizePerAddress)
{
this.maxQueueSizePerAddress = maxQueueSizePerAddress;
}
public int getRequestBufferSize()
{
return requestBufferSize;
}
public void setRequestBufferSize(int requestBufferSize)
{
this.requestBufferSize = requestBufferSize;
}
public int getResponseBufferSize()
{
return responseBufferSize;
}
public void setResponseBufferSize(int responseBufferSize)
{
this.responseBufferSize = responseBufferSize;
}
public int getMaxRedirects()
{
return maxRedirects;
}
public void setMaxRedirects(int maxRedirects)
{
this.maxRedirects = maxRedirects;
}
protected void newConnection(HttpDestination destination, Callback<Connection> callback)
{
SocketChannel channel = null;
@ -454,6 +346,134 @@ public class HttpClient extends AggregateLifeCycle
return null;
}
public ByteBufferPool getByteBufferPool()
{
return byteBufferPool;
}
public void setByteBufferPool(ByteBufferPool byteBufferPool)
{
this.byteBufferPool = byteBufferPool;
}
public long getIdleTimeout()
{
return idleTimeout;
}
public void setIdleTimeout(long idleTimeout)
{
this.idleTimeout = idleTimeout;
}
/**
* @return the address to bind socket channels to
* @see #setBindAddress(SocketAddress)
*/
public SocketAddress getBindAddress()
{
return bindAddress;
}
/**
* @param bindAddress the address to bind socket channels to
* @see #getBindAddress()
*/
public void setBindAddress(SocketAddress bindAddress)
{
this.bindAddress = bindAddress;
}
public String getUserAgent()
{
return agent;
}
public void setUserAgent(String agent)
{
this.agent = agent;
}
public boolean isFollowRedirects()
{
return followRedirects;
}
public void setFollowRedirects(boolean follow)
{
this.followRedirects = follow;
}
public Executor getExecutor()
{
return executor;
}
public void setExecutor(Executor executor)
{
this.executor = executor;
}
public Scheduler getScheduler()
{
return scheduler;
}
public void setScheduler(Scheduler scheduler)
{
this.scheduler = scheduler;
}
public int getMaxConnectionsPerAddress()
{
return maxConnectionsPerAddress;
}
public void setMaxConnectionsPerAddress(int maxConnectionsPerAddress)
{
this.maxConnectionsPerAddress = maxConnectionsPerAddress;
}
public int getMaxQueueSizePerAddress()
{
return maxQueueSizePerAddress;
}
public void setMaxQueueSizePerAddress(int maxQueueSizePerAddress)
{
this.maxQueueSizePerAddress = maxQueueSizePerAddress;
}
public int getRequestBufferSize()
{
return requestBufferSize;
}
public void setRequestBufferSize(int requestBufferSize)
{
this.requestBufferSize = requestBufferSize;
}
public int getResponseBufferSize()
{
return responseBufferSize;
}
public void setResponseBufferSize(int responseBufferSize)
{
this.responseBufferSize = responseBufferSize;
}
public int getMaxRedirects()
{
return maxRedirects;
}
public void setMaxRedirects(int maxRedirects)
{
this.maxRedirects = maxRedirects;
}
protected class ClientSelectorManager extends SelectorManager
{
public ClientSelectorManager()
@ -490,7 +510,7 @@ public class HttpClient extends AggregateLifeCycle
else
{
SSLEngine engine = sslContextFactory.newSSLEngine(endPoint.getRemoteAddress());
engine.setUseClientMode(false);
engine.setUseClientMode(true);
SslConnection sslConnection = new SslConnection(getByteBufferPool(), getExecutor(), endPoint, engine);

View File

@ -200,8 +200,7 @@ public class HttpConnection extends AbstractConnection implements Connection
HttpExchange exchange = getExchange();
if (exchange != null)
exchange.receive();
else
throw new IllegalStateException();
// If there is no exchange, we just ignore because the selector may be woken up by a remote close
}
protected void receive()
@ -258,7 +257,9 @@ public class HttpConnection extends AbstractConnection implements Connection
@Override
public void close()
{
super.close();
getEndPoint().shutdownOutput();
LOG.debug("{} oshut", this);
getEndPoint().close();
LOG.debug("{} closed", this);
}

View File

@ -242,7 +242,6 @@ public class HttpSender
BufferUtil.clear(header);
BufferUtil.clear(chunk);
releaseBuffers();
connection.getEndPoint().shutdownOutput();
generator.abort();
failed = true;

View File

@ -18,18 +18,31 @@
package org.eclipse.jetty.client;
import java.util.Arrays;
import java.util.Collection;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.NetworkConnector;
import org.eclipse.jetty.server.SelectChannelConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.After;
import org.junit.Rule;
import org.junit.rules.TestWatchman;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.model.FrameworkMethod;
public class AbstractHttpClientServerTest
@RunWith(Parameterized.class)
public abstract class AbstractHttpClientServerTest
{
@Parameterized.Parameters
public static Collection<SslContextFactory[]> parameters()
{
return Arrays.asList(new SslContextFactory[]{null}, new SslContextFactory[]{new SslContextFactory()});
}
@Rule
public final TestWatchman testName = new TestWatchman()
{
@ -43,22 +56,39 @@ public class AbstractHttpClientServerTest
}
};
protected SslContextFactory sslContextFactory;
protected String scheme;
protected Server server;
protected HttpClient client;
protected NetworkConnector connector;
public AbstractHttpClientServerTest(SslContextFactory sslContextFactory)
{
this.sslContextFactory = sslContextFactory;
this.scheme = sslContextFactory == null ? "http" : "https";
}
public void start(Handler handler) throws Exception
{
if (sslContextFactory != null)
{
sslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setTrustStorePath("src/test/resources/truststore.jks");
sslContextFactory.setTrustStorePassword("storepwd");
}
if (server == null)
server = new Server();
connector = new SelectChannelConnector(server);
connector = new SelectChannelConnector(server, sslContextFactory);
server.addConnector(connector);
server.setHandler(handler);
server.start();
QueuedThreadPool executor = new QueuedThreadPool();
executor.setName(executor.getName() + "-client");
client = new HttpClient(executor);
client = new HttpClient(sslContextFactory);
client.setExecutor(executor);
client.start();
}

View File

@ -40,6 +40,7 @@ import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.Assert;
import org.junit.Test;
@ -47,6 +48,11 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest
{
private String realm = "TestRealm";
public HttpClientAuthenticationTest(SslContextFactory sslContextFactory)
{
super(sslContextFactory);
}
public void startBasic(Handler handler) throws Exception
{
start(new BasicAuthenticator(), handler);
@ -86,14 +92,14 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest
public void test_BasicAuthentication() throws Exception
{
startBasic(new EmptyServerHandler());
test_Authentication(new BasicAuthentication("http://localhost:" + connector.getLocalPort(), realm, "basic", "basic"));
test_Authentication(new BasicAuthentication(scheme + "://localhost:" + connector.getLocalPort(), realm, "basic", "basic"));
}
@Test
public void test_DigestAuthentication() throws Exception
{
startDigest(new EmptyServerHandler());
test_Authentication(new DigestAuthentication("http://localhost:" + connector.getLocalPort(), realm, "digest", "digest"));
test_Authentication(new DigestAuthentication(scheme + "://localhost:" + connector.getLocalPort(), realm, "digest", "digest"));
}
private void test_Authentication(Authentication authentication) throws Exception
@ -112,7 +118,7 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest
client.getRequestListeners().add(requestListener);
// Request without Authentication causes a 401
Request request = client.newRequest("localhost", connector.getLocalPort()).path("/test");
Request request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).path("/test");
ContentResponse response = request.send().get(5, TimeUnit.SECONDS);
Assert.assertNotNull(response);
Assert.assertEquals(401, response.status());

View File

@ -34,6 +34,7 @@ import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.toolchain.test.IO;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@ -42,8 +43,13 @@ import static org.junit.Assert.fail;
public class HttpClientRedirectTest extends AbstractHttpClientServerTest
{
public HttpClientRedirectTest(SslContextFactory sslContextFactory)
{
super(sslContextFactory);
}
@Before
public void init() throws Exception
public void prepare() throws Exception
{
start(new RedirectHandler());
}
@ -52,6 +58,7 @@ public class HttpClientRedirectTest extends AbstractHttpClientServerTest
public void test_303() throws Exception
{
Response response = client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.path("/303/localhost/done")
.send().get(5, TimeUnit.SECONDS);
Assert.assertNotNull(response);
@ -63,6 +70,7 @@ public class HttpClientRedirectTest extends AbstractHttpClientServerTest
public void test_303_302() throws Exception
{
Response response = client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.path("/303/localhost/302/localhost/done")
.send().get(5, TimeUnit.SECONDS);
Assert.assertNotNull(response);
@ -74,6 +82,7 @@ public class HttpClientRedirectTest extends AbstractHttpClientServerTest
public void test_303_302_OnDifferentDestinations() throws Exception
{
Response response = client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.path("/303/127.0.0.1/302/localhost/done")
.send().get(5, TimeUnit.SECONDS);
Assert.assertNotNull(response);
@ -85,6 +94,7 @@ public class HttpClientRedirectTest extends AbstractHttpClientServerTest
public void test_301() throws Exception
{
Response response = client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.method(HttpMethod.HEAD)
.path("/301/localhost/done")
.send().get(5, TimeUnit.SECONDS);
@ -99,6 +109,7 @@ public class HttpClientRedirectTest extends AbstractHttpClientServerTest
try
{
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.method(HttpMethod.POST)
.path("/301/localhost/done")
.send().get(5, TimeUnit.SECONDS);
@ -119,6 +130,7 @@ public class HttpClientRedirectTest extends AbstractHttpClientServerTest
{
byte[] data = new byte[]{0, 1, 2, 3, 4, 5, 6, 7};
ContentResponse response = client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.method(HttpMethod.POST)
.path("/307/localhost/done")
.content(new ByteBufferContentProvider(ByteBuffer.wrap(data)))
@ -137,6 +149,7 @@ public class HttpClientRedirectTest extends AbstractHttpClientServerTest
try
{
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.path("/303/localhost/302/localhost/done")
.send().get(5, TimeUnit.SECONDS);
fail();
@ -155,6 +168,7 @@ public class HttpClientRedirectTest extends AbstractHttpClientServerTest
public void test_303_WithConnectionClose_WithBigRequest() throws Exception
{
Response response = client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.path("/303/localhost/done?close=true")
.send().get(5, TimeUnit.SECONDS);
Assert.assertNotNull(response);

View File

@ -28,6 +28,7 @@ import java.util.concurrent.atomic.AtomicLong;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.Assert;
import org.junit.Test;
@ -35,6 +36,11 @@ import static java.nio.file.StandardOpenOption.CREATE;
public class HttpClientStreamTest extends AbstractHttpClientServerTest
{
public HttpClientStreamTest(SslContextFactory sslContextFactory)
{
super(sslContextFactory);
}
@Test
public void testFileUpload() throws Exception
{
@ -53,6 +59,7 @@ public class HttpClientStreamTest extends AbstractHttpClientServerTest
final AtomicLong requestTime = new AtomicLong();
ContentResponse response = client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.file(upload)
.listener(new Request.Listener.Empty()
{

View File

@ -25,9 +25,9 @@ import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
@ -47,6 +47,7 @@ import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.annotation.Slow;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.Assert;
import org.junit.Test;
@ -54,12 +55,16 @@ import static java.nio.file.StandardOpenOption.CREATE;
public class HttpClientTest extends AbstractHttpClientServerTest
{
public HttpClientTest(SslContextFactory sslContextFactory)
{
super(sslContextFactory);
}
@Test
public void testStoppingClosesConnections() throws Exception
{
start(new EmptyServerHandler());
String scheme = "http";
String host = "localhost";
int port = connector.getLocalPort();
String path = "/";
@ -93,7 +98,6 @@ public class HttpClientTest extends AbstractHttpClientServerTest
{
start(new EmptyServerHandler());
String scheme = "http";
String host = "localhost";
int port = connector.getLocalPort();
client.GET(scheme + "://" + host + ":" + port).get(5, TimeUnit.SECONDS);
@ -113,7 +117,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
{
start(new EmptyServerHandler());
Response response = client.GET("http://localhost:" + connector.getLocalPort()).get(5, TimeUnit.SECONDS);
Response response = client.GET(scheme + "://localhost:" + connector.getLocalPort()).get(555, TimeUnit.SECONDS);
Assert.assertNotNull(response);
Assert.assertEquals(200, response.status());
@ -133,7 +137,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
}
});
ContentResponse response = client.GET("http://localhost:" + connector.getLocalPort()).get(5, TimeUnit.SECONDS);
ContentResponse response = client.GET(scheme + "://localhost:" + connector.getLocalPort()).get(5, TimeUnit.SECONDS);
Assert.assertNotNull(response);
Assert.assertEquals(200, response.status());
@ -165,7 +169,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
String value1 = "\u20AC";
String paramValue1 = URLEncoder.encode(value1, "UTF-8");
String query = paramName1 + "=" + paramValue1 + "&" + paramName2;
ContentResponse response = client.GET("http://localhost:" + connector.getLocalPort() + "/?" + query).get(5, TimeUnit.SECONDS);
ContentResponse response = client.GET(scheme + "://localhost:" + connector.getLocalPort() + "/?" + query).get(5, TimeUnit.SECONDS);
Assert.assertNotNull(response);
Assert.assertEquals(200, response.status());
@ -201,7 +205,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
String paramValue12 = URLEncoder.encode(value12, "UTF-8");
String paramValue2 = URLEncoder.encode(value2, "UTF-8");
String query = paramName1 + "=" + paramValue11 + "&" + paramName1 + "=" + paramValue12 + "&" + paramName2 + "=" + paramValue2;
ContentResponse response = client.GET("http://localhost:" + connector.getLocalPort() + "/?" + query).get(5, TimeUnit.SECONDS);
ContentResponse response = client.GET(scheme + "://localhost:" + connector.getLocalPort() + "/?" + query).get(5, TimeUnit.SECONDS);
Assert.assertNotNull(response);
Assert.assertEquals(200, response.status());
@ -218,7 +222,8 @@ public class HttpClientTest extends AbstractHttpClientServerTest
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch successLatch = new CountDownLatch(2);
client.newRequest("http://localhost:" + connector.getLocalPort())
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.listener(new org.eclipse.jetty.client.api.Request.Listener.Empty()
{
@Override
@ -244,7 +249,8 @@ public class HttpClientTest extends AbstractHttpClientServerTest
}
});
client.newRequest("http://localhost:" + connector.getLocalPort())
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.listener(new org.eclipse.jetty.client.api.Request.Listener.Empty()
{
@Override
@ -277,7 +283,8 @@ public class HttpClientTest extends AbstractHttpClientServerTest
client.setIdleTimeout(idleTimeout);
final CountDownLatch latch = new CountDownLatch(3);
client.newRequest("http://localhost:" + connector.getLocalPort())
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.listener(new org.eclipse.jetty.client.api.Request.Listener.Empty()
{
@Override
@ -308,7 +315,8 @@ public class HttpClientTest extends AbstractHttpClientServerTest
}
});
client.newRequest("http://localhost:" + connector.getLocalPort())
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.send(new Response.Listener.Empty()
{
@Override
@ -344,6 +352,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
final AtomicLong requestTime = new AtomicLong();
final AtomicLong responseTime = new AtomicLong();
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.file(file)
.listener(new org.eclipse.jetty.client.api.Request.Listener.Empty()
{
@ -399,6 +408,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
final CountDownLatch latch = new CountDownLatch(1);
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
// The second ByteBuffer set to null will throw an exception
.content(new ContentProvider()
{
@ -411,7 +421,26 @@ public class HttpClientTest extends AbstractHttpClientServerTest
@Override
public Iterator<ByteBuffer> iterator()
{
return Arrays.asList(ByteBuffer.allocate(chunkSize), null).iterator();
return new Iterator<ByteBuffer>()
{
@Override
public boolean hasNext()
{
return true;
}
@Override
public ByteBuffer next()
{
throw new NoSuchElementException("explicitly_thrown_by_test");
}
@Override
public void remove()
{
throw new UnsupportedOperationException();
}
};
}
})
.send(new Response.Listener.Empty()
@ -435,12 +464,13 @@ public class HttpClientTest extends AbstractHttpClientServerTest
final String host = "localhost";
final int port = connector.getLocalPort();
client.newRequest(host, port)
.scheme(scheme)
.listener(new org.eclipse.jetty.client.api.Request.Listener.Empty()
{
@Override
public void onBegin(org.eclipse.jetty.client.api.Request request)
{
HttpDestination destination = (HttpDestination)client.getDestination("http", host, port);
HttpDestination destination = (HttpDestination)client.getDestination(scheme, host, port);
destination.getActiveConnections().peek().close();
}
})

View File

@ -34,17 +34,22 @@ import org.eclipse.jetty.client.api.Result;
import org.eclipse.jetty.client.util.ByteBufferContentProvider;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.Assert;
import org.junit.Test;
public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest
{
public HttpConnectionLifecycleTest(SslContextFactory sslContextFactory)
{
super(sslContextFactory);
}
@Test
public void test_SuccessfulRequest_ReturnsConnection() throws Exception
{
start(new EmptyServerHandler());
String scheme = "http";
String host = "localhost";
int port = connector.getLocalPort();
HttpDestination destination = (HttpDestination)client.getDestination(scheme, host, port);
@ -58,6 +63,7 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest
final CountDownLatch headersLatch = new CountDownLatch(1);
final CountDownLatch successLatch = new CountDownLatch(3);
client.newRequest(host, port)
.scheme(scheme)
.listener(new Request.Listener.Empty()
{
@Override
@ -102,7 +108,6 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest
{
start(new EmptyServerHandler());
String scheme = "http";
String host = "localhost";
int port = connector.getLocalPort();
HttpDestination destination = (HttpDestination)client.getDestination(scheme, host, port);
@ -115,7 +120,7 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest
final CountDownLatch headersLatch = new CountDownLatch(1);
final CountDownLatch failureLatch = new CountDownLatch(2);
client.newRequest(host, port).listener(new Request.Listener.Empty()
client.newRequest(host, port).scheme(scheme).listener(new Request.Listener.Empty()
{
@Override
public void onBegin(Request request)
@ -153,7 +158,6 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest
{
start(new EmptyServerHandler());
String scheme = "http";
String host = "localhost";
int port = connector.getLocalPort();
HttpDestination destination = (HttpDestination)client.getDestination(scheme, host, port);
@ -166,6 +170,7 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest
final CountDownLatch successLatch = new CountDownLatch(3);
client.newRequest(host, port)
.scheme(scheme)
.listener(new Request.Listener.Empty()
{
@Override
@ -211,7 +216,6 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest
{
start(new EmptyServerHandler());
String scheme = "http";
String host = "localhost";
int port = connector.getLocalPort();
HttpDestination destination = (HttpDestination)client.getDestination(scheme, host, port);
@ -226,6 +230,7 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest
final CountDownLatch failureLatch = new CountDownLatch(2);
client.newRequest(host, port)
.scheme(scheme)
.listener(new Request.Listener.Empty()
{
@Override
@ -263,7 +268,6 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest
}
});
String scheme = "http";
String host = "localhost";
int port = connector.getLocalPort();
HttpDestination destination = (HttpDestination)client.getDestination(scheme, host, port);
@ -276,6 +280,7 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest
final CountDownLatch latch = new CountDownLatch(1);
client.newRequest(host, port)
.scheme(scheme)
.send(new Response.Listener.Empty()
{
@Override
@ -307,7 +312,6 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest
}
});
String scheme = "http";
String host = "localhost";
int port = connector.getLocalPort();
HttpDestination destination = (HttpDestination)client.getDestination(scheme, host, port);
@ -320,6 +324,7 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest
final CountDownLatch latch = new CountDownLatch(1);
client.newRequest(host, port)
.scheme(scheme)
.content(new ByteBufferContentProvider(ByteBuffer.allocate(16 * 1024 * 1024)))
.send(new Response.Listener.Empty()
{

View File

@ -31,11 +31,17 @@ import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.http.HttpCookie;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.Assert;
import org.junit.Test;
public class HttpCookieTest extends AbstractHttpClientServerTest
{
public HttpCookieTest(SslContextFactory sslContextFactory)
{
super(sslContextFactory);
}
@Test
public void test_CookieIsStored() throws Exception
{
@ -51,7 +57,6 @@ public class HttpCookieTest extends AbstractHttpClientServerTest
}
});
String scheme = "http";
String host = "localhost";
int port = connector.getLocalPort();
String path = "/path";
@ -86,7 +91,6 @@ public class HttpCookieTest extends AbstractHttpClientServerTest
}
});
String scheme = "http";
String host = "localhost";
int port = connector.getLocalPort();
String path = "/path";

View File

@ -23,12 +23,18 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.client.api.Connection;
import org.eclipse.jetty.toolchain.test.annotation.Slow;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class HttpDestinationTest extends AbstractHttpClientServerTest
{
public HttpDestinationTest(SslContextFactory sslContextFactory)
{
super(sslContextFactory);
}
@Before
public void init() throws Exception
{

View File

@ -33,6 +33,7 @@ import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.util.ByteBufferContentProvider;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.Assert;
import org.junit.Test;
@ -41,6 +42,11 @@ import static org.junit.Assert.fail;
public class HttpRequestAbortTest extends AbstractHttpClientServerTest
{
public HttpRequestAbortTest(SslContextFactory sslContextFactory)
{
super(sslContextFactory);
}
@Test
public void testAbortOnQueued() throws Exception
{
@ -50,6 +56,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
try
{
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.listener(new Request.Listener.Empty()
{
@Override
@ -85,6 +92,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
try
{
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.listener(new Request.Listener.Empty()
{
@Override
@ -117,6 +125,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
start(new EmptyServerHandler());
ContentResponse response = client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.listener(new Request.Listener.Empty()
{
@Override
@ -158,6 +167,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
try
{
ContentResponse response = client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.listener(new Request.Listener.Empty()
{
@Override

View File

@ -36,11 +36,17 @@ import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.client.api.Result;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.Assert;
import org.junit.Test;
public class HttpResponseAbortTest extends AbstractHttpClientServerTest
{
public HttpResponseAbortTest(SslContextFactory sslContextFactory)
{
super(sslContextFactory);
}
@Test
public void testAbortOnBegin() throws Exception
{
@ -48,6 +54,7 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
final CountDownLatch latch = new CountDownLatch(1);
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.send(new Response.Listener.Empty()
{
@Override
@ -73,6 +80,7 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
final CountDownLatch latch = new CountDownLatch(1);
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.send(new Response.Listener.Empty()
{
@Override
@ -117,6 +125,7 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
final CountDownLatch latch = new CountDownLatch(1);
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.send(new Response.Listener.Empty()
{
@Override
@ -160,7 +169,7 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
}
});
Future<ContentResponse> future = client.newRequest("localhost", connector.getLocalPort()).send();
Future<ContentResponse> future = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).send();
ref.set(future);
latch.countDown();

View File

@ -1,2 +1,3 @@
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
#org.eclipse.jetty.LEVEL=DEBUG
org.eclipse.jetty.client.LEVEL=DEBUG

Binary file not shown.

Binary file not shown.