Search in sources :

Example 1 with HttpRequestEncoder

use of org.jboss.netty.handler.codec.http.HttpRequestEncoder in project sockjs-netty by cgbystrom.

the class SockJsClient method newClient.

public static SockJsClient newClient(URI url, Protocol protocol, final SessionCallback callback) {
    ClientBootstrap bootstrap = new ClientBootstrap(socketChannelFactory);
    switch(protocol) {
        case WEBSOCKET:
            final WebSocketClient clientHandler = new WebSocketClient(bootstrap, url, callback);
            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", clientHandler);
                    return pipeline;
                }
            });
            return clientHandler;
    }
    throw new IllegalArgumentException("Invalid protocol specified");
}
Also used : ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) HttpRequestEncoder(org.jboss.netty.handler.codec.http.HttpRequestEncoder) HttpResponseDecoder(org.jboss.netty.handler.codec.http.HttpResponseDecoder) URISyntaxException(java.net.URISyntaxException)

Example 2 with HttpRequestEncoder

use of org.jboss.netty.handler.codec.http.HttpRequestEncoder in project sockjs-netty by cgbystrom.

the class SockJsClient method newLocalClient.

public static SockJsClient newLocalClient(URI url, Protocol protocol, final SessionCallback callback) {
    ClientBootstrap bootstrap = new ClientBootstrap(localSocketChannelFactory);
    switch(protocol) {
        case WEBSOCKET:
            final WebSocketClient clientHandler = new WebSocketClient(bootstrap, url, callback);
            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", clientHandler);
                    return pipeline;
                }
            });
            return clientHandler;
    }
    throw new IllegalArgumentException("Invalid protocol specified");
}
Also used : ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) HttpRequestEncoder(org.jboss.netty.handler.codec.http.HttpRequestEncoder) HttpResponseDecoder(org.jboss.netty.handler.codec.http.HttpResponseDecoder) URISyntaxException(java.net.URISyntaxException)

Example 3 with HttpRequestEncoder

use of org.jboss.netty.handler.codec.http.HttpRequestEncoder in project cdap by caskdata.

the class ClientChannelPipelineFactory method getPipeline.

@Override
public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("tracker", connectionTracker);
    pipeline.addLast("request-encoder", new HttpRequestEncoder());
    // outbound handler gets dynamically added here (after 'request-encoder')
    pipeline.addLast("response-decoder", new HttpResponseDecoder());
    // disable the read-specific and write-specific timeouts; we only utilize IdleState#ALL_IDLE
    pipeline.addLast("idle-event-generator", new IdleStateHandler(timer, 0, 0, connectionTimeout));
    pipeline.addLast("idle-event-processor", new IdleEventProcessor());
    return pipeline;
}
Also used : IdleEventProcessor(co.cask.cdap.gateway.router.handlers.IdleEventProcessor) IdleStateHandler(org.jboss.netty.handler.timeout.IdleStateHandler) HttpRequestEncoder(org.jboss.netty.handler.codec.http.HttpRequestEncoder) HttpResponseDecoder(org.jboss.netty.handler.codec.http.HttpResponseDecoder) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Aggregations

HttpRequestEncoder (org.jboss.netty.handler.codec.http.HttpRequestEncoder)3 HttpResponseDecoder (org.jboss.netty.handler.codec.http.HttpResponseDecoder)3 URISyntaxException (java.net.URISyntaxException)2 ClientBootstrap (org.jboss.netty.bootstrap.ClientBootstrap)2 IdleEventProcessor (co.cask.cdap.gateway.router.handlers.IdleEventProcessor)1 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)1 IdleStateHandler (org.jboss.netty.handler.timeout.IdleStateHandler)1