Class MoleculerHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.SimpleChannelInboundHandler<Object>
services.moleculer.web.netty.MoleculerHandler
- All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final services.moleculer.ServiceBrokerprotected final ApiGatewayprotected io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerprotected Stringprotected NettyWebRequestprotected final NettyWebSocketRegistry -
Constructor Summary
ConstructorsConstructorDescriptionMoleculerHandler(ApiGateway gateway, services.moleculer.ServiceBroker broker, NettyWebSocketRegistry nettyWebSocketRegistry) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidabortRequestStream(Throwable cause) Sends an error to the in-flight request body stream (if any), releasing downstream resources.voidchannelInactive(io.netty.channel.ChannelHandlerContext ctx) Releases the half-open request stream when the connection drops in the middle of an upload, so a waiting action does not leak the stream.protected voidchannelRead0(io.netty.channel.ChannelHandlerContext ctx, Object request) voidexceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) Aborts the request stream and closes the channel on a transport-level error (e.g. an HTTP decoder failure on a malformed request, or a reset by the peer).protected booleanCheap, allocation-free check for an in-flight request body stream that is still open.voiduserEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object evt) Closes connections that go silent while an HTTP request is still being read.Methods inherited from class io.netty.channel.SimpleChannelInboundHandler
acceptInboundMessage, channelReadMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChangedMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
Field Details
-
gateway
-
broker
protected final services.moleculer.ServiceBroker broker -
req
-
webSocketRegistry
-
path
-
handshaker
protected volatile io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker handshaker
-
-
Constructor Details
-
MoleculerHandler
public MoleculerHandler(ApiGateway gateway, services.moleculer.ServiceBroker broker, NettyWebSocketRegistry nettyWebSocketRegistry)
-
-
Method Details
-
channelRead0
-
userEventTriggered
public void userEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object evt) throws Exception Closes connections that go silent while an HTTP request is still being read. TheIdleStateHandler(added by theNettyServeronly when a read-timeout is configured) fires a reader-idle event; we abort any half-received request body and close the channel. This is the Slowloris defence. Established WebSockets never reach this code, because the idle handler is removed from the pipeline on a successful handshake.- Specified by:
userEventTriggeredin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
userEventTriggeredin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelInactive
Releases the half-open request stream when the connection drops in the middle of an upload, so a waiting action does not leak the stream. Runs on every connection close, so it allocates the exception only when there is actually an in-flight body stream to abort (the abnormal case) - a normal, completed request takes the cheap, allocation-free path.- Specified by:
channelInactivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelInactivein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
exceptionCaught
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception Aborts the request stream and closes the channel on a transport-level error (e.g. an HTTP decoder failure on a malformed request, or a reset by the peer). Closing silently here also avoids log-flooding from malformed or malicious clients.- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelHandler- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
exceptionCaughtin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
isRequestStreamOpen
protected boolean isRequestStreamOpen()Cheap, allocation-free check for an in-flight request body stream that is still open. Used to skip building an exception on the common path (no body, or the request already completed).- Returns:
- true if there is an open request body stream to abort
-
abortRequestStream
Sends an error to the in-flight request body stream (if any), releasing downstream resources. Idempotent:PacketStream.sendErroris a no-op once the stream is closed.- Parameters:
cause- the reason the request was aborted (never null)
-