Chris,

1) Does it make sense to call ServletRequest#getInputStream after
ServletRequest#getReader? No, and consequently it will throw
IllegalStateException.
2) Does it make sense to call ServletRequest#getInputStream after
ServletRequest#getPart/s? No, but it returns an empty stream instead of
throwing IllegalStateException.

These behaviours are not consistent.

Best regards,

{
  "blog" :
    "https://blog.behrang.org";,
  "twitter":
     "https://twitter.com/behrangsa";,
  "github":
     "https://github.com/behrangsa/";,
  "stackoverflow":
     "https://stackoverflow.com/users/309683?tab=profile"}



On Thu, Dec 12, 2019 at 4:31 AM Christopher Schultz <
ch...@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> André,
>
> On 12/10/19 16:47, André Warnier (tomcat/perl) wrote:
> > On 10.12.2019 15:31, Christopher Schultz wrote:
> >> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
> >>
> >> Behrang,
> >>
> >> On 12/8/19 05:18, Behrang Saeedzadeh wrote:
> >>> If I call javax.servlet.ServletRequest#getInputStream after
> >>> having called javax.servlet.http.HttpServletRequest#getPart,
> >>> even without performing any operations on the given part, I am
> >>> getting an empty stream (0-bytes).
> >>>
> >>> Is this in compliance with the spec?
> >>
> >> What does the servlet spec say about that situation?
> >>
> >
> > A bit in defense of the OP, I have to say that the Servlet Spec
> > (4.0 final) does not seem extremely clear on that subject.
>
> While I appreciate your research activities, I was hoping the OP would
> actually read the spec to get some clarification.
>
> > In section "3.1.1 When Parameters Are Available", it /does/ say
> > this :
> >
> > "If the conditions are met, post form data will no longer be
> > available for reading directly from the request object’s input
> > stream."
> >
> > But among those conditions that have to be met (just above that
> > quote) is "4. The servlet has made an initial call of any of the
> > "getParameter family" of methods on the request object."
> >
> > (So there, it talks about "the getParameter family", not the
> > "getPart" ones).
> >
> > It only talks about the "getPart" methods in the next section "3.2
> > File upload", and in that section, all it says about the input
> > stream is : "If the servlet container does not provide the
> > multi-part/form-data processing, the data will be available through
> > the HttpServletReuqest.getInputStream."
> >
> > So the way I read this, is that there is nothing that explicitly
> > says that the InputStream is no longer available if you have called
> > "getPart".
>
> The only reason the container would process multi-part/form-data
> requests is if you called request.getPart*. Therefore, the InputStream
> is no longer available.
>
> > (It is also in fact not very clear about what happens to the
> > parameters, when the content-type of the Request is
> > "multipart/form-data", which is only mentioned in section 3.2.)
>
> Normal parameters are available via request.getParameter*. You can
> also go through the agony of getPart("foo").getInputStream() if you'd
> like. This is documented in section 3.2 "File Upload".
>
> > On the other hand,
> > http://tomcat.apache.org/tomcat-9.0-doc/servletapi/index.html -->
> > Interface HttpServletRequest says :
> >
> > Part getPart(java.lang.String name) throws java.io.IOException,
> > ServletException Gets the named Part or null if the Part does not
> > exist. *Triggers upload of all Parts*. (emphasis mine)
> >
> > which /may/ be taken to mean (and probably does) that it consumes
> > the whole InputStream.
>
> It does. And, necessarily, it must. You can't find out what's in the
> request entity without ... reading the request entity.
>
> > But again, this may be lacking some overall clarity.
> >
> > In any case, the OP's question is not really unwarranted, unless
> > there is some other explanation somewhere which I have missed.
>
> I guess to me this falls under the category of "obvious", but then
> again I know quite a bit about this subject.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/
>
> iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl3xJ+IACgkQHPApP6U8
> pFj+aQ//eGoRadiIjoP5uG3e9rzwjK8JqL6aa39UIz0iQH3rgXGpQBAJf2u0QBwJ
> 8qjFVG8PpJV6yIrcLK8IxbrgJyKTeBsvxZc6/F092w1lU2ScHr96qSNJQFVyw94J
> YQUZezyP2yVn6SHcm5Ok6lLnf/wo2Nf527ritAkAmrNg31pnEPa89giCJFKzIUkm
> OJj82MZ8CoLmaL4u0gV4Ad5AghasCNASvrnTuc7BAh8COWDBOqHFpKc7esrHzilw
> R8uBHJJ5cHujPQPcHTpMeeSWFUOo6IU+LUi91KxYM6ROjZIb+74e6Pi0fpIVPWAk
> ycukcRPJKKGAucjDzst8TSwVsJZ659Q77UKp8PaIMms2s5njZvOwrXsTn0ZGF/uI
> PLUISkt+jbj0o/EMYJdsanVfE4ZsZXA4JSDXXiCwOAswccRluMgkLEJxQsrsRac1
> rfsWvUYqqIchTpfOSc/K0UgR4hcMIewiaF0FU0qru0eZfk6ErWVr7Pvnc6w+HkU6
> TzYxFnHY03+LZsCvu8lYDysKgNg5/ibrklyekTkebmBgSMV7LuR9ewM12X7Yqmvw
> ABhyNt8hRKHJx7yY4kg1WozwtIc+MhAWCVhKqetZzvc9E+KQbYcJHxiGOmuop5cJ
> oWnhGSQbWPx6xOqtgvWczDfJfgwCBm4UAeIn5W/62KVG7EuukfA=
> =fdap
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>

Reply via email to