本文整理汇总了Java中org.jboss.netty.handler.codec.http.HttpRequestEncoder类的典型用法代码示例。如果您正苦于以下问题:Java HttpRequestEncoder类的具体用法?Java HttpRequestEncoder怎么用?Java HttpRequestEncoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpRequestEncoder类属于org.jboss.netty.handler.codec.http包,在下文中一共展示了HttpRequestEncoder类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPipeline
import org.jboss.netty.handler.codec.http.HttpRequestEncoder; //导入依赖的package包/类
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = pipeline();
pipeline.addLast("idle-detection", IDLE_STATE_HANDLER);
pipeline.addLast("logging", new LoggingHandler(InternalLogLevel.DEBUG));
pipeline.addLast("http-deflater", new HttpContentCompressor());
pipeline.addLast("decoder", new HttpResponseDecoder(RESPONSE_MAX_INITIAL_LINE_LENGTH, RESPONSE_MAX_HEADER_SIZE, RESPONSE_MAX_CHUNK_SIZE));
pipeline.addLast("encoder", new HttpRequestEncoder());
pipeline.addLast("http-inflater", new HttpContentDecompressor());
pipeline.addLast("remote-hop-timer", new ClientTimingHandler("outbound"));
pipeline.addLast("exception-surfacer", EXCEPTION_SURFACER);
pipeline.addLast("idle-watchdog", new IdleChannelWatchdog("outbound"));
return pipeline;
}
示例2: initSendPipeline
import org.jboss.netty.handler.codec.http.HttpRequestEncoder; //导入依赖的package包/类
private void initSendPipeline(ChannelPipeline pipeline) {
pipeline.addLast("reqencoder", new HttpRequestEncoder()); // downstream
pipeline.addLast("respdecoder", new HttpResponseDecoder()); // upstream
pipeline.addLast("aggregator", new HttpChunkAggregator(HttpTunnelMessageUtils.MAX_BODY_SIZE)); // upstream
pipeline.addLast(HttpTunnelClientChannelProxyHandler.NAME, sendHttpHandler); // proxy auth, etc
pipeline.addLast(HttpTunnelClientChannelSendHandler.NAME, sendHandler); // both
pipeline.addLast("writeFragmenter", new WriteFragmenter(HttpTunnelMessageUtils.MAX_BODY_SIZE));
}
示例3: initPollPipeline
import org.jboss.netty.handler.codec.http.HttpRequestEncoder; //导入依赖的package包/类
private void initPollPipeline(ChannelPipeline pipeline) {
pipeline.addLast("reqencoder", new HttpRequestEncoder()); // downstream
pipeline.addLast("respdecoder", new HttpResponseDecoder()); // upstream
pipeline.addLast("aggregator", new HttpChunkAggregator(HttpTunnelMessageUtils.MAX_BODY_SIZE)); // upstream
pipeline.addLast(HttpTunnelClientChannelProxyHandler.NAME, pollHttpHandler); // proxy auth, etc
pipeline.addLast(HttpTunnelClientChannelPollHandler.NAME, pollHandler); // both
}
示例4: EventSource
import org.jboss.netty.handler.codec.http.HttpRequestEncoder; //导入依赖的package包/类
private EventSource(Builder builder) {
this.uri = builder.uri;
this.eventSourceHandler = builder.eventSourceHandler;
boolean exposeComments = builder.exposeComments;
long reconnectInterval = builder.reconnectInterval;
this.executor = builder.executor;
Map<String, String> headers = builder.headers;
SSLEngineFactory sslEngineFactory = builder.sslEngineFactory;
if (executor == null)
this.executor = Executors.newSingleThreadExecutor();
if (eventSourceHandler == null)
Log.d(TAG, "No handler attached");
bootstrap = new ClientBootstrap(
new NioClientSocketChannelFactory(Executors.newSingleThreadExecutor(),
Executors.newSingleThreadExecutor()));
if (!uri.getScheme().equals("https")) {
//If we don't do this then the pipeline still attempts to use SSL
sslEngineFactory = null;
} else if (sslEngineFactory == null) {
sslEngineFactory = new SSLEngineFactory();
}
final SSLEngineFactory SSLFactory = sslEngineFactory;
// add this class as the event source handler so the connect() call can be intercepted
AsyncEventSourceHandler asyncHandler =
new AsyncEventSourceHandler(executor, this, exposeComments);
clientHandler =
new EventSourceChannelHandler(asyncHandler, reconnectInterval, bootstrap, uri,
headers);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
if (SSLFactory != null) {
SSLEngine sslEngine = SSLFactory.GetNewSSLEngine();
sslEngine.setUseClientMode(true);
pipeline.addLast("ssl", new SslHandler(sslEngine));
}
pipeline.addLast("line",
new DelimiterBasedFrameDecoder(Integer.MAX_VALUE, Delimiters.lineDelimiter()));
pipeline.addLast("string", new StringDecoder());
pipeline.addLast("encoder", new HttpRequestEncoder());
pipeline.addLast("es-handler", clientHandler);
return pipeline;
}
});
}
示例5: EventSource
import org.jboss.netty.handler.codec.http.HttpRequestEncoder; //导入依赖的package包/类
public EventSource(Executor executor, long reconnectionTimeMillis, final URI pURI, URI requestUri, SSLEngineFactory fSSLEngine, EventSourceHandler eventSourceHandler, Map<String, String> headers) {
this.eventSourceHandler = eventSourceHandler;
bootstrap = new ClientBootstrap(
new NioClientSocketChannelFactory(
Executors.newSingleThreadExecutor(),
Executors.newSingleThreadExecutor()));
if (pURI.getScheme().equals("https") && fSSLEngine == null) {
fSSLEngine = new SSLEngineFactory();
} else {
//If we don't do this then the pipeline still attempts to use SSL
fSSLEngine = null;
}
final SSLEngineFactory SSLFactory = fSSLEngine;
uri = pURI;
int port = uri.getPort();
// handle default port values
if (port == -1) {
port = (uri.getScheme().equals("https")) ? 443 : 80;
}
bootstrap.setOption("remoteAddress", new InetSocketAddress(uri.getHost(), port));
// add this class as the event source handler so the connect() call can be intercepted.
AsyncEventSourceHandler asyncHandler = new AsyncEventSourceHandler(executor, this);
clientHandler = new EventSourceChannelHandler(asyncHandler, reconnectionTimeMillis, bootstrap, uri, requestUri, headers);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
if (SSLFactory != null) {
SSLEngine sslEngine = SSLFactory.GetNewSSLEngine();
sslEngine.setUseClientMode(true);
// add handling of https connection
pipeline.addLast("ssl", new SslHandler(sslEngine));
}
// simply decode flow as string
pipeline.addLast("string", new StringDecoder());
// simple encode request as HTTP request
pipeline.addLast("encoder", new HttpRequestEncoder());
// add our own event source handler
pipeline.addLast("es-handler", clientHandler);
return pipeline;
}
});
connect();
}
示例6: connect
import org.jboss.netty.handler.codec.http.HttpRequestEncoder; //导入依赖的package包/类
public static ClientChannel connect(LoggerFactory loggerFactory, URI uri,
int connectTimeoutMillis) throws ChannelException {
Logger logger = loggerFactory.create(String.format("WebSocketClientHandler-%s", uri));
WebSocketClientChannel clientChannel = new WebSocketClientChannel();
clientChannel.setUri(uri);
ConnectingChannelHandler handler = new ConnectingChannelHandler();
clientChannel.setChannelHandler(handler);
WebSocketClientUpstreamHandler wsHandler = new WebSocketClientUpstreamHandler(logger,
clientChannel);
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("decoder", new HttpResponseDecoder());
pipeline.addLast("encoder", new HttpRequestEncoder());
// connect
Channel channel = prepareAndConnect(logger, uri, pipeline, wsHandler,
uri.getScheme().equalsIgnoreCase("wss"), connectTimeoutMillis);
// handshake
try {
WebSocketClientHandshaker handshaker = wsFactory.newHandshaker(uri,
WebSocketVersion.V13, null, true, WebSocketClientHelper.getHeaders(uri));
wsHandler.handshaker = handshaker;
handshaker.handshake(channel);
// return maybe fast than call
if (!wsHandler.handshaker.isHandshakeComplete() && (handler.error == null)) {
synchronized (handler.syncObject) {
handler.syncObject.wait(connectTimeoutMillis);
}
}
} catch (Exception e) {
throw new ChannelException(Text.WS_HANDSHAKE_ERROR, e);
}
if (wsHandler.handshaker.isHandshakeComplete()) {
return clientChannel;
}
if (handler.error != null) {
throw new ChannelException(Text.CONNECT_FAIL + ": " + handler.error.getMessage(),
handler.error);
}
throw new ChannelException(Text.CONNECT_TIMEOUT);
}
示例7: NettyWSClient
import org.jboss.netty.handler.codec.http.HttpRequestEncoder; //导入依赖的package包/类
public NettyWSClient(String uriStr, WebSocketClient webSocketClient)
{
this.t = webSocketClient;
this.uri = URI.create(uriStr);
String protocol = this.uri.getScheme();
if (!protocol.equals("ws"))
{
throw new IllegalArgumentException("Unsupported protocol: " + protocol);
}
ClientBootstrap bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
Channel ch = null;
HashMap<String, String> customHeaders = new HashMap<String, String>();
customHeaders.put("MyHeader", "MyValue");
// Connect with V13 (RFC 6455 aka HyBi-17). You can change it to V08 or V00.
// If you change it to V00, ping is not supported and remember to change
// HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline.
this.handshaker = new WebSocketClientHandshakerFactory().newHandshaker(this.uri, WebSocketVersion.V13, null, false, customHeaders);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception
{
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("decoder", new HttpResponseDecoder());
pipeline.addLast("encoder", new HttpRequestEncoder());
pipeline.addLast("ws-handler", NettyWSClient.this);
return pipeline;
}
});
ChannelFuture future = bootstrap.connect(new InetSocketAddress(this.uri.getHost(), this.uri.getPort()));
future.syncUninterruptibly();
ch = future.getChannel();
try
{
this.handshaker.handshake(ch);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}