Search in sources :

Example 1 with RequestLogMessage

use of com.dtflys.forest.logging.RequestLogMessage in project forest by dromara.

the class AbstractHttpclientRequestSender method logRequest.

public <T extends HttpRequestBase> void logRequest(int retryCount, T httpReq) {
    LogConfiguration logConfiguration = request.getLogConfiguration();
    if (!logConfiguration.isLogEnabled() || !logConfiguration.isLogRequest()) {
        return;
    }
    RequestLogMessage logMessage = getRequestLogMessage(retryCount, httpReq);
    logMessage.setRequest(request);
    request.setRequestLogMessage(logMessage);
    ForestLogHandler logHandler = request.getLogConfiguration().getLogHandler();
    if (logHandler != null) {
        logHandler.logRequest(logMessage);
    }
}
Also used : RequestLogMessage(com.dtflys.forest.logging.RequestLogMessage) ForestLogHandler(com.dtflys.forest.logging.ForestLogHandler) LogConfiguration(com.dtflys.forest.logging.LogConfiguration)

Example 2 with RequestLogMessage

use of com.dtflys.forest.logging.RequestLogMessage in project forest by dromara.

the class OkHttp3Executor method logRequest.

public void logRequest(int retryCount, Request okRequest, OkHttpClient okHttpClient) {
    LogConfiguration logConfiguration = request.getLogConfiguration();
    if (!logConfiguration.isLogEnabled() || !logConfiguration.isLogRequest()) {
        return;
    }
    RequestLogMessage logMessage = buildRequestMessage(retryCount, okRequest);
    logMessage.setRequest(request);
    logMessage.setRetryCount(retryCount);
    Proxy proxy = okHttpClient.proxy();
    if (proxy != null) {
        RequestProxyLogMessage proxyLogMessage = new RequestProxyLogMessage();
        SocketAddress address = proxy.address();
        if (address instanceof InetSocketAddress) {
            InetSocketAddress inetSocketAddress = (InetSocketAddress) address;
            proxyLogMessage.setHost(inetSocketAddress.getHostString());
            proxyLogMessage.setPort(inetSocketAddress.getPort() + "");
            logMessage.setProxy(proxyLogMessage);
        }
    }
    request.setRequestLogMessage(logMessage);
    logConfiguration.getLogHandler().logRequest(logMessage);
}
Also used : RequestLogMessage(com.dtflys.forest.logging.RequestLogMessage) Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) RequestProxyLogMessage(com.dtflys.forest.logging.RequestProxyLogMessage) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) LogConfiguration(com.dtflys.forest.logging.LogConfiguration)

Example 3 with RequestLogMessage

use of com.dtflys.forest.logging.RequestLogMessage in project forest by dromara.

the class OkHttp3Executor method buildRequestMessage.

protected RequestLogMessage buildRequestMessage(int retryCount, Request okRequest) {
    RequestLogMessage message = new RequestLogMessage();
    HttpUrl url = okRequest.url();
    String scheme = url.scheme().toUpperCase();
    String uri = url.uri().toString();
    String method = okRequest.method();
    message.setUri(uri);
    message.setType(method);
    message.setScheme(scheme);
    message.setRetryCount(retryCount);
    setLogHeaders(message, okRequest);
    setLogBody(message, okRequest);
    return message;
}
Also used : RequestLogMessage(com.dtflys.forest.logging.RequestLogMessage) HttpUrl(okhttp3.HttpUrl)

Example 4 with RequestLogMessage

use of com.dtflys.forest.logging.RequestLogMessage in project forest by dromara.

the class AbstractHttpclientRequestSender method getRequestLogMessage.

private <T extends HttpRequestBase> RequestLogMessage getRequestLogMessage(int retryCount, T httpReq) {
    RequestLogMessage logMessage = new RequestLogMessage();
    URI uri = httpReq.getURI();
    logMessage.setUri(uri.toASCIIString());
    logMessage.setType(httpReq.getMethod());
    logMessage.setScheme(uri.getScheme());
    logMessage.setRetryCount(retryCount);
    setLogHeaders(logMessage, httpReq);
    setLogBody(logMessage, httpReq);
    ForestProxy proxy = request.getProxy();
    if (proxy != null) {
        RequestProxyLogMessage proxyLogMessage = new RequestProxyLogMessage();
        proxyLogMessage.setHost(proxy.getHost());
        proxyLogMessage.setPort(proxy.getPort() + "");
        logMessage.setProxy(proxyLogMessage);
    }
    return logMessage;
}
Also used : RequestLogMessage(com.dtflys.forest.logging.RequestLogMessage) RequestProxyLogMessage(com.dtflys.forest.logging.RequestProxyLogMessage) URI(java.net.URI) ForestProxy(com.dtflys.forest.http.ForestProxy)

Aggregations

RequestLogMessage (com.dtflys.forest.logging.RequestLogMessage)4 LogConfiguration (com.dtflys.forest.logging.LogConfiguration)2 RequestProxyLogMessage (com.dtflys.forest.logging.RequestProxyLogMessage)2 ForestProxy (com.dtflys.forest.http.ForestProxy)1 ForestLogHandler (com.dtflys.forest.logging.ForestLogHandler)1 InetSocketAddress (java.net.InetSocketAddress)1 Proxy (java.net.Proxy)1 SocketAddress (java.net.SocketAddress)1 URI (java.net.URI)1 HttpUrl (okhttp3.HttpUrl)1