當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpClientCodec類代碼示例

本文整理匯總了Java中io.netty.handler.codec.http.HttpClientCodec的典型用法代碼示例。如果您正苦於以下問題:Java HttpClientCodec類的具體用法?Java HttpClientCodec怎麽用?Java HttpClientCodec使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpClientCodec類屬於io.netty.handler.codec.http包,在下文中一共展示了HttpClientCodec類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initChannel

import io.netty.handler.codec.http.HttpClientCodec; //導入依賴的package包/類
/**
 * Adds pipelines to channel.
 * 
 *  @param ch channel to be operated on
 */
protected void initChannel(SocketChannel ch) throws Exception {
  ChannelPipeline pipe = ch.pipeline();

  if (ssl) {
    // HTTPs connection
    SSLEngine sslEng = getSsl(null);
    sslEng.setUseClientMode(true);
    pipe.addLast("SSL", new SslHandler(sslEng, false));
  }

  pipe.addFirst("Timer", new ReadTimeoutHandler(30));
  pipe.addLast("Codec", new HttpClientCodec());
  pipe.addLast("Inflater", new HttpContentDecompressor());
  pipe.addLast("Handler", new HTTPMessageHandler(builder));
}
 
開發者ID:didclab,項目名稱:onedatashare,代碼行數:21,代碼來源:HTTPInitializer.java

示例2: fixHandlerBeforeConnect

import io.netty.handler.codec.http.HttpClientCodec; //導入依賴的package包/類
/**
	 * 適配
	 */
	@Override
	protected ChannelHandler fixHandlerBeforeConnect(final ChannelHandler handler) {
		ChannelHandler result=new ShareableChannelInboundHandler() {
			@Override
			public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
				Channel ch=ctx.channel();
				ch.pipeline().addLast(new HttpClientCodec());
            	ch.pipeline().addLast(new HttpObjectAggregator(64*1024));
            	ch.pipeline().addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));
            	ch.pipeline().addLast(new WebSocketConnectedClientHandler(handler));
				ctx.pipeline().remove(this);//移除當前handler
				ctx.pipeline().fireChannelRegistered();//重新從第一個handler拋出事件
			}
		};
//		ChannelInitializer<SocketChannel> result=new ChannelInitializer<SocketChannel>() {
//            @Override
//            protected void initChannel(SocketChannel ch) {
//            	ch.pipeline().addLast(new HttpClientCodec());
//            	ch.pipeline().addLast(new HttpObjectAggregator(64*1024));
//            	ch.pipeline().addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));
//            	ch.pipeline().addLast(new WebSocketConnectedClientHandler(handler));
//            }
//        };
        return result;
	}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:29,代碼來源:NettyTextWebSocketClient.java

示例3: fixHandlerBeforeConnect

import io.netty.handler.codec.http.HttpClientCodec; //導入依賴的package包/類
/**
	 * 適配
	 */
	@Override
	protected ChannelHandler fixHandlerBeforeConnect(final ChannelHandler handler) {
		ChannelHandler result=new ShareableChannelInboundHandler() {
			@Override
			public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
				Channel ch=ctx.channel();
				ch.pipeline().addLast(new HttpClientCodec());
            	ch.pipeline().addLast(new HttpObjectAggregator(64*1024));
            	ch.pipeline().addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));
            	ch.pipeline().addLast(new WebSocketConnectedClientHandler(handler));
				ctx.pipeline().remove(this);//移除當前handler
				ctx.fireChannelRegistered();//重新從第一個handler拋出事件
			}
		};
//		ChannelInitializer<SocketChannel> result=new ChannelInitializer<SocketChannel>() {
//            @Override
//            protected void initChannel(SocketChannel ch) {
//            	ch.pipeline().addLast(new HttpClientCodec());
//            	ch.pipeline().addLast(new HttpObjectAggregator(64*1024));
//            	ch.pipeline().addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));
//            	ch.pipeline().addLast(new WebSocketConnectedClientHandler(handler));
//            }
//        };
        return result;
	}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:29,代碼來源:NettyBinaryWebSocketClient.java

示例4: channelCreated

