You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed a problem with the first byte being missing in the inputStream when I call Jetty server 12 with Jersey as the servlet container. This only happens from PHP with a sufficiently large payload (my test is about 1.5MB). It doesn't happen when the same call is made in Java (but I can't replicate the identical behavior with Java).
It seems that the only Jersey versions exhibiting the issue are 3.1.8 and 3.1.9, not 4.0.0-M1 or < 3.1.7.
java --version
openjdk 17.0.12 2024-07-16
OpenJDK Runtime Environment (build 17.0.12+7-Ubuntu-1ubuntu222.04)
OpenJDK 64-Bit Server VM (build 17.0.12+7-Ubuntu-1ubuntu222.04, mixed mode, sharing)
<jetty.version>12.0.14</jetty.version>
PHP version 7.4.33
PHP version 8.3.12
there are two Main classes that are both Jetty servers. The first Main.java has a Jersey ServletContainer, while the second Main2.java is a pure implementation in Jetty12.
The first one exhibits the bug/problem, while the second does not.
What happens is that when running the PHP script PhpCurlCall.php (essentially a while loop with a POST call), the server at some point starts to return a 500 internal server error (my code raise an exception), indicating that the first byte is different from what was expected.
the current state of my investigation is, that we cannot eliminate the fact that Jersey sometimes wraps the original request's stream into the PushbackInputStream to determine if the stream is empty. If the available() method of the request's InputStream returns 0, the stream gets wrapped. I've attempted to fix the issue for your case because Jetty does return available() greater than 0, but overall it's not possible to avoid this one-byte reading and wrapping.
Generally speaking, instead of referring to
@Context
private HttpServletRequest request;
you can refer to
@Context
private Request request;
which is jakarta.ws.rs.core.Request; and then we came to final InputStream entityInputStream = ((org.glassfish.jersey.server.ContainerRequest) request).getEntityStream(); which is InputStream from Jersey (either wrapped or not), so the error with missing the first byte never occurs there.
However, the other question remains - why is the proper stream not being injected into the HttpServletRequest? I continue the investigation to find out why it's not being injected.
I noticed a problem with the first byte being missing in the inputStream when I call Jetty server 12 with Jersey as the servlet container. This only happens from PHP with a sufficiently large payload (my test is about 1.5MB). It doesn't happen when the same call is made in Java (but I can't replicate the identical behavior with Java).
It seems that the only Jersey versions exhibiting the issue are 3.1.8 and 3.1.9, not 4.0.0-M1 or < 3.1.7.
Affected Jersey Versions:
In this repository:
https://github.com/Ostico/TestBug-Jersey-Container
there are two Main classes that are both Jetty servers. The first Main.java has a Jersey ServletContainer, while the second Main2.java is a pure implementation in Jetty12.
The first one exhibits the bug/problem, while the second does not.
What happens is that when running the PHP script PhpCurlCall.php (essentially a while loop with a POST call), the server at some point starts to return a 500 internal server error (my code raise an exception), indicating that the first byte is different from what was expected.
This happens randomly and sporadically.
This is a TcpDump that allowed me to see that the issue could be related to the Expect: 100-continue header, which is not sent from the Java client.
The text was updated successfully, but these errors were encountered: