List of usage examples for io.netty.channel ChannelHandlerContext fireChannelRead
@Override ChannelHandlerContext fireChannelRead(Object msg);
From source file:io.moquette.server.netty.metrics.MessageMetricsHandler.java
License:Open Source License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { MessageMetrics metrics = ctx.attr(ATTR_KEY_METRICS).get(); metrics.incrementRead(1);//from w w w . j a v a2s .c o m ctx.fireChannelRead(msg); }
From source file:io.moquette.server.netty.metrics.MQTTMessageLogger.java
License:Open Source License
@Override public void channelRead(ChannelHandlerContext ctx, Object message) { logMQTTMessage(ctx, message, "C->B"); ctx.fireChannelRead(message); }
From source file:io.mycat.netty.mysql.MySQLHandshakeHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { logger.info("receive authentication, channel read {}", msg); // handshake should remove here if authenticate success ProtocolTransport transport = new ProtocolTransport(ctx.channel(), (ByteBuf) msg); if (transport.getSession() == null) { userExecutor.execute(new AuthTask(ctx, transport)); } else {//from w ww .ja v a2 s .co m // handshake success, remove self; ctx.pipeline().remove(this); ctx.fireChannelRead(msg); } }
From source file:io.nebo.container.ServletContentHandler.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception { if (msg instanceof HttpRequest) { HttpRequest request = (HttpRequest) msg; log.info("uri" + request.getUri()); HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, false); NettyHttpServletResponse servletResponse = new NettyHttpServletResponse(ctx, servletContext, response); servletRequest = new NettyHttpServletRequest(ctx, servletContext, request, inputStream, servletResponse);//from w ww . j av a 2 s. c om if (HttpMethod.GET.equals(request.getMethod())) { HttpHeaders.setKeepAlive(response, HttpHeaders.isKeepAlive(request)); if (HttpHeaders.is100ContinueExpected(request)) { ctx.write(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE), ctx.voidPromise()); } ctx.fireChannelRead(servletRequest); } else if (HttpMethod.POST.equals(request.getMethod())) { decoder = new HttpPostRequestDecoder(factory, request); } } if (decoder != null && msg instanceof HttpContent) { HttpContent chunk = (HttpContent) msg; log.info("HttpContent" + chunk.content().readableBytes()); inputStream.addContent(chunk); List<InterfaceHttpData> interfaceHttpDatas = decoder.getBodyHttpDatas(); for (InterfaceHttpData data : interfaceHttpDatas) { try { if (data.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute) { Attribute attribute = (Attribute) data; Map<String, String[]> params = servletRequest.getParameterMap(); HttpRequestUtils.setParamMap(attribute.getName(), attribute.getValue(), params); } } finally { // data.release(); } } } if (decoder != null && msg instanceof LastHttpContent) { ctx.fireChannelRead(servletRequest); reset(); } }
From source file:io.netlibs.bgp.handlers.InboundOpenCapabilitiesProcessor.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, OpenPacket open) throws Exception { AutonomousSystem4Capability as4Cap = open.findCapability(AutonomousSystem4Capability.class); ///*from www .ja v a 2 s . c om*/ // TODO decide wether this functionality can and should be removed if (as4Cap != null) { int openASNumber = open.getAutonomousSystem(); int capASNumber = as4Cap.getAutonomousSystem(); if (capASNumber > 65535) { if (openASNumber != BGPv4Constants.BGP_AS_TRANS) { log.error("4 Octet AS numbers must transit AS {} but has {}", BGPv4Constants.BGP_AS_TRANS, openASNumber); NotificationHelper.sendNotification(ctx, new BadPeerASNotificationPacket(), new BgpEventFireChannelFutureListener(ctx)); return; } } else { if (openASNumber != capASNumber) { log.error("4 octet AS number {} not matching 2 octet AS number {} in 2 octet case", capASNumber, openASNumber); NotificationHelper.sendNotification(ctx, new BadPeerASNotificationPacket(), new BgpEventFireChannelFutureListener(ctx)); return; } } } MultiProtocolCapability ipv4UnicastCap = new MultiProtocolCapability(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING); MultiProtocolCapability ipv4AnycastCap = new MultiProtocolCapability(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_UNICAST_MULTICAST_FORWARDING); if (open.getCapabilities().contains(ipv4AnycastCap)) { open.getCapabilities().remove(ipv4AnycastCap); open.getCapabilities().add(ipv4UnicastCap); open.getCapabilities().add(new MultiProtocolCapability(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_MULTICAST_FORWARDING)); } else if (!open.getCapabilities().contains(ipv4UnicastCap)) { open.getCapabilities().add(ipv4UnicastCap); } ctx.fireChannelRead(open); }
From source file:io.netlibs.bgp.netty.handlers.UpdateAttributeChecker.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, Object e) throws Exception { boolean sentUpstream = false; if (e instanceof UpdatePacket) { PeerConnectionInformation connInfo = ctx.attr(BGPv4ClientEndpoint.PEER_CONNECTION_INFO).get(); UpdatePacket update = (UpdatePacket) e; List<PathAttribute> attributeFlagsErrorList = new LinkedList<PathAttribute>(); List<Class<? extends PathAttribute>> missingWellKnownList = new LinkedList<Class<? extends PathAttribute>>(); Set<Class<? extends PathAttribute>> givenAttributes = new HashSet<Class<? extends PathAttribute>>(); // check if passed optional / transitive bits match the presettings of the attribute type for (PathAttribute attribute : update.getPathAttributes()) { boolean badAttr = false; givenAttributes.add(attribute.getClass()); switch (attribute.getCategory()) { case WELL_KNOWN_MANDATORY: case WELL_KNOWN_DISCRETIONARY: badAttr = attribute.isOptional() || !attribute.isTransitive(); break; case OPTIONAL_NON_TRANSITIVE: badAttr = !attribute.isOptional() || attribute.isTransitive(); break; case OPTIONAL_TRANSITIVE: badAttr = !attribute.isOptional() || !attribute.isTransitive(); break; }/*from w w w .j a va 2 s. com*/ if (badAttr) { log.info("detected attribute " + attribute + " with invalid flags"); attributeFlagsErrorList.add(attribute); } } // if we have any bad attribute, generate notification message and leave if (attributeFlagsErrorList.size() > 0) { NotificationHelper.sendNotification(ctx, new AttributeFlagsNotificationPacket(serializeAttributes(attributeFlagsErrorList)), new BgpEventFireChannelFutureListener(ctx)); } else { // check presence of mandatory attributes Set<Class<? extends PathAttribute>> mandatoryAttributes; if (connInfo.isIBGPConnection()) mandatoryAttributes = mandatoryIBGPAttributes; else mandatoryAttributes = mandatoryEBGPAttributes; for (Class<? extends PathAttribute> attrClass : mandatoryAttributes) { if (!givenAttributes.contains(attrClass)) { missingWellKnownList.add(attrClass); } } if (missingWellKnownList.size() > 0) { Map<Class<? extends PathAttribute>, Integer> codeMap; List<NotificationPacket> notifications = new LinkedList<NotificationPacket>(); if (connInfo.isAS4OctetsInUse()) codeMap = as4ClazzCodeMap; else codeMap = as2ClazzCodeMap; if (connInfo.isAS4OctetsInUse()) codeMap = as4ClazzCodeMap; else codeMap = as2ClazzCodeMap; for (Class<? extends PathAttribute> attrClass : missingWellKnownList) { int code = codeMap.get(attrClass); log.info("detected missing well-known atribute, type " + code); notifications.add(new MissingWellKnownAttributeNotificationPacket(code)); } NotificationHelper.sendNotifications(ctx, notifications, new BgpEventFireChannelFutureListener(ctx)); } else { boolean haveBougsWidth = false; // check path attributes for AS number width (2 or 4) settings which mismatch the connection configuration for (PathAttribute attribute : update.getPathAttributes()) { if (attribute instanceof ASTypeAware) { if (((ASTypeAware) attribute).getAsType() != connInfo.getAsTypeInUse()) { haveBougsWidth = true; } } } if (haveBougsWidth) { NotificationHelper.sendNotification(ctx, new MalformedAttributeListNotificationPacket(), new BgpEventFireChannelFutureListener(ctx)); } else sentUpstream = true; } } } else sentUpstream = true; if (sentUpstream) ctx.fireChannelRead(e); }
From source file:io.netlibs.bgp.netty.handlers.ValidateServerIdentifier.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, OpenPacket openPacket) throws Exception { PeerConnectionInformation peerConnInfo = ctx.attr(BGPv4ClientEndpoint.PEER_CONNECTION_INFO).get(); if (openPacket.getBgpIdentifier() != peerConnInfo.getRemoteBgpIdentifier()) { log.error("expected remote BGP identifier {}, received BGP identifier {}", peerConnInfo.getRemoteBgpIdentifier(), openPacket.getBgpIdentifier()); NotificationHelper.sendNotification(ctx, new BadBgpIdentifierNotificationPacket(), new BgpEventFireChannelFutureListener(ctx)); return;//from w ww.jav a2s .c o m } if (peerConnInfo.getRemoteAS() > 65535) { // we must have an AutonomousSystem4 capability at this point in the OPEN packet and a AS_TRANS 2-octet AS number if (openPacket.getAutonomousSystem() != BGPv4Constants.BGP_AS_TRANS) { log.error("expected remote autonomous system {}, received autonomous system {}", BGPv4Constants.BGP_AS_TRANS, openPacket.getAutonomousSystem()); NotificationHelper.sendNotification(ctx, new BadPeerASNotificationPacket(), new BgpEventFireChannelFutureListener(ctx)); return; } AutonomousSystem4Capability as4cap = openPacket.findCapability(AutonomousSystem4Capability.class); if (as4cap == null) { log.error("missing Autonomous system 4-octet capability"); NotificationHelper.sendNotification(ctx, new BadPeerASNotificationPacket(), new BgpEventFireChannelFutureListener(ctx)); return; } if (as4cap.getAutonomousSystem() != peerConnInfo.getRemoteAS()) { log.error("expected remote autonomous system {}, received autonomous system {}", peerConnInfo.getRemoteAS(), as4cap.getAutonomousSystem()); NotificationHelper.sendNotification(ctx, new BadPeerASNotificationPacket(), new BgpEventFireChannelFutureListener(ctx)); return; } } else { if (openPacket.getAutonomousSystem() != peerConnInfo.getRemoteAS()) { log.error("expected remote autonomous system {}, received autonomous system {}", peerConnInfo.getRemoteAS(), openPacket.getAutonomousSystem()); NotificationHelper.sendNotification(ctx, new BadPeerASNotificationPacket(), new BgpEventFireChannelFutureListener(ctx)); return; } // we may have an optional AS4 capability but if we have it it must carry the same AS number as the 2-octet AS number AutonomousSystem4Capability as4cap = openPacket.findCapability(AutonomousSystem4Capability.class); if (as4cap != null) { if (as4cap.getAutonomousSystem() != peerConnInfo.getRemoteAS()) { log.error("expected remote autonomous system {}, received autonomous system {}", peerConnInfo.getRemoteAS(), as4cap.getAutonomousSystem()); NotificationHelper.sendNotification(ctx, new BadPeerASNotificationPacket(), new BgpEventFireChannelFutureListener(ctx)); return; } } } ctx.fireChannelRead(openPacket); }
From source file:io.netty.example.http2.helloworld.frame.server.Http2ServerInitializer.java
License:Apache License
/** * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2.0 *//* www.j a va 2 s .com*/ private void configureClearText(SocketChannel ch) { final ChannelPipeline p = ch.pipeline(); final HttpServerCodec sourceCodec = new HttpServerCodec(); p.addLast(sourceCodec); p.addLast(new HttpServerUpgradeHandler(sourceCodec, upgradeCodecFactory)); p.addLast(new SimpleChannelInboundHandler<HttpMessage>() { @Override protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception { // If this handler is hit then no upgrade has been attempted and the client is just talking HTTP. System.err.println("Directly talking: " + msg.protocolVersion() + " (no upgrade was attempted)"); ChannelPipeline pipeline = ctx.pipeline(); pipeline.addAfter(ctx.name(), null, new HelloWorldHttp1Handler("Direct. No Upgrade Attempted.")); pipeline.replace(this, null, new HttpObjectAggregator(maxHttpContentLength)); ctx.fireChannelRead(ReferenceCountUtil.retain(msg)); } }); p.addLast(new UserEventLogger()); }
From source file:io.netty.example.http2.helloworld.server.Http2ServerInitializer.java
License:Apache License
/** * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2.0 *//* w w w .j ava 2 s.c om*/ private void configureClearText(SocketChannel ch) { final ChannelPipeline p = ch.pipeline(); final HttpServerCodec sourceCodec = new HttpServerCodec(); final HttpServerUpgradeHandler upgradeHandler = new HttpServerUpgradeHandler(sourceCodec, upgradeCodecFactory); final CleartextHttp2ServerUpgradeHandler cleartextHttp2ServerUpgradeHandler = new CleartextHttp2ServerUpgradeHandler( sourceCodec, upgradeHandler, new HelloWorldHttp2HandlerBuilder().build()); p.addLast(cleartextHttp2ServerUpgradeHandler); p.addLast(new SimpleChannelInboundHandler<HttpMessage>() { @Override protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception { // If this handler is hit then no upgrade has been attempted and the client is just talking HTTP. System.err.println("Directly talking: " + msg.protocolVersion() + " (no upgrade was attempted)"); ChannelPipeline pipeline = ctx.pipeline(); pipeline.addAfter(ctx.name(), null, new HelloWorldHttp1Handler("Direct. No Upgrade Attempted.")); pipeline.replace(this, null, new HttpObjectAggregator(maxHttpContentLength)); ctx.fireChannelRead(ReferenceCountUtil.retain(msg)); } }); p.addLast(new UserEventLogger()); }
From source file:io.reactiverse.pgclient.impl.codec.decoder.MessageDecoder.java
License:Apache License
private void decodeNotificationResponse(ChannelHandlerContext ctx, ByteBuf in) { ctx.fireChannelRead( new NotificationResponse(in.readInt(), Util.readCStringUTF8(in), Util.readCStringUTF8(in))); }