Search in sources :

Example 1 with ByteArrayEndPoint

use of org.eclipse.jetty.io.ByteArrayEndPoint 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 2 with ByteArrayEndPoint

use of org.eclipse.jetty.io.ByteArrayEndPoint in project jetty.project by eclipse.

the class HttpSenderOverHTTPTest method test_Send_NoRequestContent_IncompleteFlush.

@Slow
@Test
public void test_Send_NoRequestContent_IncompleteFlush() throws Exception {
    ByteArrayEndPoint endPoint = new ByteArrayEndPoint("", 16);
    HttpDestinationOverHTTP destination = new HttpDestinationOverHTTP(client, new Origin("http", "localhost", 8080));
    destination.start();
    HttpConnectionOverHTTP connection = new HttpConnectionOverHTTP(endPoint, destination, new Promise.Adapter<Connection>());
    Request request = client.newRequest(URI.create("http://localhost/"));
    connection.send(request, null);
    // This take will free space in the buffer and allow for the write to complete
    StringBuilder builder = new StringBuilder(endPoint.takeOutputString());
    // Wait for the write to complete
    TimeUnit.SECONDS.sleep(1);
    String chunk = endPoint.takeOutputString();
    while (chunk.length() > 0) {
        builder.append(chunk);
        chunk = endPoint.takeOutputString();
    }
    String requestString = builder.toString();
    Assert.assertTrue(requestString.startsWith("GET "));
    Assert.assertTrue(requestString.endsWith("\r\n\r\n"));
}
Also used : Origin(org.eclipse.jetty.client.Origin) Promise(org.eclipse.jetty.util.Promise) Connection(org.eclipse.jetty.client.api.Connection) Request(org.eclipse.jetty.client.api.Request) ByteArrayEndPoint(org.eclipse.jetty.io.ByteArrayEndPoint) Test(org.junit.Test) Slow(org.eclipse.jetty.toolchain.test.annotation.Slow)

Example 3 with ByteArrayEndPoint

use of org.eclipse.jetty.io.ByteArrayEndPoint in project jetty.project by eclipse.

the class HttpSenderOverHTTPTest method test_Send_NoRequestContent_Exception.

@Test
public void test_Send_NoRequestContent_Exception() throws Exception {
    ByteArrayEndPoint endPoint = new ByteArrayEndPoint();
    // Shutdown output to trigger the exception on write
    endPoint.shutdownOutput();
    HttpDestinationOverHTTP destination = new HttpDestinationOverHTTP(client, new Origin("http", "localhost", 8080));
    destination.start();
    HttpConnectionOverHTTP connection = new HttpConnectionOverHTTP(endPoint, destination, new Promise.Adapter<Connection>());
    Request request = client.newRequest(URI.create("http://localhost/"));
    final CountDownLatch failureLatch = new CountDownLatch(2);
    request.listener(new Request.Listener.Adapter() {

        @Override
        public void onFailure(Request request, Throwable x) {
            failureLatch.countDown();
        }
    });
    connection.send(request, new Response.Listener.Adapter() {

        @Override
        public void onComplete(Result result) {
            Assert.assertTrue(result.isFailed());
            failureLatch.countDown();
        }
    });
    Assert.assertTrue(failureLatch.await(5, TimeUnit.SECONDS));
}
Also used : Origin(org.eclipse.jetty.client.Origin) Connection(org.eclipse.jetty.client.api.Connection) Request(org.eclipse.jetty.client.api.Request) ByteArrayEndPoint(org.eclipse.jetty.io.ByteArrayEndPoint) CountDownLatch(java.util.concurrent.CountDownLatch) Result(org.eclipse.jetty.client.api.Result) Promise(org.eclipse.jetty.util.Promise) Test(org.junit.Test)

Example 4 with ByteArrayEndPoint

use of org.eclipse.jetty.io.ByteArrayEndPoint in project jetty.project by eclipse.

the class ResponseTest method init.

