Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jakarta.ee-community] Expected behavior of calling javax.servlet.ServletRequest#getInputStream after javax.servlet.http.HttpServletRequest#getPart

Hi all,

Sorry about the very short reply from my phone. To clarify, I’ve started playing with Servlets again recently to refresh my memory. In particular I wanted to see why a certain “enterprise” system that’s written in Java had a hard time handle more than 30 concurrent file uploads per second on a relatively high specced hardware.

The JavaDoc for javax.servlet.ServletRequest#getInputStream() reads:

@exception IllegalStateException if the {@link #getReader} method has already been called for this request

Similarly the JavaDoc for javax.servlet.ServletRequest#getReader() reads:

@exception IllegalStateException if {@link #getInputStream} method has been called on this request

So, IMHO, if we call getInputStream/getReader after calling javax.servlet.http.HttpServletRequest#getParts/javax.servlet.http.HttpServletRequest#getPart, they should throw IllegalStateException, instead of returning an empty stream.

If for backwards compatibility it is too late to enforce that, then the spec can be updated and mention that it is up to the implementor what to do in this scenario.








On Mon, Dec 9, 2019 at 11:31 AM Behrang Saeedzadeh <behrangsa@xxxxxxxxx> wrote:
The implementation can call reset() on the input stream after getPart() parses it. In Tomcat's case the input stream does not support mark/reset though. 

Also similar to the way that calling getWriter() and getInputStream() on the same request throws IllegalStateException, IMHO calling them after getParts() should also thrown IllegalStateException. Or at least the spec should specify the expected behavior. 

Best regards,
Behrang Saeedzadeh
(Sent from my cellphone.)

On Mon, 9 Dec. 2019, 10:58 am Jan Bartel, <janb@xxxxxxxxxxx> wrote:
Behrang,

 I don't think you will find that this is tomcat-specific. When you call HttpServletRequest.getPart/s, this consumes the input stream of the request body, so naturally you cannot also consume it.
You will find that this is the same on jetty.

Jan

On Mon, 9 Dec 2019 at 10:24, Behrang Saeedzadeh <behrangsa@xxxxxxxxx> wrote:

Hi,

In Tomcat, when 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?

Best regards,
Behrang Saeedzadeh
(Sent from my cellphone.)
_______________________________________________
jakarta.ee-community mailing list
jakarta.ee-community@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jakarta.ee-community


--
Jan Bartel <janb@xxxxxxxxxxx>
www.webtide.com
Expert assistance from the creators of Jetty and CometD

_______________________________________________
jakarta.ee-community mailing list
jakarta.ee-community@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jakarta.ee-community

Back to the top