Search in sources :

Example 61 with Http2Exception

use of io.netty.handler.codec.http2.Http2Exception in project grpc-java by grpc.

the class AbstractNettyHandler method sendInitialConnectionWindow.

/**
 * Sends initial connection window to the remote endpoint if necessary.
 */
private void sendInitialConnectionWindow() throws Http2Exception {
    if (!initialWindowSent && ctx.channel().isActive()) {
        Http2Stream connectionStream = connection().connectionStream();
        int currentSize = connection().local().flowController().windowSize(connectionStream);
        int delta = initialConnectionWindow - currentSize;
        decoder().flowController().incrementWindowSize(connectionStream, delta);
        initialWindowSent = true;
        ctx.flush();
    }
}
Also used : Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Example 62 with Http2Exception

use of io.netty.handler.codec.http2.Http2Exception in project grpc-java by grpc.

the class Http2ControlFrameLimitEncoder method handleOutstandingControlFrames.

private ChannelPromise handleOutstandingControlFrames(ChannelHandlerContext ctx, ChannelPromise promise) {
    if (!limitReached) {
        if (outstandingControlFrames == maxOutstandingControlFrames) {
            // Let's try to flush once as we may be able to flush some of the control frames.
            ctx.flush();
        }
        if (outstandingControlFrames == maxOutstandingControlFrames) {
            limitReached = true;
            Http2Exception exception = Http2Exception.connectionError(Http2Error.ENHANCE_YOUR_CALM, "Maximum number %d of outstanding control frames reached", maxOutstandingControlFrames);
            logger.info("Maximum number {} of outstanding control frames reached. Closing channel {}", maxOutstandingControlFrames, ctx.channel(), exception);
            // First notify the Http2LifecycleManager and then close the connection.
            lifecycleManager.onError(ctx, true, exception);
            ctx.close();
        }
        outstandingControlFrames++;
        // once the promise was completed
        return promise.unvoid().addListener(outstandingControlFramesListener);
    }
    return promise;
}
Also used : Http2Exception(io.netty.handler.codec.http2.Http2Exception)

Example 63 with Http2Exception

use of io.netty.handler.codec.http2.Http2Exception in project grpc-java by grpc.

the class UtilsTest method testStatusFromThrowable.

@Test
public void testStatusFromThrowable() {
    Status s = Status.CANCELLED.withDescription("msg");
    assertSame(s, Utils.statusFromThrowable(new Exception(s.asException())));
    Throwable t;
    t = new ConnectTimeoutException("msg");
    assertStatusEquals(Status.UNAVAILABLE.withCause(t), Utils.statusFromThrowable(t));
    t = new UnresolvedAddressException();
    assertStatusEquals(Status.UNAVAILABLE.withCause(t), Utils.statusFromThrowable(t));
    t = new Http2Exception(Http2Error.INTERNAL_ERROR, "msg");
    assertStatusEquals(Status.INTERNAL.withCause(t), Utils.statusFromThrowable(t));
    t = new Exception("msg");
    assertStatusEquals(Status.UNKNOWN.withCause(t), Utils.statusFromThrowable(t));
}
Also used : Status(io.grpc.Status) Http2Exception(io.netty.handler.codec.http2.Http2Exception) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) Http2Exception(io.netty.handler.codec.http2.Http2Exception) ConnectTimeoutException(io.netty.channel.ConnectTimeoutException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) ConnectTimeoutException(io.netty.channel.ConnectTimeoutException) Test(org.junit.Test)

Example 64 with Http2Exception

use of io.netty.handler.codec.http2.Http2Exception in project grpc-java by grpc.

the class GrpcHttp2HeadersUtilsTest method decode_requestHeaders.

