use of org.jboss.netty.handler.codec.http.HttpRequestDecoder in project weave by continuuity.
the class TrackerService method startUp.
@Override
protected void startUp() throws Exception {
Executor bossThreads = Executors.newFixedThreadPool(NUM_BOSS_THREADS, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("boss-thread").build());
Executor workerThreads = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("worker-thread#%d").build());
ChannelFactory factory = new NioServerSocketChannelFactory(bossThreads, workerThreads);
bootstrap = new ServerBootstrap(factory);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() {
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("aggregator", new HttpChunkAggregator(MAX_INPUT_SIZE));
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("compressor", new HttpContentCompressor());
pipeline.addLast("handler", new ReportHandler(resourceReport));
return pipeline;
}
});
Channel channel = bootstrap.bind(new InetSocketAddress(host, 0));
bindAddress = (InetSocketAddress) channel.getLocalAddress();
url = URI.create(String.format("http://%s:%d", host, bindAddress.getPort())).resolve(TrackerService.PATH).toURL();
channelGroup.add(channel);
}
use of org.jboss.netty.handler.codec.http.HttpRequestDecoder in project graylog2-server by Graylog2.
the class HttpTransport method getBaseChannelHandlers.
@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getBaseChannelHandlers(MessageInput input) {
final LinkedHashMap<String, Callable<? extends ChannelHandler>> baseChannelHandlers = super.getBaseChannelHandlers(input);
if (idleWriterTimeout > 0) {
// Install read timeout handler to close idle connections after a timeout.
// This avoids dangling HTTP connections when the HTTP client does not close the connection properly.
// For details see: https://github.com/Graylog2/graylog2-server/issues/3223#issuecomment-270350500
baseChannelHandlers.put("read-timeout-handler", () -> new ReadTimeoutHandler(timer, idleWriterTimeout, TimeUnit.SECONDS));
}
baseChannelHandlers.put("decoder", () -> new HttpRequestDecoder(DEFAULT_MAX_INITIAL_LINE_LENGTH, DEFAULT_MAX_HEADER_SIZE, maxChunkSize));
baseChannelHandlers.put("aggregator", () -> new HttpChunkAggregator(maxChunkSize));
baseChannelHandlers.put("encoder", HttpResponseEncoder::new);
baseChannelHandlers.put("decompressor", HttpContentDecompressor::new);
return baseChannelHandlers;
}
use of org.jboss.netty.handler.codec.http.HttpRequestDecoder in project camel by apache.
the class HttpServerSharedPipelineFactory method getPipeline.
@Override
public ChannelPipeline getPipeline() throws Exception {
// Create a default pipeline implementation.
ChannelPipeline pipeline = Channels.pipeline();
SslHandler sslHandler = configureServerSSLOnDemand();
if (sslHandler != null) {
LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
pipeline.addLast("ssl", sslHandler);
}
pipeline.addLast("decoder", new HttpRequestDecoder(4096, configuration.getMaxHeaderSize(), 8192));
if (configuration.isChunked()) {
pipeline.addLast("aggregator", new HttpChunkAggregator(configuration.getChunkedMaxContentLength()));
}
pipeline.addLast("encoder", new HttpResponseEncoder());
if (configuration.isCompression()) {
pipeline.addLast("deflater", new HttpContentCompressor());
}
pipeline.addLast("handler", channelFactory.getChannelHandler());
return pipeline;
}
use of org.jboss.netty.handler.codec.http.HttpRequestDecoder in project cdap by caskdata.
the class NettyRouter method bootstrapServer.
private void bootstrapServer(final ChannelUpstreamHandler connectionTracker) throws ServiceBindException {
ExecutorService serverBossExecutor = createExecutorService(serverBossThreadPoolSize, "router-server-boss-thread-%d");
ExecutorService serverWorkerExecutor = createExecutorService(serverWorkerThreadPoolSize, "router-server-worker-thread-%d");
serverBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(serverBossExecutor, serverWorkerExecutor));
serverBootstrap.setOption("backlog", serverConnectionBacklog);
serverBootstrap.setOption("child.bufferFactory", new DirectChannelBufferFactory());
// Setup the pipeline factory
serverBootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
if (isSSLEnabled()) {
// Add SSLHandler is SSL is enabled
pipeline.addLast("ssl", sslHandlerFactory.create());
}
pipeline.addLast("tracker", connectionTracker);
pipeline.addLast("http-response-encoder", new HttpResponseEncoder());
pipeline.addLast("http-decoder", new HttpRequestDecoder());
pipeline.addLast("http-status-request-handler", new HttpStatusRequestHandler());
if (securityEnabled) {
pipeline.addLast("access-token-authenticator", new SecurityAuthenticationHttpHandler(realm, tokenValidator, configuration, accessTokenTransformer, discoveryServiceClient));
}
// for now there's only one hardcoded rule, but if there will be more, we may want it generic and configurable
pipeline.addLast("http-request-handler", new HttpRequestHandler(clientBootstrap, serviceLookup, ImmutableList.<ProxyRule>of()));
return pipeline;
}
});
// Start listening on ports.
ImmutableMap.Builder<Integer, String> serviceMapBuilder = ImmutableMap.builder();
for (Map.Entry<String, Integer> forward : serviceToPortMap.entrySet()) {
int port = forward.getValue();
String service = forward.getKey();
String boundService = serviceLookup.getService(port);
if (boundService != null) {
LOG.warn("Port {} is already configured to service {}, ignoring forward for service {}", port, boundService, service);
continue;
}
InetSocketAddress bindAddress = new InetSocketAddress(hostname, port);
LOG.info("Starting Netty Router for service {} on address {}...", service, bindAddress);
try {
Channel channel = serverBootstrap.bind(bindAddress);
InetSocketAddress boundAddress = (InetSocketAddress) channel.getLocalAddress();
serviceMapBuilder.put(boundAddress.getPort(), service);
channelGroup.add(channel);
// Update service map
serviceLookup.updateServiceMap(serviceMapBuilder.build());
LOG.info("Started Netty Router for service {} on address {}.", service, boundAddress);
} catch (ChannelException e) {
if ((Throwables.getRootCause(e) instanceof BindException)) {
throw new ServiceBindException("Router", hostname.getCanonicalHostName(), port, e);
}
throw e;
}
}
}
use of org.jboss.netty.handler.codec.http.HttpRequestDecoder in project sockjs-netty by cgbystrom.
the class StressTestServer method start.
public void start() throws Exception {
final JmxReporter reporter = JmxReporter.forRegistry(registry).build();
final ServiceRouter router = new ServiceRouter();
reporter.start();
router.setMetricRegistry(registry);
Service echoService = new Service("/stresstest", new SessionCallbackFactory() {
@Override
public StressTestSession getSession(String id) throws Exception {
return new StressTestSession();
}
});
router.registerService(echoService);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = pipeline();
pipeline.addLast("decoder", new HttpRequestDecoder());
// Required for WS handshaker or else NPE.
pipeline.addLast("chunkAggregator", new HttpChunkAggregator(130 * 1024));
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("preflight", new PreflightHandler());
pipeline.addLast("router", router);
return pipeline;
}
});
bootstrap.bind(new LocalAddress(port));
}
Aggregations