Wildfly Dump HTTP Request and Response
While I was working with Wildfly 10.1 upgrade for one my client. The client were asking me How to Dump HTTP request and response in Wildfly? This is made easy in the Wildfly 10.1 if you are interested in HTTP request and response.
In case if you are looking for request body it will not help and mostly you should have your own implementation.
Refer the undertow filter added which is highlighted in bold. You can add them via CLI or edit your standalone.xml directly,
<subsystem xmlns="urn:jboss:domain:undertow:3.1"> <buffer-cache name="default"/> <server name="default-server"> <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/> <https-listener name="https" socket-binding="https" secure="true" security-realm="ApplicationRealm" enable-http2="true"/> <host name="default-host" alias="localhost"> <access-log pattern="%a %l %u %t "%r" %s %b "%{Referer}i"" prefix="access."/> <filter-ref name="http-to-https" predicate="equals(%p,8080)"/> <strong><filter-ref name="request-dumper"/></strong> </host> </server> <servlet-container name="default" stack-trace-on-error="none"> <jsp-config x-powered-by="false" display-source-fragment="false"/> <session-cookie http-only="true" secure="true"/> <websockets/> </servlet-container> <handlers> <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/> </handlers> <filters> <strong><filter name="request-dumper" class-name="io.undertow.server.handlers.RequestDumpingHandler" module="io.undertow.core"/></strong> <rewrite name="http-to-https" target="https://127.0.0.1:9143/%U" redirect="true"/> </filters> </subsystem>
If you were able to configure itcorrect you should see request and response gets printed in the server log like below.
----------------------------REQUEST--------------------------- URI=/myservices/index.html characterEncoding=null contentLength=924 contentType= header=Accept=text/xml header=Connection=keep-alive header=Accept-Encoding=gzip, x-gzip, deflate, x-bzip2 header=content-type=text/xml header=Content-Length=924 header=User-Agent=python-requests/2.18.4 header=Host=127.0.0.1:8780 locale=[] method=POST protocol=HTTP/1.1 queryString= remoteAddr=/127.0.0.1:59193 remoteHost=127.0.0.1 scheme=http host=127.0.0.1:8780 serverPort=8780 --------------------------RESPONSE-------------------------- contentLength=-1 contentType=null header=Connection=keep-alive header=Transfer-Encoding=chunked header=Date=Thu, 10 May 2018 10:10:04 GMT status=200
The request-dumper filter doesn’t work in Wildfly 18. 🙁