io.netty.handler.codec.http.HttpClientCodec Java Examples

The following examples show how to use io.netty.handler.codec.http.HttpClientCodec. 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: BackPoolHandler.java    From api-gateway-core with Apache License 2.0 6 votes vote down vote up
@Override
    public void channelCreated(Channel ch) throws Exception {
        logger.debug("channelCreated. Channel ID: {}", ch.id());
        NioSocketChannel channel = (NioSocketChannel) ch;
        channel.config().setKeepAlive(true);
        channel.config().setTcpNoDelay(true);
        ChannelPipeline pipeline = channel.pipeline();
        if (sslCtx != null) {
            pipeline.addLast(sslCtx.newHandler(ch.alloc()));
        }
        pipeline.addLast(new HttpClientCodec());
        pipeline.addLast(new HttpContentDecompressor());
        pipeline.addLast(new HttpObjectAggregator(1024 * 1024 * 64));
        pipeline.addLast(new ChunkedWriteHandler());
//        pipeline.addLast(new ReadTimeoutHandler(requestHolder.route.getTimeoutInMilliseconds(), TimeUnit.MILLISECONDS));
        pipeline.addLast(new BackHandler());
    }
 
Example #2
Source File: HttpSnoopClientInitializer.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();

    // Enable HTTPS if necessary.
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }

    p.addLast(new HttpClientCodec());

    // Remove the following line if you don't want automatic content decompression.
    p.addLast(new HttpContentDecompressor());

    // Uncomment the following line if you don't want to handle HttpContents.
    //p.addLast(new HttpObjectAggregator(1048576));

    p.addLast(new HttpSnoopClientHandler());
}
 
Example #3
Source File: AppWebSocketClient.java    From blynk-server with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ChannelInitializer<SocketChannel> getChannelInitializer() {
    return new ChannelInitializer<SocketChannel> () {
        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(
                    sslCtx.newHandler(ch.alloc(), host, port),
                    new HttpClientCodec(),
                    new HttpObjectAggregator(8192),
                    appHandler,
                    new WSMessageDecoder(new GlobalStats(),
                            new Limits(new ServerProperties(Collections.emptyMap()))
                    )
            );
        }
    };
}
 
Example #4
Source File: HttpUploadClientInitializer.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

    if (sslCtx != null) {
        pipeline.addLast("ssl", sslCtx.newHandler(ch.alloc()));
    }

    pipeline.addLast("codec", new HttpClientCodec());

    // Remove the following line if you don't want automatic content decompression.
    pipeline.addLast("inflater", new HttpContentDecompressor());

    // to be used since huge file transfer
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

    pipeline.addLast("handler", new HttpUploadClientHandler());
}
 
Example #5
Source File: WebSocketClient.java    From blynk-server with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected ChannelInitializer<SocketChannel> getChannelInitializer() {
    return new ChannelInitializer<SocketChannel> () {
        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            if (sslCtx != null) {
                p.addLast(sslCtx.newHandler(ch.alloc(), host, port));
            }
            p.addLast(
                    new HttpClientCodec(),
                    new HttpObjectAggregator(8192),
                    handler,
                    new MessageDecoder(new GlobalStats(),
                            new Limits(new ServerProperties(Collections.emptyMap())))
            );
        }
    };
}
 
Example #6
Source File: HttpClientInitializer.java    From SI with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
	public void initChannel(SocketChannel ch) {
		ChannelPipeline pipeline = ch.pipeline();

		// Enable HTTPS if necessary.
//		if (sslCtx != null) {
//			pipeline.addLast(sslCtx.newHandler(ch.alloc()));
//		}

		pipeline.addLast(new HttpClientCodec());
		// Remove the following line if you don't want automatic content decompression.
		pipeline.addLast(new HttpContentDecompressor());

		// Uncomment the following line if you don't want to handle HttpContents.
		//pipeline.addLast(new HttpObjectAggregator(65536));
		pipeline.addLast(new HttpObjectAggregator(65536 * 3));

		
//		pipeline.addLast(new HttpClientHandler(null, mHttpClientListener));
	}
 
Example #7
Source File: HttpSnoopClientInitializer.java    From tools-journey with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();

    // Enable HTTPS if necessary.
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }

    p.addLast(new HttpClientCodec());

    // Remove the following line if you don't want automatic content decompression.
    p.addLast(new HttpContentDecompressor());

    // Uncomment the following line if you don't want to handle HttpContents.
    //p.addLast(new HttpObjectAggregator(1048576));

    p.addLast(new HttpSnoopClientHandler());
}
 
