Netty - configuration du pipeline
Bonjour,
Qui se sert de Netty ici et serait susceptible de m'aider?
J'ai un problème de configuration du pipeline et je ne trouve pas d'où il vient malgré mes recherches. Voici le message d'erreur que j'ai:
"reached at the tail of the pipeline. Please check your pipeline configuration".
Entre autres, c'est un problème de disponiblité des handler si j'ai bien compris. Je n'en ai pas de disponible pour traiter ma requee HTTP.
Voici le code de mon serveur:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| public static void main(String... args) {
try {
new NettyServer().start();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("API started on port {}", PORT);
}
} catch (final Exception e) {
LOGGER.error("Unable to start API server", e);
}
}
static final boolean SSL = System.getProperty("ssl") != null;
// Use the same default port with the telnet example so that we can use the telnet client example to access it.
static final int PORT = Integer.parseInt(System.getProperty("port", SSL? "8992" : "8080"));
public void start() throws Exception {
// Configure SSL.
final SslContext sslCtx;
if (SSL) {
SelfSignedCertificate ssc = new SelfSignedCertificate();
sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
} else {
sslCtx = null;
}
// Configure the server.
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
// try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 100)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new NettyServerInitializer(sslCtx) {
});
// Start the server.
ChannelFuture f = b.bind(PORT).sync();
// Wait until the server socket is closed.
// f.channel().closeFuture().sync();
/* } finally {
// Shut down all event loops to terminate all threads.
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}*/
}
} |
et voici le code de son initialisation:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| public class NettyServerInitializer extends ChannelInitializer<SocketChannel> {
private final SslContext sslCtx;
public NettyServerInitializer(SslContext sslCtx) {
this.sslCtx = sslCtx;
}
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc()));
}
p.addLast(
new StringEncoder(CharsetUtil.UTF_8),
new LineBasedFrameDecoder(8192),
new StringDecoder(CharsetUtil.UTF_8),
new ChunkedWriteHandler(),
new NettyServerHandler());
p.addLast(new HttpRequestDecoder());
p.addLast(new HttpResponseEncoder());
// Remove the following line if you don't want automatic content compression.
p.addLast(new HttpContentCompressor());
p.addLast( "http-aggregator", new HttpObjectAggregator( 1024 ) );
}
} |
Grand merci d'avance pour votre aide et vos idées.