public static ProtocolNegotiator serverPlaintext ( ) { return new ProtocolNegotiator ( ) { @ Override public ChannelHandler newHandler ( final GrpcHttp2ConnectionHandler handler ) { class PlaintextHandler extends ChannelHandlerAdapter { @ Override public void handlerAdded ( ChannelHandlerContext ctx ) throws Exception { // Set sttributes before replace to be sure we pass it before accepting any requests. handler . handleProtocolNegotiationCompleted ( Attributes . newBuilder ( ) . set ( Grpc . TRANSPORT_ATTR_REMOTE_ADDR , ctx . channel ( ) . remoteAddress ( ) ) . set ( Grpc . TRANSPORT_ATTR_LOCAL_ADDR , ctx . channel ( ) . localAddress ( ) ) . build ( ) , /*securityInfo=*/ null ) ; // Just replace this handler with the gRPC handler. ctx . pipeline ( ) . replace ( this , null , handler ) ; } } return new PlaintextHandler ( ) ; } @ Override public void close ( ) { } @ Override public AsciiString scheme ( ) { return Utils . HTTP ; } } ; }
Create a server plaintext handler for gRPC .