@Test
public void decode_requestHeaders() throws Http2Exception {
    Http2HeadersDecoder decoder = new GrpcHttp2ServerHeadersDecoder(DEFAULT_MAX_HEADER_LIST_SIZE);
    Http2HeadersEncoder encoder = new DefaultHttp2HeadersEncoder(NEVER_SENSITIVE);
    Http2Headers headers = new DefaultHttp2Headers(false);
    headers.add(of(":scheme"), of("https")).add(of(":method"), of("GET")).add(of(":path"), of("index.html")).add(of(":authority"), of("foo.grpc.io")).add(of("custom"), of("header"));
    encodedHeaders = Unpooled.buffer();
    encoder.encodeHeaders(1, /* randomly chosen */
    headers, encodedHeaders);
    Http2Headers decodedHeaders = decoder.decodeHeaders(3, /* randomly chosen */
    encodedHeaders);
    assertEquals(headers.get(of(":scheme")), decodedHeaders.scheme());
    assertEquals(headers.get(of(":method")), decodedHeaders.method());
    assertEquals(headers.get(of(":path")), decodedHeaders.path());
    assertEquals(headers.get(of(":authority")), decodedHeaders.authority());
    assertEquals(headers.get(of("custom")), decodedHeaders.get(of("custom")));
    assertEquals(headers.size(), decodedHeaders.size());
    String toString = decodedHeaders.toString();
    assertContainsKeyAndValue(toString, ":scheme", decodedHeaders.scheme());
    assertContainsKeyAndValue(toString, ":method", decodedHeaders.method());
    assertContainsKeyAndValue(toString, ":path", decodedHeaders.path());
    assertContainsKeyAndValue(toString, ":authority", decodedHeaders.authority());
    assertContainsKeyAndValue(toString, "custom", decodedHeaders.get(of("custom")));
}
Also used : DefaultHttp2HeadersEncoder(io.netty.handler.codec.http2.DefaultHttp2HeadersEncoder) Http2HeadersEncoder(io.netty.handler.codec.http2.Http2HeadersEncoder) Http2Headers(io.netty.handler.codec.http2.Http2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) GrpcHttp2ServerHeadersDecoder(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2ServerHeadersDecoder) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) AsciiString(io.netty.util.AsciiString) Http2HeadersDecoder(io.netty.handler.codec.http2.Http2HeadersDecoder) DefaultHttp2HeadersEncoder(io.netty.handler.codec.http2.DefaultHttp2HeadersEncoder) Test(org.junit.Test)

Example 65 with Http2Exception

use of io.netty.handler.codec.http2.Http2Exception in project grpc-java by grpc.

the class GrpcHttp2HeadersUtilsTest method decode_emptyHeaders.

@Test
public void decode_emptyHeaders() throws Http2Exception {
    Http2HeadersDecoder decoder = new GrpcHttp2ClientHeadersDecoder(8192);
    Http2HeadersEncoder encoder = new DefaultHttp2HeadersEncoder(NEVER_SENSITIVE);
    ByteBuf encodedHeaders = Unpooled.buffer();
    encoder.encodeHeaders(1, /* randomly chosen */
    new DefaultHttp2Headers(false), encodedHeaders);
    Http2Headers decodedHeaders = decoder.decodeHeaders(3, /* randomly chosen */
    encodedHeaders);
    assertEquals(0, decodedHeaders.size());
    assertThat(decodedHeaders.toString()).contains("[]");
}
Also used : DefaultHttp2HeadersEncoder(io.netty.handler.codec.http2.DefaultHttp2HeadersEncoder) Http2HeadersEncoder(io.netty.handler.codec.http2.Http2HeadersEncoder) Http2Headers(io.netty.handler.codec.http2.Http2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) GrpcHttp2ClientHeadersDecoder(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2ClientHeadersDecoder) Http2HeadersDecoder(io.netty.handler.codec.http2.Http2HeadersDecoder) DefaultHttp2HeadersEncoder(io.netty.handler.codec.http2.DefaultHttp2HeadersEncoder) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)109 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)100 ChannelFuture (io.netty.channel.ChannelFuture)92 Test (org.junit.Test)89 Http2Exception (io.netty.handler.codec.http2.Http2Exception)85 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)81 AtomicReference (java.util.concurrent.atomic.AtomicReference)78 ByteArrayOutputStream (java.io.ByteArrayOutputStream)76 Channel (io.netty.channel.Channel)75 ChannelPipeline (io.netty.channel.ChannelPipeline)75 ArrayList (java.util.ArrayList)75 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)75 ChannelInitializer (io.netty.channel.ChannelInitializer)74 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)74 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)74 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)74 Http2Headers (io.netty.handler.codec.http2.Http2Headers)74 ApplicationProtocolNames (io.netty.handler.ssl.ApplicationProtocolNames)74 ApplicationProtocolNegotiationHandler (io.netty.handler.ssl.ApplicationProtocolNegotiationHandler)74 SslHandler (io.netty.handler.ssl.SslHandler)74