logging - 在 WildFly 8 中转储 HTTP 请求

标签 logging wildfly wildfly-8

为了在开发过程中调试 HTTP 请求,我希望我的 WildFly 8 应用程序服务器将 HTTP 请求(包括请求方法和 header )转储到日志文件server.log就可以了。

在WildFly的HTTP子系统的源代码中,我发现RequestDumpingHandler以及相应的日志记录类别 io.undertow.request.dump

但是,我不知道如何安装该 header ,以便将其应用于我的应用程序提供的所有请求(带有一些静态资源和 JAX-RS 处理程序的 WAR)。

相应的文档页面( Undertow web subsystem configuration )并没有真正解释处理程序。有一个<handler>配置部分中的元素

<?xml version="1.0" ?>
<server xmlns="urn:jboss:domain:2.1">
    ...
    <profile>
        ...
        <subsystem xmlns="urn:jboss:domain:undertow:1.1">
        <buffer-cache name="default"/>
        <server name="default-server">
            <http-listener name="default" socket-binding="http"/>
            <host name="default-host" alias="localhost">
                <location name="/" handler="welcome-content"/>
                <filter-ref name="server-header"/>
                <filter-ref name="x-powered-by-header"/>
            </host>
        </server>
        <servlet-container name="default">
            <jsp-config/>
        </servlet-container>
        <handlers>
            <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
            <!-- <dump-request /> ?? or something?-->
        </handlers>
        <filters>
            <response-header name="server-header" header-name="Server" header-value="WildFly/8"/>
            <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
        </filters>
        </subsystem>
        ...
    </profile>
    ...
</server>

但据我所知,只有 <file>预计会有代理(?)。

如何在 WildFly 中记录传入 HTTP 请求的完整详细信息? 我知道我可以在 JAX-RS 层安装一些日志记录机制,但我希望有一个转储机制可以同时处理这两种情况REST API 调用和静态提供的资源。

最佳答案

您需要将 RequestDumpingHandler 添加到您的处理程序链中。

作为 Wildfly 8.1 的一部分,这尚无法以友好的方式实现。

这在 8.2 和 9 中得到了改进,因此您可以通过添加如下内容来配置它:

<host name="default-host" >
     .....
     <filter-ref name="request-dumper"/>
</host>
....
<filters>
    ...
    <filter name="request-dumper" class-name="io.undertow.server.handlers.RequestDumpingHandler" module="io.undertow.core" />
</filters>

在 8.1 中,现在唯一的选择是添加 ServletExtension http://undertow.io/undertow-docs/undertow-docs-1.2.0/#servlet-extensions

这会将此 RequestDumpingHandler 添加到外链。

FWIW 8.2 版本即将准备就绪,因此您可以等待它或者只是为 8.x 分支构建源代码。

要通过 CLI 添加上述配置,您可以使用:

/subsystem=undertow/configuration=filter/custom-filter=request-dumper:add(class-name="io.undertow.server.handlers.RequestDumpingHandler", module="io.undertow.core")
/subsystem=undertow/server=default-server/host=default-host/filter-ref=request-dumper:add

并在调试后删除配置:

/subsystem=undertow/server=default-server/host=default-host/filter-ref=request-dumper:remove
/subsystem=undertow/configuration=filter/custom-filter=request-dumper:remove

关于logging - 在 WildFly 8 中转储 HTTP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26715552/

相关文章:

java - 驻留在 Wildfly 模块中的 JPA 实体类不会被扫描

java - 使用maven-wildfly插件部署webapp,在deployment目录下部署war

java - Wildfly8/jBoss 包装 Logback 日志(双前缀)

java - 如何将 log4j 日志记录集成到我的客户端-服务器程序中?

ruby-on-rails - Rails : How to write to a custom log file from within a rake task in production mode?

jquery - 如何在 jQuery 小部件中切换 console.log?

spring - 获取 java.lang.ClassNotFoundException : org. springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter

java - 从文件上传 Elasticsearch 中的数据

java - 具有独立 ActiveMQ 的 Wildfly 上的 ActiveMQ Artemis

java - 为什么我无法通过 JNDI 使用远程接口(interface)访问我的 EJB?