use of org.eclipse.jetty.client.HttpClient in project jetty.project by eclipse.
the class WebSocketClientInitTest method testInit_HttpClient_SyntheticStart.
/**
* This is the backward compatibility mode of WebSocketClient.
* This is also the primary mode that JSR356 Standalone WebSocket Client is initialized.
*
* @throws Exception
* on test failure
*/
@Test
public void testInit_HttpClient_SyntheticStart() throws Exception {
HttpClient http = null;
WebSocketClient ws = new WebSocketClient();
ws.start();
try {
http = ws.getHttpClient();
assertThat("WebSocketClient started", ws.isStarted(), is(true));
assertThat("HttpClient started", http.isStarted(), is(true));
HttpClient httpBean = ws.getBean(HttpClient.class);
assertThat("HttpClient bean found in WebSocketClient", httpBean, is(http));
assertThat("HttpClient bean is managed", ws.isManaged(httpBean), is(true));
assertThat("WebSocketClient should not be found in HttpClient", http.getBean(WebSocketClient.class), nullValue());
} finally {
ws.stop();
}
assertThat("WebSocketClient stopped", ws.isStopped(), is(true));
assertThat("HttpClient stopped", http.isStopped(), is(true));
}
use of org.eclipse.jetty.client.HttpClient in project jetty.project by eclipse.
the class HttpReceiverOverHTTPTest method init.
@Before
public void init() throws Exception {
client = new HttpClient();
client.start();
destination = new HttpDestinationOverHTTP(client, new Origin("http", "localhost", 8080));
destination.start();
endPoint = new ByteArrayEndPoint();
connection = new HttpConnectionOverHTTP(endPoint, destination, new Promise.Adapter<>());
endPoint.setConnection(connection);
}
use of org.eclipse.jetty.client.HttpClient in project jetty.project by eclipse.
the class HttpSenderOverHTTPTest method init.
@Before
public void init() throws Exception {
client = new HttpClient();
client.start();
}
use of org.eclipse.jetty.client.HttpClient in project jetty.project by eclipse.
the class Usage method testGETAsync.
@Test
public void testGETAsync() throws Exception {
HttpClient client = new HttpClient();
client.start();
final AtomicReference<Response> responseRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
client.newRequest("localhost", 8080).send(new Response.CompleteListener() {
@Override
public void onComplete(Result result) {
if (result.isSucceeded()) {
responseRef.set(result.getResponse());
latch.countDown();
}
}
});
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
Response response = responseRef.get();
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
}
use of org.eclipse.jetty.client.HttpClient in project jetty.project by eclipse.
the class Usage method testBasicAuthentication.
@Test
public void testBasicAuthentication() throws Exception {
HttpClient client = new HttpClient();
client.start();
URI uri = URI.create("http://localhost:8080/secure");
// Setup Basic authentication credentials for TestRealm
client.getAuthenticationStore().addAuthentication(new BasicAuthentication(uri, "TestRealm", "username", "password"));
// One liner to send the request
ContentResponse response = client.newRequest(uri).timeout(5, TimeUnit.SECONDS).send();
Assert.assertEquals(200, response.getStatus());
}
Aggregations