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());
}
use of org.eclipse.jetty.client.HttpClient in project jetty.project by eclipse.
the class Usage method testCookie.
@Test
public void testCookie() throws Exception {
HttpClient client = new HttpClient();
client.start();
// Set a cookie to be sent in requests that match the cookie's domain
client.getCookieStore().add(URI.create("http://host:8080/path"), new HttpCookie("name", "value"));
// Send a request for the cookie's domain
Response response = client.newRequest("host", 8080).send();
Assert.assertEquals(200, response.getStatus());
}
use of org.eclipse.jetty.client.HttpClient in project jetty.project by eclipse.
the class Usage method testRequestListener.
@Test
public void testRequestListener() throws Exception {
HttpClient client = new HttpClient();
client.start();
Response response = client.newRequest("localhost", 8080).listener(new Request.Listener.Adapter() {
@Override
public void onSuccess(Request request) {
}
}).send();
Assert.assertEquals(200, response.getStatus());
}
Aggregations