Thanks Andre for explaining it much better than I did.

I posted this to Jakarta EE's mailing list too:
https://www.eclipse.org/lists/jakarta.ee-community/msg01477.html

I think at least the JavaDocs comments and the spec need minor amendments
to document this expected behaviour clearly.

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 Wed, Dec 11, 2019 at 8:47 AM André Warnier (tomcat/perl) <a...@ice-sa.com>
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.
> 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".
>
> (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.)
>
> 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.
>
> 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.
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>

Reply via email to