use of io.micronaut.http.context.event.HttpRequestReceivedEvent in project micronaut-core by micronaut-projects.
the class HttpRequestDecoder method decode.
@Override
protected void decode(ChannelHandlerContext ctx, HttpRequest msg, List<Object> out) {
if (LOG.isTraceEnabled()) {
LOG.trace("Server {}:{} Received Request: {} {}", embeddedServer.getHost(), embeddedServer.getPort(), msg.method(), msg.uri());
}
try {
NettyHttpRequest<Object> request = new NettyHttpRequest<>(msg, ctx, conversionService, configuration);
if (httpRequestReceivedEventPublisher != ApplicationEventPublisher.NO_OP) {
try {
ctx.executor().execute(() -> {
try {
httpRequestReceivedEventPublisher.publishEvent(new HttpRequestReceivedEvent(request));
} catch (Exception e) {
if (LOG.isErrorEnabled()) {
LOG.error("Error publishing Http request received event: " + e.getMessage(), e);
}
}
});
} catch (Exception e) {
if (LOG.isErrorEnabled()) {
LOG.error("Error publishing Http request received event: " + e.getMessage(), e);
}
}
}
out.add(request);
} catch (IllegalArgumentException e) {
// this configured the request in the channel as an attribute
new NettyHttpRequest<>(new DefaultHttpRequest(msg.protocolVersion(), msg.method(), "/"), ctx, conversionService, configuration);
final Throwable cause = e.getCause();
ctx.fireExceptionCaught(cause != null ? cause : e);
if (msg instanceof StreamedHttpRequest) {
// discard any data that may come in
((StreamedHttpRequest) msg).closeIfNoSubscriber();
}
}
}
Aggregations