use of org.apache.shenyu.agent.plugin.logging.common.body.LoggingServerHttpRequest in project incubator-shenyu by apache.
the class DefaultLoggingPluginHandler method after.
@Override
public Object after(final TargetObject target, final Method method, final Object[] args, final MethodResult methodResult) {
Object result = methodResult.getResult();
ServerWebExchange exchange = (ServerWebExchange) result;
ServerHttpRequest request = exchange.getRequest();
// control sampling
if (!LogCollectConfigUtils.isSampled(request)) {
return methodResult.getResult();
}
ShenyuRequestLog requestInfo = new ShenyuRequestLog();
requestInfo.setRequestUri(request.getURI().toString());
requestInfo.setMethod(request.getMethodValue());
requestInfo.setRequestHeader(LogCollectUtils.getRequestHeaders(request.getHeaders()));
requestInfo.setQueryParams(request.getURI().getQuery());
requestInfo.setClientIp(HostAddressUtils.acquireIp(exchange));
requestInfo.setUserAgent(request.getHeaders().getFirst(USER_AGENT));
requestInfo.setHost(request.getHeaders().getFirst(HOST));
requestInfo.setPath(request.getURI().getPath());
LoggingServerHttpRequest loggingServerHttpRequest = new LoggingServerHttpRequest(request, requestInfo);
LoggingServerHttpResponse loggingServerHttpResponse = new LoggingServerHttpResponse(exchange.getResponse(), requestInfo, DefaultLogCollector.getInstance());
ServerWebExchange webExchange = exchange.mutate().request(loggingServerHttpRequest).response(loggingServerHttpResponse).build();
loggingServerHttpResponse.setExchange(webExchange);
return webExchange;
}
Aggregations