Search in sources :

Example 26 with ResetFrame

use of org.eclipse.jetty.http2.frames.ResetFrame in project jetty.project by eclipse.

the class HttpClientTransportOverHTTP2Test method testRequestAbortSendsResetFrame.

@Test
public void testRequestAbortSendsResetFrame() throws Exception {
    CountDownLatch resetLatch = new CountDownLatch(1);
    start(new ServerSessionListener.Adapter() {

        @Override
        public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
            return new Stream.Listener.Adapter() {

                @Override
                public void onReset(Stream stream, ResetFrame frame) {
                    resetLatch.countDown();
                }
            };
        }
    });
    try {
        client.newRequest("localhost", connector.getLocalPort()).onRequestCommit(request -> request.abort(new Exception("explicitly_aborted_by_test"))).send();
        Assert.fail();
    } catch (ExecutionException x) {
        Assert.assertTrue(resetLatch.await(5, TimeUnit.SECONDS));
    }
}
Also used : Request(org.eclipse.jetty.server.Request) ServletException(javax.servlet.ServletException) HTTP2Client(org.eclipse.jetty.http2.client.HTTP2Client) ByteBuffer(java.nio.ByteBuffer) Stream(org.eclipse.jetty.http2.api.Stream) ServerSocket(java.net.ServerSocket) HttpClient(org.eclipse.jetty.client.HttpClient) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MetaData(org.eclipse.jetty.http.MetaData) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) Map(java.util.Map) HttpProxy(org.eclipse.jetty.client.HttpProxy) HttpStatus(org.eclipse.jetty.http.HttpStatus) ResetFrame(org.eclipse.jetty.http2.frames.ResetFrame) Callback(org.eclipse.jetty.util.Callback) HttpDestination(org.eclipse.jetty.client.HttpDestination) DataFrame(org.eclipse.jetty.http2.frames.DataFrame) HTTP2Session(org.eclipse.jetty.http2.HTTP2Session) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Session(org.eclipse.jetty.http2.api.Session) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) BufferUtil(org.eclipse.jetty.util.BufferUtil) Socket(java.net.Socket) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HttpVersion(org.eclipse.jetty.http.HttpVersion) ErrorCode(org.eclipse.jetty.http2.ErrorCode) SettingsFrame(org.eclipse.jetty.http2.frames.SettingsFrame) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServerSessionListener(org.eclipse.jetty.http2.api.server.ServerSessionListener) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SocketTimeoutException(java.net.SocketTimeoutException) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) HttpFields(org.eclipse.jetty.http.HttpFields) OutputStream(java.io.OutputStream) GoAwayFrame(org.eclipse.jetty.http2.frames.GoAwayFrame) Executor(java.util.concurrent.Executor) RawHTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.RawHTTP2ServerConnectionFactory) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Test(org.junit.Test) ServerParser(org.eclipse.jetty.http2.parser.ServerParser) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Generator(org.eclipse.jetty.http2.generator.Generator) HttpMethod(org.eclipse.jetty.http.HttpMethod) Ignore(org.junit.Ignore) Assert(org.junit.Assert) InputStream(java.io.InputStream) ServerSessionListener(org.eclipse.jetty.http2.api.server.ServerSessionListener) Stream(org.eclipse.jetty.http2.api.Stream) OutputStream(java.io.OutputStream) InputStream(java.io.InputStream) ResetFrame(org.eclipse.jetty.http2.frames.ResetFrame) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) ServerSessionListener(org.eclipse.jetty.http2.api.server.ServerSessionListener) ServletException(javax.servlet.ServletException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 27 with ResetFrame

use of org.eclipse.jetty.http2.frames.ResetFrame in project jetty.project by eclipse.

the class HttpClientTransportOverHTTP2Test method testConnectionIdleTimeoutSendsResetFrame.

@Test
public void testConnectionIdleTimeoutSendsResetFrame() throws Exception {
    long idleTimeout = 1000;
    CountDownLatch resetLatch = new CountDownLatch(1);
    start(new ServerSessionListener.Adapter() {

        @Override
        public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
            return new Stream.Listener.Adapter() {

                @Override
                public void onReset(Stream stream, ResetFrame frame) {
                    resetLatch.countDown();
                }
            };
        }
    });
    client.stop();
    client.setIdleTimeout(idleTimeout);
    client.start();
    try {
        client.newRequest("localhost", connector.getLocalPort()).idleTimeout(2 * idleTimeout, TimeUnit.MILLISECONDS).send();
        Assert.fail();
    } catch (ExecutionException e) {
    // Expected.
    }
    Assert.assertTrue(resetLatch.await(5, TimeUnit.SECONDS));
}
Also used : ServerSessionListener(org.eclipse.jetty.http2.api.server.ServerSessionListener) Stream(org.eclipse.jetty.http2.api.Stream) OutputStream(java.io.OutputStream) InputStream(java.io.InputStream) ResetFrame(org.eclipse.jetty.http2.frames.ResetFrame) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) ServerSessionListener(org.eclipse.jetty.http2.api.server.ServerSessionListener) Test(org.junit.Test)

Aggregations

ResetFrame (org.eclipse.jetty.http2.frames.ResetFrame)24 Test (org.junit.Test)21 Stream (org.eclipse.jetty.http2.api.Stream)20 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)20 CountDownLatch (java.util.concurrent.CountDownLatch)19 MetaData (org.eclipse.jetty.http.MetaData)19 HttpFields (org.eclipse.jetty.http.HttpFields)18 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)18 Session (org.eclipse.jetty.http2.api.Session)16 Callback (org.eclipse.jetty.util.Callback)13 FuturePromise (org.eclipse.jetty.util.FuturePromise)12 DataFrame (org.eclipse.jetty.http2.frames.DataFrame)11 IOException (java.io.IOException)10 HttpServletResponse (javax.servlet.http.HttpServletResponse)10 ByteBuffer (java.nio.ByteBuffer)9 ServletOutputStream (javax.servlet.ServletOutputStream)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 ISession (org.eclipse.jetty.http2.ISession)9 ServletException (javax.servlet.ServletException)8 WriteListener (javax.servlet.WriteListener)8