Example #8
Source File: HttpSnoopClientInitializer.java    From julongchain with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();

    // 启用 HTTPS .
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }

    p.addLast(new HttpClientCodec());

    // 如果不想自动处理内容压缩请移除下面这一行.
    p.addLast(new HttpContentDecompressor());

    // 如果不想处理HttpContents就放开下面这行注释.
    //p.addLast(new HttpObjectAggregator(1048576));

    p.addLast(new HttpSnoopClientHandler());
}
 
Example #9
Source File: LBAwareSigV4WebSocketChannelizer.java    From amazon-neptune-tools with Apache License 2.0 6 votes vote down vote up
@Override
public void configure(final ChannelPipeline pipeline) {
    final String scheme = connection.getUri().getScheme();
    if (!WEB_SOCKET.equalsIgnoreCase(scheme) && !WEB_SOCKET_SECURE.equalsIgnoreCase(scheme)) {
        throw new IllegalStateException(String.format("Unsupported scheme (only %s: or %s: supported): %s",
                WEB_SOCKET, WEB_SOCKET_SECURE, scheme));
    }

    if (!supportsSsl() && WEB_SOCKET_SECURE.equalsIgnoreCase(scheme)) {
        throw new IllegalStateException(String.format("To use %s scheme ensure that enableSsl is set to true in "
                        + "configuration",
                WEB_SOCKET_SECURE));
    }

    final int maxContentLength = cluster.connectionPoolSettings().maxContentLength;
    handler = createHandler();

    pipeline.addLast(HTTP_CODEC, new HttpClientCodec());
    pipeline.addLast(AGGREGATOR, new HttpObjectAggregator(maxContentLength));
    pipeline.addLast(WEB_SOCKET_HANDLER, handler);
    pipeline.addLast(GREMLIN_ENCODER, webSocketGremlinRequestEncoder);
    pipeline.addLast(GRELIN_DECODER, webSocketGremlinResponseDecoder);
}
 
Example #10
Source File: HttpClient.java    From multi-model-server with Apache License 2.0 6 votes vote down vote up
private Bootstrap bootstrap(ClientHandler handler) {
    Bootstrap b = new Bootstrap();
    b.group(new NioEventLoopGroup(1))
            .channel(NioSocketChannel.class)
            .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10 * 1000)
            .handler(
                    new ChannelInitializer<Channel>() {
                        @Override
                        public void initChannel(Channel ch) {
                            ChannelPipeline p = ch.pipeline();
                            p.addLast(new ReadTimeoutHandler(10 * 60 * 1000));
                            p.addLast(new HttpClientCodec());
                            p.addLast(new HttpContentDecompressor());
                            p.addLast(new ChunkedWriteHandler());
                            p.addLast(new HttpObjectAggregator(6553600));
                            p.addLast(handler);
                        }
                    });
    return b;
}
 
Example #11
Source File: HttpUploadClientInitializer.java    From tools-journey with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

    if (sslCtx != null) {
        pipeline.addLast("ssl", sslCtx.newHandler(ch.alloc()));
    }

    pipeline.addLast("codec", new HttpClientCodec());

    // Remove the following line if you don't want automatic content decompression.
    pipeline.addLast("inflater", new HttpContentDecompressor());

    // to be used since huge file transfer
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

    pipeline.addLast("handler", new HttpUploadClientHandler());
}
 
Example #12
Source File: HttpClientChannelPoolHandler.java    From protools with Apache License 2.0 6 votes vote down vote up
@Override
public void channelCreated(Channel channel) {

    NioSocketChannel nioSocketChannel = (NioSocketChannel) channel;
    nioSocketChannel.config().setTcpNoDelay(true).setKeepAlive(true);

    final ChannelPipeline p = nioSocketChannel.pipeline();

    //HTTPS
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(channel.alloc()));
    }

    p.addLast(new HttpClientCodec(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE));

    p.addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
}
 
Example #13
Source File: HttpBlobStore.java    From bazel-buildfarm with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("FutureReturnValueIgnored")
private void releaseDownloadChannel(Channel ch) {
  if (ch.isOpen()) {
    // The channel might have been closed due to an error, in which case its pipeline
    // has already been cleared. Closed channels can't be reused.
    try {
      ch.pipeline().remove(ReadTimeoutHandler.class);
      ch.pipeline().remove(HttpClientCodec.class);
      ch.pipeline().remove(HttpDownloadHandler.class);
    } catch (NoSuchElementException e) {
      // If the channel is in the process of closing but not yet closed, some handlers could have
      // been removed and would cause NoSuchElement exceptions to be thrown. Because handlers are
      // removed in reverse-order, if we get a NoSuchElement exception, the following handlers
      // should have been removed.
    }
  }
  channelPool.release(ch);
}
 
