io.netty.handler.codec.http2.Http2Exception Java Examples

The following examples show how to use io.netty.handler.codec.http2.Http2Exception. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NettyServerHandler.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
private void onDataRead(int streamId, ByteBuf data, int padding, boolean endOfStream)
    throws Http2Exception {
  flowControlPing().onDataRead(data.readableBytes(), padding);
  try {
    NettyServerStream.TransportState stream = serverStream(requireHttp2Stream(streamId));
    PerfMark.startTask("NettyServerHandler.onDataRead", stream.tag());
    try {
      stream.inboundDataReceived(data, endOfStream);
    } finally {
      PerfMark.stopTask("NettyServerHandler.onDataRead", stream.tag());
    }
  } catch (Throwable e) {
    logger.log(Level.WARNING, "Exception in onDataRead()", e);
    // Throw an exception that will get handled by onStreamError.
    throw newStreamException(streamId, e);
  }
}
 
Example #2
Source File: NettyClientHandler.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
private void forcefulClose(final ChannelHandlerContext ctx, final ForcefulCloseCommand msg,
    ChannelPromise promise) throws Exception {
  // close() already called by NettyClientTransport, so just need to clean up streams
  connection().forEachActiveStream(new Http2StreamVisitor() {
    @Override
    public boolean visit(Http2Stream stream) throws Http2Exception {
      NettyClientStream.TransportState clientStream = clientStream(stream);
      if (clientStream != null) {
        clientStream.transportReportStatus(msg.getStatus(), true, new Metadata());
        resetStream(ctx, stream.id(), Http2Error.CANCEL.code(), ctx.newPromise());
      }
      stream.close();
      return true;
    }
  });
  promise.setSuccess();
}
 
Example #3
Source File: NettyClientHandler.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
/**
 * Handler for a GOAWAY being received. Fails any streams created after the
 * last known stream.
 */
private void goingAway(Status status) {
  lifecycleManager.notifyShutdown(status);
  final Status goAwayStatus = lifecycleManager.getShutdownStatus();
  final int lastKnownStream = connection().local().lastStreamKnownByPeer();
  try {
    connection().forEachActiveStream(new Http2StreamVisitor() {
      @Override
      public boolean visit(Http2Stream stream) throws Http2Exception {
        if (stream.id() > lastKnownStream) {
          NettyClientStream.TransportState clientStream = clientStream(stream);
          if (clientStream != null) {
            clientStream.transportReportStatus(
                goAwayStatus, RpcProgress.REFUSED, false, new Metadata());
          }
          stream.close();
        }
        return true;
      }
    });
  } catch (Http2Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example #4
Source File: NettyServerHandler.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Override
public void onPingAckRead(ChannelHandlerContext ctx, long data) throws Http2Exception {
  if (keepAliveManager != null) {
    keepAliveManager.onDataReceived();
  }
  if (data == flowControlPing().payload()) {
    flowControlPing().updateWindow();
    if (logger.isLoggable(Level.FINE)) {
      logger.log(Level.FINE, String.format("Window: %d",
          decoder().flowController().initialWindowSize(connection().connectionStream())));
    }
  } else if (data == GRACEFUL_SHUTDOWN_PING) {
    if (gracefulShutdown == null) {
      // this should never happen
      logger.warning("Received GRACEFUL_SHUTDOWN_PING Ack but gracefulShutdown is null");
    } else {
      gracefulShutdown.secondGoAwayAndClose(ctx);
    }
  } else if (data != KEEPALIVE_PING) {
    logger.warning("Received unexpected ping ack. No ping outstanding");
  }
}
 
Example #5
Source File: NettyClientHandler.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
private void forcefulClose(final ChannelHandlerContext ctx, final ForcefulCloseCommand msg,
    ChannelPromise promise) throws Exception {
  // close() already called by NettyClientTransport, so just need to clean up streams
  connection().forEachActiveStream(new Http2StreamVisitor() {
    @Override
    public boolean visit(Http2Stream stream) throws Http2Exception {
      NettyClientStream.TransportState clientStream = clientStream(stream);
      Tag tag = clientStream != null ? clientStream.tag() : PerfMark.createTag();
      PerfMark.startTask("NettyClientHandler.forcefulClose", tag);
      PerfMark.linkIn(msg.getLink());
      try {
        if (clientStream != null) {
          clientStream.transportReportStatus(msg.getStatus(), true, new Metadata());
          resetStream(ctx, stream.id(), Http2Error.CANCEL.code(), ctx.newPromise());
        }
        stream.close();
        return true;
      } finally {
        PerfMark.stopTask("NettyClientHandler.forcefulClose", tag);
      }
    }
  });
  promise.setSuccess();
}
 
Example #6
Source File: Http2ControlFrameLimitEncoder.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
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++;

        // We did not reach the limit yet, add the listener to decrement the number of outstanding control frames
        // once the promise was completed
        return promise.unvoid().addListener(outstandingControlFramesListener);
    }
    return promise;
}
 
