use of io.netty.bootstrap.ServerBootstrap in project vert.x by eclipse.
the class Http2ClientTest method testInvalidServerResponse.
@Test
public void testInvalidServerResponse() throws Exception {
ServerBootstrap bootstrap = createH2Server((dec, enc) -> new Http2EventAdapter() {
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
enc.writeHeaders(ctx, streamId, new DefaultHttp2Headers().status("xyz"), 0, false, ctx.newPromise());
ctx.flush();
}
});
ChannelFuture s = bootstrap.bind(DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT).sync();
try {
Context ctx = vertx.getOrCreateContext();
ctx.runOnContext(v -> {
client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
fail();
}).connectionHandler(conn -> {
conn.exceptionHandler(err -> {
fail();
});
}).exceptionHandler(err -> {
assertOnIOContext(ctx);
if (err instanceof NumberFormatException) {
testComplete();
}
}).end();
});
await();
} finally {
s.channel().close().sync();
}
}
use of io.netty.bootstrap.ServerBootstrap in project vert.x by eclipse.
the class Http2ClientTest method testConnectionWindowSize.
@Test
public void testConnectionWindowSize() throws Exception {
ServerBootstrap bootstrap = createH2Server((decoder, encoder) -> new Http2EventAdapter() {
@Override
public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement) throws Http2Exception {
vertx.runOnContext(v -> {
assertEquals(65535, windowSizeIncrement);
testComplete();
});
}
});
ChannelFuture s = bootstrap.bind(DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT).sync();
client.close();
client = vertx.createHttpClient(new HttpClientOptions(clientOptions).setHttp2ConnectionWindowSize(65535 * 2));
client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
}).exceptionHandler(this::fail).end();
await();
}
use of io.netty.bootstrap.ServerBootstrap in project jersey by jersey.
the class NettyHttpContainerProvider method createServer.
/**
* Create and start Netty server.
*
* @param baseUri base uri.
* @param configuration Jersey configuration.
* @param sslContext Netty SSL context (can be null).
* @param block when {@code true}, this method will block until the server is stopped. When {@code false}, the
* execution will
* end immediately after the server is started.
* @return Netty channel instance.
* @throws ProcessingException when there is an issue with creating new container.
*/
public static Channel createServer(final URI baseUri, final ResourceConfig configuration, SslContext sslContext, final boolean block) throws ProcessingException {
// Configure the server.
final EventLoopGroup bossGroup = new NioEventLoopGroup(1);
final EventLoopGroup workerGroup = new NioEventLoopGroup();
final NettyHttpContainer container = new NettyHttpContainer(configuration);
try {
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024);
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new JerseyServerInitializer(baseUri, sslContext, container));
int port = getPort(baseUri);
Channel ch = b.bind(port).sync().channel();
ch.closeFuture().addListener(new GenericFutureListener<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
container.getApplicationHandler().onShutdown(container);
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
});
if (block) {
ch.closeFuture().sync();
return ch;
} else {
return ch;
}
} catch (InterruptedException e) {
throw new ProcessingException(e);
}
}
use of io.netty.bootstrap.ServerBootstrap in project pinot by linkedin.
the class NettyTCPServer method getServerBootstrap.
@Override
protected ServerBootstrap getServerBootstrap() {
ServerBootstrap b = new ServerBootstrap();
b.group(_bossGroup, _workerGroup).channel(NioServerSocketChannel.class).childHandler(createChannelInitializer()).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);
return b;
}
use of io.netty.bootstrap.ServerBootstrap in project netty-socketio by mrniko.
the class SocketIOServer method startAsync.
/**
* Start server asynchronously
*/
public Future<Void> startAsync() {
log.info("Session store / pubsub factory used: {}", configCopy.getStoreFactory());
initGroups();
pipelineFactory.start(configCopy, namespacesHub);
Class<? extends ServerChannel> channelClass = NioServerSocketChannel.class;
if (configCopy.isUseLinuxNativeEpoll()) {
channelClass = EpollServerSocketChannel.class;
}
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(channelClass).childHandler(pipelineFactory);
applyConnectionOptions(b);
InetSocketAddress addr = new InetSocketAddress(configCopy.getPort());
if (configCopy.getHostname() != null) {
addr = new InetSocketAddress(configCopy.getHostname(), configCopy.getPort());
}
return b.bind(addr).addListener(new FutureListener<Void>() {
@Override
public void operationComplete(Future<Void> future) throws Exception {
if (future.isSuccess()) {
log.info("SocketIO server started at port: {}", configCopy.getPort());
} else {
log.error("SocketIO server start failed at port: {}!", configCopy.getPort());
}
}
});
}
Aggregations