Why is the POST body unavailable to my servlet when the RequestDumperValve is enabled?
Environment
-
JBoss Enterprise Applicatoin Platform (EAP) 4.x
-
JBoss Enterprise Applicatoin Platform (EAP) 5.x
Issue
- A client executes an HTTP POST containing a payload that a servlet parses. When the RequestDumperValve is enabled, the payload is no longer available to the servlet.
Resolution
- Explicitly set the ContentType on the client to something other than application/x-ww-form-urlencoded; e.g., application/soap+xml
Root Cause
- The client either is not specifying a ContentType header or is specifying a ContentType of application/x-www-form-urlencoded.
- When the RequestDumperValve is enabled, it repeatedly calls ServletRequest#getParameter(java.lang.String) for each parameter, which causes the ServletInputStream to be read and parsed into parameters if the ContentType is application/x-www-form-urlencoded.
- Thus, when the servlet recieves the request, the POST body is no longer available.
Diagnostic Steps
- Execute the client without and then with the RequestDumperValve enabled.
- If POST is still unavailable when removing the RequestDumperValve use Byteman to determine what is calling the getInputStream prematurely, most likely another filter: Using Byteman to troubleshoot Java issues
Notes
The javadoc for ServletRequest#getParameter [0] warns about processing of the input stream because of the parsing it will do on its own.
The w3c states [1] that application/x-www-form-urlencoded is the default content-type for form submissions.
[0] Content from docs.oracle.com is not included.Content from docs.oracle.com is not included.http://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html#getParameter%28java.lang.String%29
[1] Content from www.w3.org is not included.Content from www.w3.org is not included.http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.