Example #7
Source File: NettyServerHandler.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
private void onRstStreamRead(int streamId, long errorCode) throws Http2Exception {
  try {
    NettyServerStream.TransportState stream = serverStream(connection().stream(streamId));
    if (stream != null) {
      PerfMark.startTask("NettyServerHandler.onRstStreamRead", stream.tag());
      try {
        stream.transportReportStatus(
            Status.CANCELLED.withDescription("RST_STREAM received for code " + errorCode));
      } finally {
        PerfMark.stopTask("NettyServerHandler.onRstStreamRead", stream.tag());
      }
    }
  } catch (Throwable e) {
    logger.log(Level.WARNING, "Exception in onRstStreamRead()", e);
    // Throw an exception that will get handled by onStreamError.
    throw newStreamException(streamId, e);
  }
}
 
Example #8
Source File: NettyClientHandler.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Override
public void onPingAckRead(ChannelHandlerContext ctx, long ackPayload) throws Http2Exception {
  Http2Ping p = ping;
  if (ackPayload == flowControlPing().payload()) {
    flowControlPing().updateWindow();
    if (logger.isLoggable(Level.FINE)) {
      logger.log(Level.FINE, String.format("Window: %d",
          decoder().flowController().initialWindowSize(connection().connectionStream())));
    }
  } else if (p != null) {
    if (p.payload() == ackPayload) {
      p.complete();
      ping = null;
    } else {
      logger.log(Level.WARNING, String.format(
          "Received unexpected ping ack. Expecting %d, got %d", p.payload(), ackPayload));
    }
  } else {
    logger.warning("Received unexpected ping ack. No ping outstanding");
  }
  if (keepAliveManager != null) {
    keepAliveManager.onDataReceived();
  }
}
 
Example #9
Source File: Http2RequestDecoder.java    From armeria with Apache License 2.0 6 votes vote down vote up
private void writeErrorResponse(ChannelHandlerContext ctx, int streamId, HttpResponseStatus status,
                                @Nullable ByteBuf content) throws Http2Exception {
    final ByteBuf data =
            content != null ? content
                            : Unpooled.wrappedBuffer(status.toString().getBytes(StandardCharsets.UTF_8));

    writer.writeHeaders(
            ctx, streamId,
            new DefaultHttp2Headers(false)
                    .status(status.codeAsText())
                    .set(HttpHeaderNames.CONTENT_TYPE, MediaType.PLAIN_TEXT_UTF_8.toString())
                    .setInt(HttpHeaderNames.CONTENT_LENGTH, data.readableBytes()),
            0, false, ctx.voidPromise());

    writer.writeData(ctx, streamId, data, 0, true, ctx.voidPromise());

    final Http2Stream stream = writer.connection().stream(streamId);
    if (stream != null && writer.flowController().hasFlowControlled(stream)) {
        // Ensure to flush the error response if it's flow-controlled so that it is sent
        // before an RST_STREAM frame.
        writer.flowController().writePendingBytes();
    }
}
 
Example #10
Source File: NettyServerHandler.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
private void forcefulClose(final ChannelHandlerContext ctx, final ForcefulCloseCommand msg,
    ChannelPromise promise) throws Exception {
  super.close(ctx, promise);
  connection().forEachActiveStream(new Http2StreamVisitor() {
    @Override
    public boolean visit(Http2Stream stream) throws Http2Exception {
      NettyServerStream.TransportState serverStream = serverStream(stream);
      if (serverStream != null) {
        PerfMark.startTask("NettyServerHandler.forcefulClose", serverStream.tag());
        PerfMark.linkIn(msg.getLink());
        try {
          serverStream.transportReportStatus(msg.getStatus());
          resetStream(ctx, stream.id(), Http2Error.CANCEL.code(), ctx.newPromise());
        } finally {
          PerfMark.stopTask("NettyServerHandler.forcefulClose", serverStream.tag());
        }
      }
      stream.close();
      return true;
    }
  });
}
 
