Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jersey not compatible with HttpServletRequests not always returning the same input stream from version 2.44 #5739

Open
Lorenzo-Bracci opened this issue Sep 3, 2024 · 0 comments

Comments

@Lorenzo-Bracci
Copy link

After this pr jersey is no longer handling correctly any override of HttpServletRequest which does not return always the same input stream when invoking getInputStream.

Context about different implementation of ServletRequest#getInputStream

The servlet api does not seem to specify wether or not it is required for an implementation to always return the same input stream across multiple invocations and it therefore seems valid in some cases to override this method in an HttpServletRequestWrapper returning a new copy of the input stream for any invocation (to be able to consume the input stream multiple times). This is showcased for example in this stack overflow answer about how a servlet input stream could be consumed multiple times.

Current issue

With the aforementioned change the InputStreamWrapper will invoke the underlying ServletRequest#getInputStream whenever any operation is performed to the request input stream. This can cause the input stream to be read forever as invocations to InputStreamWrapper#available will create a new input stream every time that this has not yet been consumed.

How to reproduce this issue

When overriding the http servlet request in a servlet filter with a request such as the one showed in the previous stack overflow answer no jersey invocation to an endpoint consuming json seems to work.

Possible solutions

This use case seems quiet valid also considering that HttpServletRequest does not expose anywhere in its api a way to override the input stream and therefore allow for more easy input replayability. I therefore wondered if this could be fixed/supported by having InputStreamWrapper caching the result of InputStreamWrapper#getWrapped after it is invoked the first time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant