当前位置: 首页>>代码示例>>Java>>正文


Java ExchangeCompletionListener类代码示例

本文整理汇总了Java中io.undertow.server.ExchangeCompletionListener的典型用法代码示例。如果您正苦于以下问题:Java ExchangeCompletionListener类的具体用法?Java ExchangeCompletionListener怎么用?Java ExchangeCompletionListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ExchangeCompletionListener类属于io.undertow.server包,在下文中一共展示了ExchangeCompletionListener类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addExchangeCompleteListener

import io.undertow.server.ExchangeCompletionListener; //导入依赖的package包/类
private void addExchangeCompleteListener(HttpServerExchange exchange, Integer logLevel, final StringBuilder sb, final long start) {
    exchange.addExchangeCompleteListener((final HttpServerExchange exchange1, final ExchangeCompletionListener.NextListener nextListener) -> {
        if (logLevel < 1) {
            return;
        }

        // note sc is always null if this handler is chained before SecurityHandlerDispacher
        final SecurityContext sc = exchange1.getSecurityContext();

        if (logLevel == 1) {
            sb.append(" =>").append(" status=");

            if (exchange.getStatusCode() >= 300
                    && exchange.getStatusCode() != 304) {
                sb.append(ansi().fg(RED).bold().a(exchange.getStatusCode()).reset().toString());
            } else {
                sb.append(ansi().fg(GREEN).bold().a(exchange.getStatusCode()).reset().toString());
            }

            sb.append(" elapsed=")
                    .append(System.currentTimeMillis() - start)
                    .append("ms")
                    .append(" contentLength=").append(exchange1.getResponseContentLength());

            if (sc != null && sc.getAuthenticatedAccount() != null) {
                sb.append(" username=").append(sc.getAuthenticatedAccount().getPrincipal().getName())
                        .append(" roles=").append(sc.getAuthenticatedAccount().getRoles());
            }
        } else if (logLevel >= 2) {
            sb.append("--------------------------RESPONSE--------------------------\n");
            if (sc != null) {
                if (sc.isAuthenticated()) {
                    sb.append("          authType=").append(sc.getMechanismName()).append("\n");
                    sb.append("          username=").append(sc.getAuthenticatedAccount().getPrincipal().getName()).append("\n");
                    sb.append("             roles=").append(sc.getAuthenticatedAccount().getRoles()).append("\n");
                } else {
                    sb.append("          authType=none" + "\n");
                }
            }

            sb.append("     contentLength=").append(exchange1.getResponseContentLength()).append("\n");
            sb.append("       contentType=").append(exchange1.getResponseHeaders().getFirst(Headers.CONTENT_TYPE)).append("\n");
            Map<String, Cookie> cookies1 = exchange1.getResponseCookies();
            if (cookies1 != null) {
                cookies1.values().stream().forEach((cookie) -> {
                    sb.append("            cookie=").append(cookie.getName()).append("=").append(cookie.getValue()).append("; domain=").append(cookie.getDomain()).append("; path=").append(cookie.getPath()).append("\n");
                });
            }
            for (HeaderValues header : exchange1.getResponseHeaders()) {
                header.stream().forEach((value) -> {
                    sb.append("            header=").append(header.getHeaderName()).append("=").append(value).append("\n");
                });
            }
            sb.append("            status=");

            if (exchange.getStatusCode() >= 300) {
                sb.append(ansi().fg(RED).bold().a(exchange1.getStatusCode()).reset().toString());
            } else {
                sb.append(ansi().fg(GREEN).bold().a(exchange1.getStatusCode()).reset().toString());
            }

            sb.append("\n");

            sb.append("           elapsed=").append(System.currentTimeMillis() - start).append("ms\n");
            sb.append("==============================================================");
        }

        nextListener.proceed();
        LOGGER.info(sb.toString());
    });
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:72,代码来源:RequestLoggerHandler.java


注:本文中的io.undertow.server.ExchangeCompletionListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。