在 WildFly 8 中转储 HTTP 请求 [英] Dump HTTP requests in WildFly 8

查看:22
本文介绍了在 WildFly 8 中转储 HTTP 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在开发过程中调试 HTTP 请求,我希望 WildFly 8 应用服务器将 HTTP 请求(包括请求方法和标头)转储到日志文件中.server.log 没问题.

To debug HTTP requests during development, I would like my WildFly 8 application server to dump HTTP requests, including request method and headers, to a log file. server.log would be fine.

在WildFly的HTTP子系统的源码中,我找到了RequestDumpingHandler 和对应的日志分类io.undertow.request.dump

In the sources of WildFly's HTTP subsystem, I found RequestDumpingHandler and the corresponding logging category io.undertow.request.dump

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

However, I cannot figure out, how to install that header so that it is applied for all requests served by my application (a WAR with some static resources and JAX-RS handler).

相应的文档页面(Undertow web 子系统配置)没有并没有真正解释处理程序.配置部分有一个 元素

The corresponding documentation page (Undertow web subsystem configuration) doesn't really explain handlers. There is a <handler> element in the configuration section

<?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>

但据我所知,那里只需要 和代理(?).

but as far as I can tell, only <file> and proxy are expected there(?).

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

How can I log full details of incoming HTTP requests in WildFly? I know I could install some logging mechanism at the JAX-RS layer, but I would like to have one dump mechanism that handles both REST API calls and statically served resources.

推荐答案

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

You would need to add RequestDumpingHandler to your handler chain.

作为 wildfly 8.1 的一部分,这还不能以友好的方式实现.

As part of wildfly 8.1, that is not yet possible in a friendly way.

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

This is improved in 8.2 and 9 so you will be able to configure this by adding something like this:

<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

in 8.1 only option now would be to add ServletExtension http://undertow.io/undertow-docs/undertow-docs-1.2.0/#servlet-extensions

这会将这个 RequestDumpingHandler 添加到外链.

that would add this RequestDumpingHandler to outer chain.

FWIW 8.2 版本即将发布,所以你可以等待它或者只是为 8.x 分支构建源代码.

FWIW 8.2 release is almost ready, so you could wait for it or just build sources for 8.x branch.

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

To add above config via CLI, you can use:

/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

这篇关于在 WildFly 8 中转储 HTTP 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