Example #11
Source File: ExceptionsTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Test
public void testIsExpected() {
    final boolean expected = !Flags.verboseSocketExceptions();

    assertThat(Exceptions.isExpected(new Exception())).isFalse();
    assertThat(Exceptions.isExpected(new Exception("broken pipe"))).isFalse();
    assertThat(Exceptions.isExpected(new Exception("connection reset by peer"))).isFalse();
    assertThat(Exceptions.isExpected(new Exception("stream closed"))).isFalse();
    assertThat(Exceptions.isExpected(new Exception("SSLEngine closed already"))).isFalse();

    assertThat(Exceptions.isExpected(new ClosedChannelException())).isEqualTo(expected);
    assertThat(Exceptions.isExpected(ClosedSessionException.get())).isEqualTo(expected);

    assertThat(Exceptions.isExpected(new IOException("connection reset by peer"))).isEqualTo(expected);
    assertThat(Exceptions.isExpected(new IOException("invalid argument"))).isEqualTo(false);

    assertThat(Exceptions.isExpected(new ChannelException("broken pipe"))).isEqualTo(expected);
    assertThat(Exceptions.isExpected(new ChannelException("invalid argument"))).isEqualTo(false);

    assertThat(Exceptions.isExpected(new Http2Exception(Http2Error.INTERNAL_ERROR, "stream closed")))
            .isEqualTo(expected);
    assertThat(Exceptions.isExpected(new Http2Exception(Http2Error.INTERNAL_ERROR))).isEqualTo(false);

    assertThat(Exceptions.isExpected(new SSLException("SSLEngine closed already"))).isEqualTo(expected);
    assertThat(Exceptions.isExpected(new SSLException("Handshake failed"))).isEqualTo(false);
}
 
Example #12
Source File: NettyServerHandler.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Override
public void onPingAckRead(ChannelHandlerContext ctx, long data) throws Http2Exception {
  if (keepAliveManager != null) {
    keepAliveManager.onDataReceived();
  }
  if (data == flowControlPing().payload()) {
    flowControlPing().updateWindow();
    if (logger.isLoggable(Level.FINE)) {
      logger.log(Level.FINE, String.format("Window: %d",
          decoder().flowController().initialWindowSize(connection().connectionStream())));
    }
  } else if (data == GRACEFUL_SHUTDOWN_PING) {
    if (gracefulShutdown == null) {
      // this should never happen
      logger.warning("Received GRACEFUL_SHUTDOWN_PING Ack but gracefulShutdown is null");
    } else {
      gracefulShutdown.secondGoAwayAndClose(ctx);
    }
  } else if (data != KEEPALIVE_PING) {
    logger.warning("Received unexpected ping ack. No ping outstanding");
  }
}
 
Example #13
Source File: Http2RequestDecoder.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) throws Http2Exception {
    keepAliveChannelRead();
    final DecodedHttpRequest req = requests.get(streamId);
    if (req == null) {
        throw connectionError(PROTOCOL_ERROR,
                              "received a RST_STREAM frame for an unknown stream: %d", streamId);
    }

    req.abortResponse(new ClosedStreamException(
            "received a RST_STREAM frame: " + Http2Error.valueOf(errorCode)));
}
 
Example #14
Source File: GrpcStatus.java    From armeria with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the {@link Throwable} to a {@link Status}, taking into account exceptions specific to Armeria as
 * well and the protocol package.
 */
public static Status fromThrowable(Throwable t) {
    t = unwrap(requireNonNull(t, "t"));

    final Status s = Status.fromThrowable(t);
    if (s.getCode() != Code.UNKNOWN) {
        return s;
    }

    if (t instanceof ClosedSessionException || t instanceof ClosedChannelException) {
        // ClosedChannelException is used any time the Netty channel is closed. Proper error
        // processing requires remembering the error that occurred before this one and using it
        // instead.
        return s;
    }
    if (t instanceof ClosedStreamException) {
        return Status.CANCELLED;
    }
    if (t instanceof UnprocessedRequestException || t instanceof IOException) {
        return Status.UNAVAILABLE.withCause(t);
    }
    if (t instanceof Http2Exception) {
        if (t instanceof Http2Exception.StreamException &&
            ((Http2Exception.StreamException) t).error() == Http2Error.CANCEL) {
            return Status.CANCELLED;
        }
        return Status.INTERNAL.withCause(t);
    }
    if (t instanceof TimeoutException) {
        return Status.DEADLINE_EXCEEDED.withCause(t);
    }
    if (t instanceof ContentTooLargeException) {
        return Status.RESOURCE_EXHAUSTED.withCause(t);
    }
    return s;
}
 
