May 17
request.getInputStream(): Tomcat vs. Weblogic
-
How it works using Tomcat
So on the server side we use theServletInputStreamof aHttpServletRequestof a standard servlet. On that InputStream we receive data usingrequest.getParameter("param1");and keep calling theis.read(target, transferred , size - transferred);method to read the appended data from InputStream. Once that data was read into abyte[]we write this array to anOutputStream. -
What happens using Weblogic
Everything is done using the standardjavax.servlet.*classes, no Tomcat specific classes so we thought this should work on Weblogic, too. But we were wrong. After I spent a (long) while debugging the problem I found that on Weblogic, once you have accessed some methods (not quite sure which ones)requestobject you can no longer read from theInputStream. It seems to me that Weblogic marks the request as totally processed after reading a request, parameter for example:request.getParameter("param1");(this one is for sure causing the not readability of theInputStream). So once we read the parameter that we needed for further processing we weren't able to read the data appended to the POST request usingis.read(target, transferred , size - transferred);anymore. -
How we got it to work using Weblogic
To solve this problem we now don't put the"param1"value as a parameter, we now put it in the request header. Accessing the header valuerequest.getHeader("param1");leaves theInputStreamthe way we expected it so we are able to read the appended data. -
Question
Maybe someone can answer the question, why are Weblogic and Tomcat handling this differently?
But hey, we got it working. Not even Weblogic was able to stop us. If anything in this post is not clear and you would like to help clarify this but need more information please feel free to contact me or post a comment here.
Update:
Thanks to @royvanrijn I got an explanation for the behaviour described above:The description for the ServletRequest.getParameter(String) method in the Servlet Specification 2.5 contains the following paragraph:
...If the parameter data was sent in the request body, such as occurs with an
HTTP POST request, then reading the body directly via getInputStream()
or getReader() can interfere with the execution of this method...









blog comments powered by Disqus