Search in sources :

Example 1 with ActionLog

use of com.jeesuite.logging.integrate.ActionLog in project jeesuite-libs by vakinge.

the class ResponseLogHandler method process.

@Override
public Object process(RequestContext ctx, HttpServletRequest request, BizSystemModule module) {
    int statusCode = ctx.getResponseStatusCode();
    if (statusCode != 200)
        return null;
    ActionLog actionLog = ActionLogCollector.currentActionLog();
    if (actionLog == null)
        return null;
    List<Pair<String, String>> headers = ctx.getOriginResponseHeaders();
    for (Pair<String, String> pair : headers) {
        if (CustomRequestHeaders.HEADER_EXCEPTION_CODE.equals(pair.first())) {
            actionLog.setResponseCode(Integer.parseInt(pair.second()));
            break;
        }
    }
    if (ignoreBody)
        return null;
    ApiInfo apiInfo = module.getApiInfo(request.getRequestURI());
    if (apiInfo != null && !apiInfo.isResponseLog()) {
        return null;
    }
    ResponseCompose responseCompose = new ResponseCompose(ctx);
    ctx.set(ResponseCompose.class.getName(), responseCompose);
    actionLog.setResponseData(responseCompose.getBodyString());
    return null;
}
Also used : ApiInfo(com.jeesuite.common.model.ApiInfo) ActionLog(com.jeesuite.logging.integrate.ActionLog) Pair(com.netflix.util.Pair)

Example 2 with ActionLog

use of com.jeesuite.logging.integrate.ActionLog in project jeesuite-libs by vakinge.

the class RequestLogHandler method process.

@Override
public Object process(RequestContext ctx, HttpServletRequest request, BizSystemModule module) {
    ActionLog actionLog = ActionLogCollector.currentActionLog();
    if (actionLog == null)
        return null;
    actionLog.setModuleId(module.getServiceId());
    ApiInfo apiInfo = module.getApiInfo(request.getRequestURI());
    if (apiInfo != null && !apiInfo.isRequestLog()) {
        return null;
    }
    actionLog.setQueryParameters(request.getQueryString());
    if (!ignoreBody && HttpMethod.POST.name().equals(request.getMethod()) && !WebUtils.isMultipartContent(request)) {
        try {
            String data = CharStreams.toString(new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8));
            actionLog.setRequestData(data);
        } catch (Exception e) {
        }
    }
    return null;
}
Also used : InputStreamReader(java.io.InputStreamReader) ApiInfo(com.jeesuite.common.model.ApiInfo) ActionLog(com.jeesuite.logging.integrate.ActionLog)

Aggregations

ApiInfo (com.jeesuite.common.model.ApiInfo)2 ActionLog (com.jeesuite.logging.integrate.ActionLog)2 Pair (com.netflix.util.Pair)1 InputStreamReader (java.io.InputStreamReader)1