Example #15
Source File: Http2MetricsChannelHandlers.java    From zuul with Apache License 2.0 5 votes vote down vote up
protected static void incrementErrorCounter(Registry registry, String counterName, String metricId, Http2Exception h2e)
{
    String h2Error = h2e.error() != null ? h2e.error().name() : "NA";
    String exceptionName = h2e.getClass().getSimpleName();

    registry.counter(counterName,
                "id", metricId,
                "error", h2Error,
                "exception", exceptionName)
            .increment();
}
 
Example #16
Source File: NettyServerHandler.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public void onHeadersRead(ChannelHandlerContext ctx,
    int streamId,
    Http2Headers headers,
    int streamDependency,
    short weight,
    boolean exclusive,
    int padding,
    boolean endStream) throws Http2Exception {
  if (keepAliveManager != null) {
    keepAliveManager.onDataReceived();
  }
  NettyServerHandler.this.onHeadersRead(ctx, streamId, headers);
}
 
Example #17
Source File: HttpClientPipelineConfigurator.java    From armeria with Apache License 2.0 5 votes vote down vote up
private static void incrementLocalWindowSize(ChannelPipeline pipeline, int delta) {
    try {
        final Http2Connection connection = pipeline.get(Http2ClientConnectionHandler.class).connection();
        connection.local().flowController().incrementWindowSize(connection.connectionStream(), delta);
    } catch (Http2Exception e) {
        logger.warn("Failed to increment local flowController window size: {}", delta, e);
    }
}
 
Example #18
Source File: NettyClientHandler.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
protected void onConnectionError(ChannelHandlerContext ctx,  boolean outbound, Throwable cause,
    Http2Exception http2Ex) {
  logger.log(Level.FINE, "Caught a connection error", cause);
  lifecycleManager.notifyShutdown(Utils.statusFromThrowable(cause));
  // Parent class will shut down the Channel
  super.onConnectionError(ctx, outbound, cause, http2Ex);
}
 
Example #19
Source File: AbstractHttp2ConnectionHandler.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
protected void onConnectionError(ChannelHandlerContext ctx, boolean outbound,
                                 Throwable cause, Http2Exception http2Ex) {
    if (handlingConnectionError) {
        return;
    }

    handlingConnectionError = true;
    if (!Exceptions.isExpected(cause)) {
        logger.warn("{} HTTP/2 connection error:", ctx.channel(), cause);
    }
    super.onConnectionError(ctx, outbound, cause, filterHttp2Exception(cause, http2Ex));
}
 
Example #20
Source File: Exceptions.java    From armeria with Apache License 2.0 5 votes vote down vote up
/**
 * Returns {@code true} if the specified exception is expected to occur in well-known circumstances.
 * <ul>
 *   <li>{@link ClosedChannelException}</li>
 *   <li>{@link ClosedSessionException}</li>
 *   <li>{@link IOException} - 'Connection reset/closed/aborted by peer'</li>
 *   <li>'Broken pipe'</li>
 *   <li>{@link Http2Exception} - 'Stream closed'</li>
 *   <li>{@link SSLException} - 'SSLEngine closed already'</li>
 * </ul>
 *
 * @see Flags#verboseSocketExceptions()
 */
public static boolean isExpected(Throwable cause) {
    if (Flags.verboseSocketExceptions()) {
        return false;
    }

    // We do not need to log every exception because some exceptions are expected to occur.

    if (cause instanceof ClosedChannelException || cause instanceof ClosedSessionException) {
        // Can happen when attempting to write to a channel closed by the other end.
        return true;
    }

    final String msg = cause.getMessage();
    if (msg != null) {
        if ((cause instanceof IOException || cause instanceof ChannelException) &&
            IGNORABLE_SOCKET_ERROR_MESSAGE.matcher(msg).find()) {
            // Can happen when socket error occurs.
            return true;
        }

        if (cause instanceof Http2Exception && IGNORABLE_HTTP2_ERROR_MESSAGE.matcher(msg).find()) {
            // Can happen when disconnected prematurely.
            return true;
        }

        if (cause instanceof SSLException && IGNORABLE_TLS_ERROR_MESSAGE.matcher(msg).find()) {
            // Can happen when disconnected prematurely.
            return true;
        }
    }

    return false;
}
 
Example #21
Source File: Exceptions.java    From armeria with Apache License 2.0 5 votes vote down vote up
/**
 * Returns {@code true} if the specified exception will cancel the current request or response stream.
 */
public static boolean isStreamCancelling(Throwable cause) {
    if (cause instanceof UnprocessedRequestException) {
        cause = cause.getCause();
    }

    return cause instanceof ClosedStreamException ||
           cause instanceof CancelledSubscriptionException ||
           cause instanceof WriteTimeoutException ||
           cause instanceof AbortedStreamException ||
           (cause instanceof Http2Exception.StreamException &&
            ((Http2Exception.StreamException) cause).error() == Http2Error.CANCEL);
}
 
