當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。