Search in sources :

Example 21 with HttpClient

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

Example 22 with HttpClient

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

Example 23 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 24 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 25 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)

Aggregations

HttpClient (org.eclipse.jetty.client.HttpClient)135 Test (org.junit.Test)90 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)70 Request (org.eclipse.jetty.client.api.Request)44 HttpServletRequest (javax.servlet.http.HttpServletRequest)42 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)40 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)23 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)18 HTTP2Client (org.eclipse.jetty.http2.client.HTTP2Client)8 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)8 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)8 URI (java.net.URI)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 HttpProxy (org.eclipse.jetty.client.HttpProxy)7 Before (org.junit.Before)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)6 InputStream (java.io.InputStream)5 File (java.io.File)4 ContentExchange (org.eclipse.jetty.client.ContentExchange)4