use of org.eclipse.jetty.client.api.Destination in project jetty.project by eclipse.
the class HttpClientTest method test_DestinationCount.
@Test
public void test_DestinationCount() throws Exception {
start(new EmptyServerHandler());
String host = "localhost";
int port = connector.getLocalPort();
client.GET(scheme + "://" + host + ":" + port);
List<Destination> destinations = client.getDestinations();
Assert.assertNotNull(destinations);
Assert.assertEquals(1, destinations.size());
Destination destination = destinations.get(0);
Assert.assertNotNull(destination);
Assert.assertEquals(scheme, destination.getScheme());
Assert.assertEquals(host, destination.getHost());
Assert.assertEquals(port, destination.getPort());
}
use of org.eclipse.jetty.client.api.Destination in project jetty.project by eclipse.
the class ForwardProxyTLSServerTest method testTwoConcurrentExchanges.
@Test
public void testTwoConcurrentExchanges() throws Exception {
startTLSServer(new ServerHandler());
startProxy();
final HttpClient httpClient = new HttpClient(newSslContextFactory());
httpClient.getProxyConfiguration().getProxies().add(newHttpProxy());
httpClient.start();
try {
final AtomicReference<Connection> connection = new AtomicReference<>();
final CountDownLatch connectionLatch = new CountDownLatch(1);
String content1 = "BODY";
ContentResponse response1 = httpClient.newRequest("localhost", serverConnector.getLocalPort()).scheme(HttpScheme.HTTPS.asString()).method(HttpMethod.GET).path("/echo?body=" + URLEncoder.encode(content1, "UTF-8")).onRequestCommit(request -> {
Destination destination = httpClient.getDestination(HttpScheme.HTTPS.asString(), "localhost", serverConnector.getLocalPort());
destination.newConnection(new Promise.Adapter<Connection>() {
@Override
public void succeeded(Connection result) {
connection.set(result);
connectionLatch.countDown();
}
});
}).timeout(5, TimeUnit.SECONDS).send();
Assert.assertEquals(HttpStatus.OK_200, response1.getStatus());
String content = response1.getContentAsString();
Assert.assertEquals(content1, content);
Assert.assertTrue(connectionLatch.await(5, TimeUnit.SECONDS));
String body2 = "body=" + content1;
org.eclipse.jetty.client.api.Request request2 = httpClient.newRequest("localhost", serverConnector.getLocalPort()).scheme(HttpScheme.HTTPS.asString()).method(HttpMethod.POST).path("/echo").header(HttpHeader.CONTENT_TYPE, MimeTypes.Type.FORM_ENCODED.asString()).header(HttpHeader.CONTENT_LENGTH, String.valueOf(body2.length())).content(new StringContentProvider(body2));
// Make sure the second connection can send the exchange via the tunnel
FutureResponseListener listener2 = new FutureResponseListener(request2);
connection.get().send(request2, listener2);
ContentResponse response2 = listener2.get(5, TimeUnit.SECONDS);
Assert.assertEquals(HttpStatus.OK_200, response2.getStatus());
String content2 = response2.getContentAsString();
Assert.assertEquals(content1, content2);
} finally {
httpClient.stop();
}
}
Aggregations