}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof FullHttpRequest) {
FullHttpRequest req = (FullHttpRequest) msg;
QueryStringDecoder queryDecoder = new QueryStringDecoder(req.getUri());
List<String> transport = queryDecoder.parameters().get("transport");
if (transport != null && NAME.equals(transport.get(0))) {
List<String> sid = queryDecoder.parameters().get("sid");
List<String> j = queryDecoder.parameters().get("j");
String origin = req.headers().get(HttpHeaders.Names.ORIGIN);
ctx.channel().attr(EncoderHandler.ORIGIN).set(origin);
String userAgent = req.headers().get(HttpHeaders.Names.USER_AGENT);
ctx.channel().attr(EncoderHandler.USER_AGENT).set(userAgent);
if (j != null && j.get(0) != null) {
Integer index = Integer.valueOf(j.get(0));
ctx.channel().attr(EncoderHandler.JSONP_INDEX).set(index);
}
try {
if (sid != null && sid.get(0) != null) {
final UUID sessionId = UUID.fromString(sid.get(0));
handleMessage(req, sessionId, queryDecoder, ctx);
} else {
// first connection
ClientHead client = ctx.channel().attr(ClientHead.CLIENT).get();
handleMessage(req, client.getSessionId(), queryDecoder, ctx);
}
} finally {
req.release();
}
return;
}
}
ctx.fireChannelRead(msg);