Example #22
Source File: Http2FrameForwarder.java    From xio with Apache License 2.0 5 votes vote down vote up
@Override
public void onHeadersRead(
    ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream)
    throws Http2Exception {
  if (isServer) {
    ctx.fireChannelRead(Http2Request.build(streamId, headers, endStream));
  } else {
    ctx.fireChannelRead(Http2Response.build(streamId, headers, endStream));
  }
}
 
Example #23
Source File: NettyClientHandler.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
protected void onStreamError(ChannelHandlerContext ctx, boolean outbound, Throwable cause,
    Http2Exception.StreamException http2Ex) {
  // Close the stream with a status that contains the cause.
  NettyClientStream.TransportState stream = clientStream(connection().stream(http2Ex.streamId()));
  if (stream != null) {
    stream.transportReportStatus(Utils.statusFromThrowable(cause), false, new Metadata());
  } else {
    logger.log(Level.FINE, "Stream error for unknown stream " + http2Ex.streamId(), cause);
  }

  // Delegate to the base class to send a RST_STREAM.
  super.onStreamError(ctx, outbound, cause, http2Ex);
}
 
Example #24
Source File: GrpcHttp2HeadersUtilsTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@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(), containsString("[]"));
}
 
Example #25
Source File: NettyServerHandler.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the given processed bytes back to inbound flow control.
 */
void returnProcessedBytes(Http2Stream http2Stream, int bytes) {
  try {
    decoder().flowController().consumeBytes(http2Stream, bytes);
  } catch (Http2Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example #26
Source File: HttpUpgradeHandler.java    From cute-proxy with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void upgradeHttp2(ChannelHandlerContext ctx, String method, String path) throws Http2Exception {
    logger.debug("upgrade to h2c");

    var http2Interceptor = new Http2Interceptor(address, messageListener, true, method, path);
    localPipeline.replace("http-codec", "http2-frame-codec", new Http2EventCodec());
    ctx.pipeline().replace("http-codec", "http2-frame-codec", new Http2EventCodec());
    ctx.pipeline().replace("http-interceptor", "http2-interceptor", http2Interceptor);
}
 
Example #27
Source File: NettyClientHandlerTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Override
protected NettyClientHandler newHandler() throws Http2Exception {
  Http2Connection connection = new DefaultHttp2Connection(false);

  // Create and close a stream previous to the nextStreamId.
  Http2Stream stream = connection.local().createStream(streamId - 2, true);
  stream.close();

  final Ticker ticker = new Ticker() {
    @Override
    public long read() {
      return nanoTime;
    }
  };
  Supplier<Stopwatch> stopwatchSupplier = new Supplier<Stopwatch>() {
    @Override
    public Stopwatch get() {
      return Stopwatch.createUnstarted(ticker);
    }
  };
  return NettyClientHandler.newHandler(
      connection,
      frameReader(),
      frameWriter(),
      lifecycleManager,
      mockKeepAliveManager,
      flowControlWindow,
      maxHeaderListSize,
      stopwatchSupplier,
      tooManyPingsRunnable,
      transportTracer,
      Attributes.EMPTY,
      "someauthority");
}
 
Example #28
Source File: Http2FrameForwarder.java    From xio with Apache License 2.0 5 votes vote down vote up
@Override
public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings)
    throws Http2Exception {
  // h2 clients need to know that server settings have been received before they can write
  if (!isServer) {
    ctx.fireUserEventTriggered(RequestBuffer.WriteReady.INSTANCE);
  }
}
 
Example #29
Source File: NettyClientHandler.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public void onHeadersRead(ChannelHandlerContext ctx,
    int streamId,
    Http2Headers headers,
    int streamDependency,
    short weight,
    boolean exclusive,
    int padding,
    boolean endStream) throws Http2Exception {
  NettyClientHandler.this.onHeadersRead(streamId, headers, endStream);
}
 
Example #30
Source File: Http2ToHttpInboundAdapter.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private void onHeadersRead(Http2HeadersFrame headersFrame, ChannelHandlerContext ctx) throws Http2Exception {

        HttpResponse httpResponse = HttpConversionUtil.toHttpResponse(headersFrame.stream().id(), headersFrame.headers(), true);
        ctx.fireChannelRead(httpResponse);

        if (HttpStatusFamily.of(httpResponse.status().code()) == HttpStatusFamily.SERVER_ERROR) {
            fireConnectionExceptionForServerError(ctx);
        }
    }