import io.netty.handler.codec.http.HttpClientCodec; //導入依賴的package包/類
@Override
public void channelCreated(Channel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();

    if (sslContext != null) {
        SslHandler handler = sslContext.newHandler(ch.alloc());
        p.addLast(handler);
        handler.handshakeFuture().addListener(future -> {
            if (!future.isSuccess()) {
                log.error(() -> "SSL handshake failed.", future.cause());
            }
        });
    }

    p.addLast(new HttpClientCodec());
    p.addLast(handlers);
    // Disabling auto-read is needed for backpressure to work
    ch.config().setOption(ChannelOption.AUTO_READ, false);
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:20,代碼來源:ChannelPipelineInitializer.java

示例5: initChannel

import io.netty.handler.codec.http.HttpClientCodec; //導入依賴的package包/類
@Override
    public void initChannel(SocketChannel ch) throws Exception {
        // Create a default pipeline implementation.
        ChannelPipeline p = ch.pipeline();

        p.addLast("log", new LoggingHandler(LogLevel.INFO));
        // Enable HTTPS if necessary.
/*        if (ssl) {
            SSLEngine engine =
                SecureChatSslContextFactory.getClientContext().createSSLEngine();
            engine.setUseClientMode(true);

            p.addLast("ssl", new SslHandler(engine));
        }*/

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

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

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

        p.addLast("handler", new HttpSnoopClientHandler());
    }
 
開發者ID:eBay,項目名稱:ServiceCOLDCache,代碼行數:26,代碼來源:HttpSnoopClientInitializer.java

示例6: initChannel

import io.netty.handler.codec.http.HttpClientCodec; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel channel) throws SSLException {
    URI uri = config.getConnectionWebsocketUri();

    DefaultHttpHeaders headers = new DefaultHttpHeaders();
    headers.add(USER_ID_HEADER, config.getConnectionUserId().toString());
    headers.add(USER_PASSWORD_HEADER, config.getConnectionUserPassword());
    headers.add(SUPPLIER_ID_HEADER, config.getConnectionServerId());

    WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(uri, WS_VERSION, null, false, headers);

    ChannelPipeline pipeline = channel.pipeline();
    if (config.isConnectionSecure()) {
        try {
            SslContext sslContext = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE);
            pipeline.addLast(sslContext.newHandler(channel.alloc()));
        } catch (SSLException e) {
            logger.log(Level.SEVERE, "Shutting down client due to unexpected failure to create SSL context", e);
            throw e;
        }
    }
    pipeline.addLast(new HttpClientCodec());
    pipeline.addLast(new HttpObjectAggregator(8192));
    pipeline.addLast(new AudioConnectClientHandler(handshaker));
}
 
開發者ID:DeadmanDungeons,項目名稱:AudioConnect,代碼行數:26,代碼來源:AudioConnectClient.java

示例7: createNettyHttpClientBootstrap

import io.netty.handler.codec.http.HttpClientCodec; //導入依賴的package包/類
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;
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:22,代碼來源:ComponentTestUtils.java

示例8: configure

import io.netty.handler.codec.http.HttpClientCodec; //導入依賴的package包/類
@Override
public void configure(final ChannelPipeline pipeline) {
    final String scheme = connection.getUri().getScheme();
    if (!"ws".equalsIgnoreCase(scheme) && !"wss".equalsIgnoreCase(scheme))
        throw new IllegalStateException("Unsupported scheme (only ws: or wss: supported): " + scheme);

    if (!supportsSsl() && "wss".equalsIgnoreCase(scheme))
        throw new IllegalStateException("To use wss scheme ensure that enableSsl is set to true in configuration");

    final int maxContentLength = cluster.connectionPoolSettings().maxContentLength;
    handler = new WebSocketClientHandler(
            WebSocketClientHandshakerFactory.newHandshaker(
                    connection.getUri(), WebSocketVersion.V13, null, false, HttpHeaders.EMPTY_HEADERS, maxContentLength));

    pipeline.addLast("http-codec", new HttpClientCodec());
    pipeline.addLast("aggregator", new HttpObjectAggregator(maxContentLength));
    pipeline.addLast("ws-handler", handler);
    pipeline.addLast("gremlin-encoder", webSocketGremlinRequestEncoder);
    pipeline.addLast("gremlin-decoder", webSocketGremlinResponseDecoder);
}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:21,代碼來源:Channelizer.java

示例9: initChannel

import io.netty.handler.codec.http.HttpClientCodec; //導入依賴的package包/類
@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());
}
 
開發者ID:cowthan,項目名稱:JavaAyo,代碼行數:19,代碼來源:HttpUploadClientIntializer.java

示例10: initChannel

import io.netty.handler.codec.http.HttpClientCodec; //導入依賴的package包/類
@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());
}
 
開發者ID:cowthan,項目名稱:JavaAyo,代碼行數:20,代碼來源:HttpSnoopClientInitializer.java

示例11: initChannel

import io.netty.handler.codec.http.HttpClientCodec; //導入依賴的package包/類
@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));
	}
 
開發者ID:iotoasis,項目名稱:SI,代碼行數:21,代碼來源:HttpClientInitializer.java

示例12: provideHandlerProviders

import io.netty.handler.codec.http.HttpClientCodec; //導入依賴的package包/類
@Provides
@HttpsRelayProtocol
static ImmutableList<Provider<? extends ChannelHandler>> provideHandlerProviders(
    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);
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:18,代碼來源:HttpsRelayProtocolModule.java

示例13: getChannelInitializer

import io.netty.handler.codec.http.HttpClientCodec; //導入依賴的package包/類
@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())
            );
        }
    };
}
 
開發者ID:blynkkk,項目名稱:blynk-server,代碼行數:19,代碼來源:WebSocketClient.java

示例14: initChannel

import io.netty.handler.codec.http.HttpClientCodec; //導入依賴的package包/類
@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(handler);
}
 
開發者ID:FIWARE-Middleware,項目名稱:KIARA,代碼行數:19,代碼來源:URILoader.java

示例15: initChannel

import io.netty.handler.codec.http.HttpClientCodec; //導入依賴的package包/類
@Override
public void initChannel(SocketChannel ch) throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = ch.pipeline();

    if (ssl) {
        SSLEngine engine = SecureChatSslContextFactory.getClientContext().createSSLEngine();
        engine.setUseClientMode(true);
        pipeline.addLast("ssl", new SslHandler(engine));
    }

    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());
}
 
開發者ID:kyle-liu,項目名稱:netty4study,代碼行數:22,代碼來源:HttpUploadClientIntializer.java


注:本文中的io.netty.handler.codec.http.HttpClientCodec類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。