Example #14
Source File: ComponentTestUtils.java    From riposte with Apache License 2.0 6 votes vote down vote up
public static Bootstrap createNettyHttpClientBootstrap() {
    Bootstrap bootstrap = new Bootstrap();
    bootstrap.group(new NioEventLoopGroup())
             .channel(NioSocketChannel.class)
             .handler(new ChannelInitializer<SocketChannel>() {
                 @Override
                 protected void initChannel(SocketChannel ch) throws Exception {
                     ChannelPipeline p = ch.pipeline();
                     p.addLast(new HttpClientCodec());
                     p.addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
                     p.addLast("clientResponseHandler", new SimpleChannelInboundHandler<HttpObject>() {
                         @Override
                         protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
                             throw new RuntimeException("Client response handler was not setup before the call");
                         }
                     });
                 }
             });

    return bootstrap;
}
 
Example #15
Source File: HttpSnoopClientInitializer.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();

    // Enable HTTPS if necessary.
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }

    p.addLast(new HttpClientCodec());

    // Remove the following line if you don't want automatic content decompression.
    p.addLast(new HttpContentDecompressor());

    // Uncomment the following line if you don't want to handle HttpContents.
    //p.addLast(new HttpObjectAggregator(1048576));

    p.addLast(new HttpSnoopClientHandler());
}
 
Example #16
Source File: HttpUploadClientIntializer.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

    if (sslCtx != null) {
        pipeline.addLast("ssl", sslCtx.newHandler(ch.alloc()));
    }

    pipeline.addLast("codec", new HttpClientCodec());

    // Remove the following line if you don't want automatic content decompression.
    pipeline.addLast("inflater", new HttpContentDecompressor());

    // to be used since huge file transfer
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

    pipeline.addLast("handler", new HttpUploadClientHandler());
}
 
Example #17
Source File: HttpClientInitializer.java    From SI with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
	public void initChannel(SocketChannel ch) {
		ChannelPipeline pipeline = ch.pipeline();

		// Enable HTTPS if necessary.
//		if (sslCtx != null) {
//			pipeline.addLast(sslCtx.newHandler(ch.alloc()));
//		}

		pipeline.addLast(new HttpClientCodec());
		// Remove the following line if you don't want automatic content decompression.
		pipeline.addLast(new HttpContentDecompressor());

		// Uncomment the following line if you don't want to handle HttpContents.
		//pipeline.addLast(new HttpObjectAggregator(65536));
		pipeline.addLast(new HttpObjectAggregator(65536 * 3));

		
//		pipeline.addLast(new HttpClientHandler(null, mHttpClientListener));
	}
 
Example #18
Source File: WebWhoisModule.java    From nomulus with Apache License 2.0 6 votes vote down vote up
/**
 * {@link Provides} the list of providers of {@link ChannelHandler}s that are used for https
 * protocol.
 */
@Provides
@HttpsWhoisProtocol
static ImmutableList<Provider<? extends ChannelHandler>> providerHttpsWhoisHandlerProviders(
    @HttpsWhoisProtocol
        Provider<SslClientInitializer<NioSocketChannel>> sslClientInitializerProvider,
    Provider<HttpClientCodec> httpClientCodecProvider,
    Provider<HttpObjectAggregator> httpObjectAggregatorProvider,
    Provider<WebWhoisMessageHandler> messageHandlerProvider,
    Provider<WebWhoisActionHandler> webWhoisActionHandlerProvider) {
  return ImmutableList.of(
      sslClientInitializerProvider,
      httpClientCodecProvider,
      httpObjectAggregatorProvider,
      messageHandlerProvider,
      webWhoisActionHandlerProvider);
}
 
