Search in sources :

Example 1 with StatsTraceContext

use of io.grpc.internal.StatsTraceContext in project grpc-java by grpc.

the class NettyServerHandler method onHeadersRead.

private void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers) throws Http2Exception {
    if (!teWarningLogged && !TE_TRAILERS.equals(headers.get(TE_HEADER))) {
        logger.warning(String.format("Expected header TE: %s, but %s is received. This means " + "some intermediate proxy may not support trailers", TE_TRAILERS, headers.get(TE_HEADER)));
        teWarningLogged = true;
    }
    try {
        // Verify that the Content-Type is correct in the request.
        verifyContentType(streamId, headers);
        String method = determineMethod(streamId, headers);
        // The Http2Stream object was put by AbstractHttp2ConnectionHandler before calling this
        // method.
        Http2Stream http2Stream = requireHttp2Stream(streamId);
        Metadata metadata = Utils.convertHeaders(headers);
        StatsTraceContext statsTraceCtx = checkNotNull(transportListener.methodDetermined(method, metadata), "statsTraceCtx");
        NettyServerStream.TransportState state = new NettyServerStream.TransportState(this, http2Stream, maxMessageSize, statsTraceCtx);
        String authority = getOrUpdateAuthority((AsciiString) headers.authority());
        NettyServerStream stream = new NettyServerStream(ctx.channel(), state, attributes, authority, statsTraceCtx);
        transportListener.streamCreated(stream, method, metadata);
        state.onStreamAllocated();
        http2Stream.setProperty(streamKey, state);
    } catch (Http2Exception e) {
        throw e;
    } catch (Throwable e) {
        logger.log(Level.WARNING, "Exception in onHeadersRead()", e);
        // Throw an exception that will get handled by onStreamError.
        throw newStreamException(streamId, e);
    }
}
Also used : Http2Exception(io.netty.handler.codec.http2.Http2Exception) StatsTraceContext(io.grpc.internal.StatsTraceContext) Metadata(io.grpc.Metadata) AsciiString(io.netty.util.AsciiString) Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Example 2 with StatsTraceContext

use of io.grpc.internal.StatsTraceContext in project grpc-java by grpc.

the class NettyServerStreamTest method createStream.

@Override
protected NettyServerStream createStream() {
    when(handler.getWriteQueue()).thenReturn(writeQueue);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            if (future.isDone()) {
                ((ChannelPromise) invocation.getArguments()[1]).setSuccess();
            }
            return null;
        }
    }).when(writeQueue).enqueue(any(QueuedCommand.class), any(ChannelPromise.class), anyBoolean());
    when(writeQueue.enqueue(any(QueuedCommand.class), anyBoolean())).thenReturn(future);
    StatsTraceContext statsTraceCtx = StatsTraceContext.NOOP;
    NettyServerStream.TransportState state = new NettyServerStream.TransportState(handler, http2Stream, DEFAULT_MAX_MESSAGE_SIZE, statsTraceCtx);
    NettyServerStream stream = new NettyServerStream(channel, state, Attributes.EMPTY, "test-authority", statsTraceCtx);
    stream.transportState().setListener(serverListener);
    state.onStreamAllocated();
    verify(serverListener, atLeastOnce()).onReady();
    verifyNoMoreInteractions(serverListener);
    return stream;
}
Also used : StatsTraceContext(io.grpc.internal.StatsTraceContext) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ChannelPromise(io.netty.channel.ChannelPromise) QueuedCommand(io.grpc.netty.WriteQueue.QueuedCommand)

Aggregations

StatsTraceContext (io.grpc.internal.StatsTraceContext)2 Metadata (io.grpc.Metadata)1 QueuedCommand (io.grpc.netty.WriteQueue.QueuedCommand)1 ChannelPromise (io.netty.channel.ChannelPromise)1 Http2Exception (io.netty.handler.codec.http2.Http2Exception)1 Http2Stream (io.netty.handler.codec.http2.Http2Stream)1 AsciiString (io.netty.util.AsciiString)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1