L'URL est comme http://url.com/username
.Quand client se connecter Server, j'ai besoin de vérifier le nom d'utilisateur dans channelActive, est-ce possible?
MerciComment puis-je obtenir l'URL dans la méthode channelActive() dans netty4.x
public class Handler extends ChannelInboundHandlerAdapter{
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg){
//NOT HERE
}
@Override
public void channelActive(ChannelHandlerContext ctx) {
//1. get username
//2. do some queries with username
}
EDIT: J'ai essayé avec deux gestionnaires pour obtenir l'objet, mais ne fonctionne toujours pas.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new SimpleChannelInboundHandler<Object>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
DB.insert(msg);//insert msg to DB
}
});
pipeline.addLast(new MyHandler());
public class MyHandler extends ChannelInboundHandlerAdapter {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
DB.get();// get msg from DB
ctx.fireChannelActive();
}
J'ai essayé avec deux ChannelInboundHandlers, mais ne fonctionne toujours pas.est-il un autre moyen d'obtenir l'objet @Dmitriy Dumanskiy – uidin
Checkout Exemple http netty - https://github.com/netty/netty/tree/4.1/codec-http –