Example #19
Source File: HttpsRelayProtocolModule.java    From nomulus with Apache License 2.0 6 votes vote down vote up
@Provides
@HttpsRelayProtocol
static ImmutableList<Provider<? extends ChannelHandler>> provideHandlerProviders(
    @HttpsRelayProtocol
        Provider<SslClientInitializer<NioSocketChannel>> sslClientInitializerProvider,
    Provider<HttpClientCodec> httpClientCodecProvider,
    Provider<HttpObjectAggregator> httpObjectAggregatorProvider,
    Provider<BackendMetricsHandler> backendMetricsHandlerProvider,
    Provider<LoggingHandler> loggingHandlerProvider,
    Provider<FullHttpResponseRelayHandler> relayHandlerProvider) {
  return ImmutableList.of(
      sslClientInitializerProvider,
      httpClientCodecProvider,
      httpObjectAggregatorProvider,
      backendMetricsHandlerProvider,
      loggingHandlerProvider,
      relayHandlerProvider);
}
 
Example #20
Source File: Http2ClientInitializer.java    From jmeter-http2-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2.
 */
private void configureClearText(SocketChannel ch) {
    HttpClientCodec sourceCodec = new HttpClientCodec();
    Http2ClientUpgradeCodec upgradeCodec = new Http2ClientUpgradeCodec(connectionHandler);
    HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, 65536);

    ch.pipeline().addLast("Http2SourceCodec", sourceCodec);
    ch.pipeline().addLast("Http2UpgradeHandler", upgradeHandler);
    ch.pipeline().addLast("Http2UpgradeRequestHandler", new UpgradeRequestHandler());
    ch.pipeline().addLast("Logger", new UserEventLogger());
}
 
Example #21
Source File: WebWhoisModule.java    From nomulus with Apache License 2.0 5 votes vote down vote up
/**
 * {@link Provides} the list of providers of {@link ChannelHandler}s that are used for http
 * protocol.
 */
@Provides
@HttpWhoisProtocol
static ImmutableList<Provider<? extends ChannelHandler>> providerHttpWhoisHandlerProviders(
    Provider<HttpClientCodec> httpClientCodecProvider,
    Provider<HttpObjectAggregator> httpObjectAggregatorProvider,
    Provider<WebWhoisMessageHandler> messageHandlerProvider,
    Provider<WebWhoisActionHandler> webWhoisActionHandlerProvider) {
  return ImmutableList.of(
      httpClientCodecProvider,
      httpObjectAggregatorProvider,
      messageHandlerProvider,
      webWhoisActionHandlerProvider);
}
 
Example #22
Source File: SSLDetector.java    From cute-proxy with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void setHttpInterceptor(ChannelHandlerContext ctx, boolean ssl) {
    ctx.pipeline().addLast("http-codec", new HttpServerCodec());
    ctx.pipeline().addLast(new HttpServerExpectContinueHandler());
    ctx.pipeline().addLast("replay-handler", new ReplayHandler(outboundChannel));

    outboundChannel.pipeline().addLast("http-codec", new HttpClientCodec());
    var httpUpgradeHandler = new HttpUpgradeHandler(ssl, address, messageListener, ctx.pipeline());
    outboundChannel.pipeline().addLast("http-upgrade-handler", httpUpgradeHandler);
    var httpInterceptor = new HttpInterceptor(ssl, address, messageListener);
    outboundChannel.pipeline().addLast("http-interceptor", httpInterceptor);
    outboundChannel.pipeline().addLast("replay-handler", new ReplayHandler(ctx.channel()));
}
 
Example #23
Source File: WebSocketFrameTransport.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
protected void buildInputOutputPipeline(final ChannelPipeline pipeline)
{
    pipeline.addLast(new HttpClientCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(_webSocketClientHandler);
    pipeline.addLast(_webSocketFramingOutputHandler);
    pipeline.addLast(_webSocketDeframingInputHandler);
    super.buildInputOutputPipeline(pipeline);
}
 
Example #24
Source File: Http2ClientInitializer.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
/**
 * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2.
 */
private void configureClearText(SocketChannel ch) {
    HttpClientCodec sourceCodec = new HttpClientCodec();
    Http2ClientUpgradeCodec upgradeCodec = new Http2ClientUpgradeCodec(connectionHandler);
    HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, 65536);

    ch.pipeline().addLast(sourceCodec,
                          upgradeHandler,
                          new UpgradeRequestHandler(),
                          new UserEventLogger());
}
 