@Before
public void init() throws Exception {
    _server = new Server();
    Scheduler _scheduler = new TimerScheduler();
    HttpConfiguration config = new HttpConfiguration();
    LocalConnector connector = new LocalConnector(_server, null, _scheduler, null, 1, new HttpConnectionFactory(config));
    _server.addConnector(connector);
    _server.setHandler(new DumpHandler());
    _server.start();
    AbstractEndPoint endp = new ByteArrayEndPoint(_scheduler, 5000) {

        @Override
        public InetSocketAddress getLocalAddress() {
            return LOCALADDRESS;
        }
    };
    _channel = new HttpChannel(connector, new HttpConfiguration(), endp, new HttpTransport() {

        private Throwable _channelError;

        @Override
        public void send(MetaData.Response info, boolean head, ByteBuffer content, boolean lastContent, Callback callback) {
            if (_channelError == null)
                callback.succeeded();
            else
                callback.failed(_channelError);
        }

        @Override
        public boolean isPushSupported() {
            return false;
        }

        @Override
        public void push(org.eclipse.jetty.http.MetaData.Request request) {
        }

        @Override
        public void onCompleted() {
        }

        @Override
        public void abort(Throwable failure) {
            _channelError = failure;
        }

        @Override
        public boolean isOptimizedForDirectBuffers() {
            return false;
        }
    });
}
Also used : TimerScheduler(org.eclipse.jetty.util.thread.TimerScheduler) AbstractEndPoint(org.eclipse.jetty.io.AbstractEndPoint) Scheduler(org.eclipse.jetty.util.thread.Scheduler) TimerScheduler(org.eclipse.jetty.util.thread.TimerScheduler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ByteArrayEndPoint(org.eclipse.jetty.io.ByteArrayEndPoint) ByteBuffer(java.nio.ByteBuffer) HttpServletResponse(javax.servlet.http.HttpServletResponse) Callback(org.eclipse.jetty.util.Callback) Before(org.junit.Before)

Example 5 with ByteArrayEndPoint

use of org.eclipse.jetty.io.ByteArrayEndPoint in project jetty.project by eclipse.

the class HttpSenderOverHTTPTest method test_Send_NoRequestContent.

@Test
public void test_Send_NoRequestContent() throws Exception {
    ByteArrayEndPoint endPoint = new ByteArrayEndPoint();
    HttpDestinationOverHTTP destination = new HttpDestinationOverHTTP(client, new Origin("http", "localhost", 8080));
    destination.start();
    HttpConnectionOverHTTP connection = new HttpConnectionOverHTTP(endPoint, destination, new Promise.Adapter<Connection>());
    Request request = client.newRequest(URI.create("http://localhost/"));
    final CountDownLatch headersLatch = new CountDownLatch(1);
    final CountDownLatch successLatch = new CountDownLatch(1);
    request.listener(new Request.Listener.Adapter() {

        @Override
        public void onHeaders(Request request) {
            headersLatch.countDown();
        }

        @Override
        public void onSuccess(Request request) {
            successLatch.countDown();
        }
    });
    connection.send(request, null);
    String requestString = endPoint.takeOutputString();
    Assert.assertTrue(requestString.startsWith("GET "));
    Assert.assertTrue(requestString.endsWith("\r\n\r\n"));
    Assert.assertTrue(headersLatch.await(5, TimeUnit.SECONDS));
    Assert.assertTrue(successLatch.await(5, TimeUnit.SECONDS));
}
Also used : Origin(org.eclipse.jetty.client.Origin) Connection(org.eclipse.jetty.client.api.Connection) Request(org.eclipse.jetty.client.api.Request) ByteArrayEndPoint(org.eclipse.jetty.io.ByteArrayEndPoint) CountDownLatch(java.util.concurrent.CountDownLatch) Promise(org.eclipse.jetty.util.Promise) Test(org.junit.Test)

Aggregations

ByteArrayEndPoint (org.eclipse.jetty.io.ByteArrayEndPoint)10 Origin (org.eclipse.jetty.client.Origin)8 Test (org.junit.Test)8 Connection (org.eclipse.jetty.client.api.Connection)7 Request (org.eclipse.jetty.client.api.Request)7 Promise (org.eclipse.jetty.util.Promise)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 ByteBufferContentProvider (org.eclipse.jetty.client.util.ByteBufferContentProvider)3 Result (org.eclipse.jetty.client.api.Result)2 Before (org.junit.Before)2 File (java.io.File)1 ByteBuffer (java.nio.ByteBuffer)1 SSLEngine (javax.net.ssl.SSLEngine)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpClient (org.eclipse.jetty.client.HttpClient)1 AbstractConnection (org.eclipse.jetty.io.AbstractConnection)1 AbstractEndPoint (org.eclipse.jetty.io.AbstractEndPoint)1 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)1