当前位置: 首页>>代码示例>>Java>>正文


Java ChannelOutboundHandlerAdapter类代码示例

本文整理汇总了Java中io.netty.channel.ChannelOutboundHandlerAdapter的典型用法代码示例。如果您正苦于以下问题:Java ChannelOutboundHandlerAdapter类的具体用法?Java ChannelOutboundHandlerAdapter怎么用?Java ChannelOutboundHandlerAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChannelOutboundHandlerAdapter类属于io.netty.channel包,在下文中一共展示了ChannelOutboundHandlerAdapter类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createRpcClientRTEDuringConnectionSetup

import io.netty.channel.ChannelOutboundHandlerAdapter; //导入依赖的package包/类
@Override
protected AsyncRpcClient createRpcClientRTEDuringConnectionSetup(Configuration conf) {
  setConf(conf);
  return new AsyncRpcClient(conf, new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
          ch.pipeline().addFirst(new ChannelOutboundHandlerAdapter() {
            @Override
            public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
                throws Exception {
              promise.setFailure(new RuntimeException("Injected fault"));
            }
          });
        }
      });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:17,代码来源:TestAsyncIPC.java

示例2: configureNewPipeline

import io.netty.channel.ChannelOutboundHandlerAdapter; //导入依赖的package包/类
@Override
public void configureNewPipeline(ChannelPipeline pipeline) {
    serverPipelineConfigurator.configureNewPipeline(pipeline);
    pipeline.addLast(SSE_ENCODER_HANDLER_NAME, SERVER_SENT_EVENT_ENCODER);
    pipeline.addLast(SSE_RESPONSE_HEADERS_COMPLETER, new ChannelOutboundHandlerAdapter() {
        @Override
        public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
            if (HttpServerResponse.class.isAssignableFrom(msg.getClass())) {
                @SuppressWarnings("rawtypes")
                HttpServerResponse rxResponse = (HttpServerResponse) msg;
                String contentTypeHeader = rxResponse.getHeaders().get(CONTENT_TYPE);
                if (null == contentTypeHeader) {
                    rxResponse.getHeaders().set(CONTENT_TYPE, "text/event-stream");
                }
            }
            super.write(ctx, msg, promise);
        }
    });
}
 
开发者ID:allenxwang,项目名称:RxNetty,代码行数:20,代码来源:SseOverHttpServerPipelineConfigurator.java

示例3: invalid_http_call_should_result_in_expected_400_error

import io.netty.channel.ChannelOutboundHandlerAdapter; //导入依赖的package包/类
@Test
public void invalid_http_call_should_result_in_expected_400_error() throws Exception {
    // given
    // Normal request, but fiddle with the first chunk as it's going out to remove the HTTP version and make it an
    //      invalid HTTP call.
    NettyHttpClientRequestBuilder request = request()
        .withMethod(HttpMethod.GET)
        .withUri(BasicEndpoint.MATCHING_PATH)
        .withPipelineAdjuster(
            p -> p.addFirst(new ChannelOutboundHandlerAdapter() {
                @Override
                public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
                    String msgAsString = ((ByteBuf)msg).toString(CharsetUtil.UTF_8);

                    if (msgAsString.contains("HTTP/1.1")) {
                        msg = Unpooled.copiedBuffer(msgAsString.replace("HTTP/1.1", ""), CharsetUtil.UTF_8);
                    }
                    super.write(ctx, msg, promise);
                }
            })
        );

    // when
    NettyHttpClientResponse response = request.execute(downstreamServerConfig.endpointsPort(), 3000);

    // then
    verifyErrorReceived(response.payload,
                        response.statusCode,
                        new ApiErrorWithMetadata(SampleCoreApiError.MALFORMED_REQUEST,
                                                 Pair.of("cause", "Invalid HTTP request"))
    );
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:33,代码来源:VerifyCornerCasesComponentTest.java


注:本文中的io.netty.channel.ChannelOutboundHandlerAdapter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。