Search in sources :

Example 46 with HttpClient

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();
}
Also used : HttpClient(org.eclipse.jetty.client.HttpClient) Before(org.junit.Before)

Example 47 with HttpClient

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());
}
Also used : HttpClient(org.eclipse.jetty.client.HttpClient) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 48 with HttpClient

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());
}
Also used : HttpClient(org.eclipse.jetty.client.HttpClient) BasicAuthentication(org.eclipse.jetty.client.util.BasicAuthentication) URI(java.net.URI) Test(org.junit.Test)

Example 49 with HttpClient

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());
}
Also used : HttpClient(org.eclipse.jetty.client.HttpClient) HttpCookie(java.net.HttpCookie) Test(org.junit.Test)

Example 50 with HttpClient

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());
}
Also used : HttpClient(org.eclipse.jetty.client.HttpClient) Test(org.junit.Test)

Aggregations

HttpClient (org.eclipse.jetty.client.HttpClient)197 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)102 Test (org.junit.Test)94 Request (org.eclipse.jetty.client.api.Request)53 HttpServletRequest (javax.servlet.http.HttpServletRequest)42 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)40 Test (org.testng.annotations.Test)34 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)24 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)19 CloudStore (com.yahoo.athenz.zts.store.CloudStore)17 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)16 HttpCertSigner (com.yahoo.athenz.zts.cert.impl.HttpCertSigner)14 HttpCertSignerFactory (com.yahoo.athenz.zts.cert.impl.HttpCertSignerFactory)14 URI (java.net.URI)11 HTTP2Client (org.eclipse.jetty.http2.client.HTTP2Client)11 ExecutionException (java.util.concurrent.ExecutionException)8 HttpProxy (org.eclipse.jetty.client.HttpProxy)8 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)8 IOException (java.io.IOException)7 CountDownLatch (java.util.concurrent.CountDownLatch)7