Search in sources :

Example 1 with HttpServerRequest

use of reactor.netty.http.server.HttpServerRequest in project spring-framework by spring-projects.

the class ReactorHttpHandlerAdapter method apply.

@Override
public Mono<Void> apply(HttpServerRequest reactorRequest, HttpServerResponse reactorResponse) {
    NettyDataBufferFactory bufferFactory = new NettyDataBufferFactory(reactorResponse.alloc());
    try {
        ReactorServerHttpRequest request = new ReactorServerHttpRequest(reactorRequest, bufferFactory);
        ServerHttpResponse response = new ReactorServerHttpResponse(reactorResponse, bufferFactory);
        if (request.getMethod() == HttpMethod.HEAD) {
            response = new HttpHeadResponseDecorator(response);
        }
        return this.httpHandler.handle(request, response).doOnError(ex -> logger.trace(request.getLogPrefix() + "Failed to complete: " + ex.getMessage())).doOnSuccess(aVoid -> logger.trace(request.getLogPrefix() + "Handling completed"));
    } catch (URISyntaxException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to get request URI: " + ex.getMessage());
        }
        reactorResponse.status(HttpResponseStatus.BAD_REQUEST);
        return Mono.empty();
    }
}
Also used : HttpLogging(org.springframework.http.HttpLogging) HttpServerRequest(reactor.netty.http.server.HttpServerRequest) HttpServerResponse(reactor.netty.http.server.HttpServerResponse) NettyDataBufferFactory(org.springframework.core.io.buffer.NettyDataBufferFactory) URISyntaxException(java.net.URISyntaxException) BiFunction(java.util.function.BiFunction) HttpMethod(org.springframework.http.HttpMethod) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Log(org.apache.commons.logging.Log) Mono(reactor.core.publisher.Mono) Assert(org.springframework.util.Assert) URISyntaxException(java.net.URISyntaxException) NettyDataBufferFactory(org.springframework.core.io.buffer.NettyDataBufferFactory)

Example 2 with HttpServerRequest

use of reactor.netty.http.server.HttpServerRequest in project pinpoint by naver.

the class AbstractHttpServerHandleInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    try {
        if (Boolean.FALSE == isReceived(args)) {
            return;
        }
        final HttpServerRequest request = (HttpServerRequest) args[0];
        final HttpServerResponse response = (HttpServerResponse) args[0];
        final int statusCode = getStatusCode(response);
        // must before request listener due to trace block ending
        this.servletResponseListener.destroyed(response, throwable, statusCode);
        this.servletRequestListener.destroyed(request, throwable, statusCode);
    } catch (Throwable t) {
        if (isInfo) {
            logger.info("Failed to servlet request event handle.", t);
        }
    }
}
Also used : HttpServerRequest(reactor.netty.http.server.HttpServerRequest) HttpServerResponse(reactor.netty.http.server.HttpServerResponse)

Example 3 with HttpServerRequest

use of reactor.netty.http.server.HttpServerRequest in project pinpoint by naver.

the class AbstractHttpServerHandleInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    if (traceContext.currentRawTraceObject() != null) {
        if (isDisconnecting(args)) {
            final AsyncContext asyncContext = AsyncContextAccessorUtils.getAsyncContext(args, 0);
            if (asyncContext != null) {
                if (asyncContext instanceof AsyncStateSupport) {
                    final AsyncStateSupport asyncStateSupport = (AsyncStateSupport) asyncContext;
                    AsyncState asyncState = asyncStateSupport.getAsyncState();
                    asyncState.finish();
                    if (isDebug) {
                        logger.debug("Finished asyncState. asyncTraceId={}", asyncContext);
                    }
                }
            }
        }
        // duplicate trace.
        return;
    }
    try {
        if (Boolean.FALSE == isReceived(args)) {
            // invalid args
            return;
        }
        final HttpServerRequest request = (HttpServerRequest) args[0];
        final HttpServerResponse response = (HttpServerResponse) args[0];
        this.servletRequestListener.initialized(request, ReactorNettyConstants.REACTOR_NETTY_INTERNAL, this.methodDescriptor);
        // must after request listener due to trace block begin
        this.servletResponseListener.initialized(response, ReactorNettyConstants.REACTOR_NETTY_INTERNAL, this.methodDescriptor);
        // Set end-point
        final Trace trace = this.traceContext.currentTraceObject();
        if (trace == null) {
            return;
        }
        final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        if (recorder != null) {
            // make asynchronous trace-id
            final boolean asyncStateSupport = enableAsyncEndPoint;
            final AsyncContext asyncContext = recorder.recordNextAsyncContext(asyncStateSupport);
            ((AsyncContextAccessor) args[0])._$PINPOINT$_setAsyncContext(asyncContext);
            if (isDebug) {
                if (enableAsyncEndPoint) {
                    logger.debug("Set closeable-AsyncContext {}", asyncContext);
                } else {
                    logger.debug("Set AsyncContext {}", asyncContext);
                }
            }
        }
    } catch (Throwable t) {
        if (isInfo) {
            logger.info("Failed to servlet request event handle.", t);
        }
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) AsyncState(com.navercorp.pinpoint.bootstrap.context.AsyncState) HttpServerRequest(reactor.netty.http.server.HttpServerRequest) HttpServerResponse(reactor.netty.http.server.HttpServerResponse) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext) AsyncStateSupport(com.navercorp.pinpoint.bootstrap.context.AsyncStateSupport)

Aggregations

HttpServerRequest (reactor.netty.http.server.HttpServerRequest)3 HttpServerResponse (reactor.netty.http.server.HttpServerResponse)3 AsyncContextAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor)1 AsyncContext (com.navercorp.pinpoint.bootstrap.context.AsyncContext)1 AsyncState (com.navercorp.pinpoint.bootstrap.context.AsyncState)1 AsyncStateSupport (com.navercorp.pinpoint.bootstrap.context.AsyncStateSupport)1 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)1 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)1 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)1 URISyntaxException (java.net.URISyntaxException)1 BiFunction (java.util.function.BiFunction)1 Log (org.apache.commons.logging.Log)1 NettyDataBufferFactory (org.springframework.core.io.buffer.NettyDataBufferFactory)1 HttpLogging (org.springframework.http.HttpLogging)1 HttpMethod (org.springframework.http.HttpMethod)1 Assert (org.springframework.util.Assert)1 Mono (reactor.core.publisher.Mono)1