use of reactor.netty.http.server.HttpServerResponse 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();
}
}
use of reactor.netty.http.server.HttpServerResponse in project spring-framework by spring-projects.
the class ReactorNettyRequestUpgradeStrategy method upgrade.
@Override
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler, @Nullable String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory) {
ServerHttpResponse response = exchange.getResponse();
HttpServerResponse reactorResponse = ServerHttpResponseDecorator.getNativeResponse(response);
HandshakeInfo handshakeInfo = handshakeInfoFactory.get();
NettyDataBufferFactory bufferFactory = (NettyDataBufferFactory) response.bufferFactory();
URI uri = exchange.getRequest().getURI();
// Trigger WebFlux preCommit actions and upgrade
return response.setComplete().then(Mono.defer(() -> {
WebsocketServerSpec spec = buildSpec(subProtocol);
return reactorResponse.sendWebsocket((in, out) -> {
ReactorNettyWebSocketSession session = new ReactorNettyWebSocketSession(in, out, handshakeInfo, bufferFactory, spec.maxFramePayloadLength());
return handler.handle(session).checkpoint(uri + " [ReactorNettyRequestUpgradeStrategy]");
}, spec);
}));
}
use of reactor.netty.http.server.HttpServerResponse 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);
}
}
}
use of reactor.netty.http.server.HttpServerResponse 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);
}
}
}
Aggregations