/** * Build an instance of this class. * * @return this; */ public Config build() { if (paths.isEmpty()) { paths.add("/"); } if (context != null) { if (enabledCipherSuites == null) { throw new IllegalStateException("Incomplete Config: SSLContext requires cipherSuites to be specified."); } if (contextListener == null) { contextListener = new SSLContextListener() { @Override public void onPostCreate(SSLEngine e) { e.setEnabledCipherSuites(enabledCipherSuites); e.setUseClientMode(false); } }; } } return new Config(this); }
@Override protected void initChannel(Channel ch) throws Exception { final ChannelPipeline pipeline = ch.pipeline(); if (config.sslContext() != null) { SSLEngine e = config.sslContext().createSSLEngine(); config.sslContextListener().onPostCreate(e); pipeline.addLast("ssl", new SslHandler(e)); } if (config.nettySslContext() != null) { pipeline.addLast("ssl", config.nettySslContext().newHandler(ch.alloc())); } pipeline.addLast("decoder", new HttpRequestDecoder()); pipeline.addLast("aggregator", new HttpObjectAggregator(config.maxChunkContentLength())); if (config.supportChunking()) { pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); } for (ChannelInboundHandler h: config.channelUpstreamHandlers()) { pipeline.addLast(h.getClass().getName(), h); } pipeline.addLast(new WebSocketServerCompressionHandler()); pipeline.addLast(BridgeRuntime.class.getName(), bridgeRuntime); }
private ServerBootstrap buildBootstrap(Config config) { final ServerBootstrap bootstrap = new ServerBootstrap(); parentGroup = config.epoll() ? new EpollEventLoopGroup() : new NioEventLoopGroup(); childGroup = config.epoll() ? new EpollEventLoopGroup() : new NioEventLoopGroup(); bootstrap .channel(config.epoll() ? EpollServerSocketChannel.class : NioServerSocketChannel.class) .group(parentGroup, childGroup); bootstrap.childHandler(channelInitializer); return bootstrap; }
public BridgeRuntime(final Config config) { super(config.path()); this.config = config; framework = new AtmosphereFramework(); if (config.broadcaster() != null) { framework.setDefaultBroadcasterClassName(config.broadcaster().getName()); framework.setAtmosphereDotXmlPath(config.configFile()); if (config.broadcasterFactory() != null) { framework.setBroadcasterFactory(config.broadcasterFactory()); if (config.broadcasterCache() != null) { try { framework.setBroadcasterCacheClassName(config.broadcasterCache().getName()); } catch (Throwable t) { logger.trace("", t); Map<String, AtmosphereHandler> handlersMap = config.handlersMap(); for (Map.Entry<String, AtmosphereHandler> e : handlersMap.entrySet()) { framework.addAtmosphereHandler(e.getKey(), e.getValue()); final Map<String, WebSocketHandler> webSocketHandlerMap = config.webSocketHandlersMap(); if (config.webSocketProtocol() != null) { framework.setWebSocketProtocolClassName(config.webSocketProtocol().getName()); for (AtmosphereInterceptor i : config.interceptors()) { framework.interceptor(i);
config.subProtocols(), false, maxWebSocketFrameSize); wsFactory.sendUnsupportedVersionResponse(ctx.channel()); } else { final NettyWebSocket webSocket = new NettyWebSocket(ctx.channel(), framework.getAtmosphereConfig(), config.noInternalAlloc(), config.binaryWrite()); final AtmosphereRequest atmosphereRequest = createAtmosphereRequest(ctx, request, EMPTY);
ByteBuf binaryData = frame.content(); byte[] body = null; if ((config.textFrameAsBinary() || !(frame instanceof TextWebSocketFrame)) && binaryData.isReadable()) { body = new byte[binaryData.readableBytes()]; binaryData.readBytes(body); ctx.channel().writeAndFlush(new PongWebSocketFrame(binaryData)); } else if (frame instanceof BinaryWebSocketFrame || (frame instanceof TextWebSocketFrame && config.textFrameAsBinary())) { webSocketProcessor.invokeWebSocketProtocol(attachment, body, 0, body.length); } else if (frame instanceof TextWebSocketFrame) { if (config.enablePong()) { ctx.channel().writeAndFlush(new PingWebSocketFrame(frame.content())); } else {
boolean writeHeader = false; boolean forceSuspend = false; boolean aggregateBodyInMemory = config.aggregateRequestBodyInMemory(); boolean supportChunking = config.supportChunking(); Boolean ka = (Boolean) request.getAttribute(KEEP_ALIVE); asyncWriter = config.supportChunking() ? new ChunkedWriter(ctx.channel(), isLast, ka) : new StreamWriter(ctx.channel(), isLast, ka);
public BridgeRuntime(final Config config) { super(config.path()); this.config = config; framework = new AtmosphereFramework(); if (config.broadcaster() != null) { framework.setDefaultBroadcasterClassName(config.broadcaster().getName()); framework.setAtmosphereDotXmlPath(config.configFile()); if (config.broadcasterFactory() != null) { framework.setBroadcasterFactory(config.broadcasterFactory()); if (config.broadcasterCache() != null) { try { framework.setBroadcasterCacheClassName(config.broadcasterCache().getName()); } catch (Throwable t) { logger.trace("", t); Map<String, AtmosphereHandler> handlersMap = config.handlersMap(); for (Map.Entry<String, AtmosphereHandler> e : handlersMap.entrySet()) { framework.addAtmosphereHandler(e.getKey(), e.getValue()); final Map<String, WebSocketHandler> webSocketHandlerMap = config.webSocketHandlersMap(); if (config.webSocketProtocol() != null) { framework.setWebSocketProtocolClassName(config.webSocketProtocol().getName()); for (AtmosphereInterceptor i : config.interceptors()) { framework.interceptor(i);
config.subProtocols(), false, maxWebSocketFrameSize); wsFactory.sendUnsupportedVersionResponse(ctx.channel()); } else { final NettyWebSocket webSocket = new NettyWebSocket(ctx.channel(), framework.getAtmosphereConfig(), config.noInternalAlloc(), config.binaryWrite()); final AtmosphereRequest atmosphereRequest = createAtmosphereRequest(ctx, request, EMPTY);
ByteBuf binaryData = frame.content(); byte[] body = null; if ((config.textFrameAsBinary() || !(frame instanceof TextWebSocketFrame)) && binaryData.isReadable()) { body = new byte[binaryData.readableBytes()]; binaryData.readBytes(body); ctx.channel().writeAndFlush(new PongWebSocketFrame(binaryData)); } else if (frame instanceof BinaryWebSocketFrame || (frame instanceof TextWebSocketFrame && config.textFrameAsBinary())) { webSocketProcessor.invokeWebSocketProtocol(attachment, body, 0, body.length); } else if (frame instanceof TextWebSocketFrame) { if (config.enablePong()) { ctx.channel().writeAndFlush(new PingWebSocketFrame(frame.content())); } else {
boolean writeHeader = false; boolean forceSuspend = false; boolean aggregateBodyInMemory = config.aggregateRequestBodyInMemory(); boolean supportChunking = config.supportChunking(); Boolean ka = (Boolean) request.getAttribute(KEEP_ALIVE); asyncWriter = config.supportChunking() ? new ChunkedWriter(ctx.channel(), isLast, ka) : new StreamWriter(ctx.channel(), isLast, ka);
@Override protected void initChannel(Channel ch) throws Exception { final ChannelPipeline pipeline = ch.pipeline(); if (config.sslContext() != null) { SSLEngine e = config.sslContext().createSSLEngine(); config.sslContextListener().onPostCreate(e); pipeline.addLast("ssl", new SslHandler(e)); } if (config.nettySslContext() != null) { pipeline.addLast("ssl", config.nettySslContext().newHandler(ch.alloc())); } pipeline.addLast("decoder", new HttpRequestDecoder()); pipeline.addLast("aggregator", new HttpObjectAggregator(config.maxChunkContentLength())); if (config.supportChunking()) { pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); } for (ChannelInboundHandler h: config.channelUpstreamHandlers()) { pipeline.addLast(h.getClass().getName(), h); } pipeline.addLast(new WebSocketServerCompressionHandler()); pipeline.addLast(BridgeRuntime.class.getName(), bridgeRuntime); }
private ServerBootstrap buildBootstrap(Config config) { final ServerBootstrap bootstrap = new ServerBootstrap(); parentGroup = config.epoll() ? new EpollEventLoopGroup() : new NioEventLoopGroup(); childGroup = config.epoll() ? new EpollEventLoopGroup() : new NioEventLoopGroup(); bootstrap .channel(config.epoll() ? EpollServerSocketChannel.class : NioServerSocketChannel.class) .group(parentGroup, childGroup); bootstrap.childHandler(channelInitializer); return bootstrap; }
/** * Build an instance of this class. * * @return this; */ public Config build() { if (paths.isEmpty()) { paths.add("/"); } if (context != null) { if (enabledCipherSuites == null) { throw new IllegalStateException("Incomplete Config: SSLContext requires cipherSuites to be specified."); } if (contextListener == null) { contextListener = new SSLContextListener() { @Override public void onPostCreate(SSLEngine e) { e.setEnabledCipherSuites(enabledCipherSuites); e.setUseClientMode(false); } }; } } return new Config(this); }
private ServerBootstrap buildBootstrapFlashPolicy(Config config) { final ServerBootstrap bootstrap = new ServerBootstrap(); parentGroup = config.epoll() ? new EpollEventLoopGroup() : new NioEventLoopGroup(); childGroup = config.epoll() ? new EpollEventLoopGroup() : new NioEventLoopGroup(); bootstrap .channel(config.epoll() ? EpollServerSocketChannel.class : NioServerSocketChannel.class) .group(parentGroup, childGroup); // Set up the event pipeline factory. bootstrap.childHandler(new FlashPolicyServerChannelInitializer()); return bootstrap; }
private ServerBootstrap buildBootstrapFlashPolicy(Config config) { final ServerBootstrap bootstrap = new ServerBootstrap(); parentGroup = config.epoll() ? new EpollEventLoopGroup() : new NioEventLoopGroup(); childGroup = config.epoll() ? new EpollEventLoopGroup() : new NioEventLoopGroup(); bootstrap .channel(config.epoll() ? EpollServerSocketChannel.class : NioServerSocketChannel.class) .group(parentGroup, childGroup); // Set up the event pipeline factory. bootstrap.childHandler(new FlashPolicyServerChannelInitializer()); return bootstrap; }