本文整理汇总了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));
}
示例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;
}
示例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;
}
示例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);
}
示例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());
}
示例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));
}
示例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;
}
示例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);
}
示例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());
}
示例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());
}
示例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));
}
示例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);
}
示例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())
);
}
};
}
示例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);
}
示例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());
}