Search in sources :

Example 1 with ShenyuRequestLog

use of org.apache.shenyu.agent.plugin.logging.entity.ShenyuRequestLog 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;
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) LoggingServerHttpResponse(org.apache.shenyu.agent.plugin.logging.common.body.LoggingServerHttpResponse) LoggingServerHttpRequest(org.apache.shenyu.agent.plugin.logging.common.body.LoggingServerHttpRequest) ServerHttpRequest(org.springframework.http.server.reactive.ServerHttpRequest) LoggingServerHttpRequest(org.apache.shenyu.agent.plugin.logging.common.body.LoggingServerHttpRequest) TargetObject(org.apache.shenyu.agent.api.entity.TargetObject) ShenyuRequestLog(org.apache.shenyu.agent.plugin.logging.entity.ShenyuRequestLog)

Aggregations

TargetObject (org.apache.shenyu.agent.api.entity.TargetObject)1 LoggingServerHttpRequest (org.apache.shenyu.agent.plugin.logging.common.body.LoggingServerHttpRequest)1 LoggingServerHttpResponse (org.apache.shenyu.agent.plugin.logging.common.body.LoggingServerHttpResponse)1 ShenyuRequestLog (org.apache.shenyu.agent.plugin.logging.entity.ShenyuRequestLog)1 ServerHttpRequest (org.springframework.http.server.reactive.ServerHttpRequest)1 ServerWebExchange (org.springframework.web.server.ServerWebExchange)1