Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
596 views
in Technique[技术] by (71.8m points)

logging - Dump HTTP requests in WildFly 8

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.

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

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).

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(?).

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You would need to add RequestDumpingHandler to your handler chain.

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

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>

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

that would add this RequestDumpingHandler to outer chain.

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...