Example #25
Source File: HttpBlobStore.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("FutureReturnValueIgnored")
private Future<Channel> acquireDownloadChannel() {
  Promise<Channel> channelReady = eventLoop.next().newPromise();
  channelPool
      .acquire()
      .addListener(
          (Future<Channel> channelAcquired) -> {
            if (!channelAcquired.isSuccess()) {
              channelReady.setFailure(channelAcquired.cause());
              return;
            }

            try {
              Channel ch = channelAcquired.getNow();
              ChannelPipeline p = ch.pipeline();

              if (!isChannelPipelineEmpty(p)) {
                channelReady.setFailure(
                    new IllegalStateException("Channel pipeline is not empty."));
                return;
              }

              ch.pipeline()
                  .addFirst("read-timeout-handler", new ReadTimeoutHandler(timeoutMillis));
              p.addLast(new HttpClientCodec());
              synchronized (credentialsLock) {
                p.addLast(new HttpDownloadHandler(creds));
              }

              channelReady.setSuccess(ch);
            } catch (Throwable t) {
              channelReady.setFailure(t);
            }
          });

  return channelReady;
}
 
Example #26
Source File: ProxyTunnelInitHandlerTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void handlerRemoved_removesCodec() {
    HttpClientCodec codec = new HttpClientCodec();
    when(mockPipeline.get(eq(HttpClientCodec.class))).thenReturn(codec);

    Promise<Channel> promise = GROUP.next().newPromise();
    ProxyTunnelInitHandler handler = new ProxyTunnelInitHandler(mockChannelPool, REMOTE_HOST, promise);

    handler.handlerRemoved(mockCtx);

    verify(mockPipeline).remove(eq(HttpClientCodec.class));
}
 
Example #27
Source File: ProxyTunnelInitHandlerTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void successfulProxyResponse_removesSelfAndCodec() {
    Promise<Channel> promise = GROUP.next().newPromise();
    ProxyTunnelInitHandler handler = new ProxyTunnelInitHandler(mockChannelPool, REMOTE_HOST, promise);
    successResponse(handler);

    verify(mockPipeline).remove(eq(handler));
    verify(mockPipeline).remove(any(HttpClientCodec.class));
}
 
Example #28
Source File: ProxyTunnelInitHandlerTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void addedToPipeline_addsCodec() {
    HttpClientCodec codec = new HttpClientCodec();
    Supplier<HttpClientCodec> codecSupplier = () -> codec;
    when(mockCtx.name()).thenReturn("foo");

    ProxyTunnelInitHandler handler = new ProxyTunnelInitHandler(mockChannelPool, REMOTE_HOST, null, codecSupplier);
    handler.handlerAdded(mockCtx);

    verify(mockPipeline).addBefore(eq("foo"), eq(null), eq(codec));
}
 
Example #29
Source File: WebSocketClientHandshaker.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
/**
 * Begins the opening handshake
 *
 * @param channel
 *            Channel
 * @param promise
 *            the {@link ChannelPromise} to be notified when the opening handshake is sent
 */
public final ChannelFuture handshake(Channel channel, final ChannelPromise promise) {
    FullHttpRequest request =  newHandshakeRequest();

    HttpResponseDecoder decoder = channel.pipeline().get(HttpResponseDecoder.class);
    if (decoder == null) {
        HttpClientCodec codec = channel.pipeline().get(HttpClientCodec.class);
        if (codec == null) {
           promise.setFailure(new IllegalStateException("ChannelPipeline does not contain " +
                   "a HttpResponseDecoder or HttpClientCodec"));
           return promise;
        }
    }

    channel.writeAndFlush(request).addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) {
            if (future.isSuccess()) {
                ChannelPipeline p = future.channel().pipeline();
                ChannelHandlerContext ctx = p.context(HttpRequestEncoder.class);
                if (ctx == null) {
                    ctx = p.context(HttpClientCodec.class);
                }
                if (ctx == null) {
                    promise.setFailure(new IllegalStateException("ChannelPipeline does not contain " +
                            "a HttpRequestEncoder or HttpClientCodec"));
                    return;
                }
                p.addAfter(ctx.name(), "ws-encoder", newWebSocketEncoder());

                promise.setSuccess();
            } else {
                promise.setFailure(future.cause());
            }
        }
    });
    return promise;
}
 
Example #30
Source File: StreamingAsyncHttpClient.java    From riposte with Apache License 2.0 5 votes vote down vote up
protected static int determineHttpClientCodecInboundState(HttpClientCodec currentCodec) {
    try {
        HttpObjectDecoder decoder = (HttpObjectDecoder) httpClientCodecInboundHandlerField.get(currentCodec);
        return ((Enum) httpObjectDecoderCurrentStateField.get(decoder)).ordinal();
    }
    catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}