ocpsoft / rewrite

OCPsoft URL-Rewriting Framework
http://ocpsoft.org/rewrite/
Apache License 2.0
188 stars 86 forks source link

GZipResponseStreamWrapper fails on Wildfly #145

Open chkal opened 10 years ago

chkal commented 10 years ago

It looks like WrappedResponseStreamTest fails because there is some issue with the content length. When running the test, the following exception occurs on the client:

Caused by: org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 39; received: 10
    at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:184)
    at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:238)
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
    at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:116)
    at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:138)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
    at java.io.InputStreamReader.read(InputStreamReader.java:184)
    at org.ocpsoft.rewrite.test.HttpAction.toString(HttpAction.java:174)
    ... 85 more

On the server the following exception occurs:

Caused by: org.xnio.channels.FixedLengthOverflowException
    at io.undertow.conduits.FixedLengthStreamSinkConduit.write(FixedLengthStreamSinkConduit.java:92)
    at org.xnio.conduits.ConduitStreamSinkChannel.write(ConduitStreamSinkChannel.java:135) [xnio-api-3.1.0.CR7.jar:3.1.0.CR7]
    at io.undertow.channels.DetachableStreamSinkChannel.write(DetachableStreamSinkChannel.java:198)
    at org.xnio.channels.Channels.writeBlocking(Channels.java:97) [xnio-api-3.1.0.CR7.jar:3.1.0.CR7]
    at io.undertow.servlet.spec.ServletOutputStreamImpl.writeBufferBlocking(ServletOutputStreamImpl.java:566)
    at io.undertow.servlet.spec.ServletOutputStreamImpl.close(ServletOutputStreamImpl.java:592)
    at io.undertow.servlet.spec.HttpServletResponseImpl.responseDone(HttpServletResponseImpl.java:510)
    ... 9 more

Not sure what is going wrong here. But I'll ignore the test for now on Wildfly to get the overall test suite green. But we should have a deeper look at this issue.

chkal commented 10 years ago

Hmmm. It's not just the GZIP stuff. JsMinifyTest and CssMinifyTest also fail.

Caused by: org.xnio.channels.FixedLengthUnderflowException: 8 bytes remaining
    at io.undertow.conduits.FixedLengthStreamSinkConduit.terminateWrites(FixedLengthStreamSinkConduit.java:189)
    at org.xnio.conduits.ConduitStreamSinkChannel.shutdownWrites(ConduitStreamSinkChannel.java:163) [xnio-api-3.1.0.CR7.jar:3.1.0.CR7]
    at io.undertow.channels.DetachableStreamSinkChannel.shutdownWrites(DetachableStreamSinkChannel.java:77)
    at io.undertow.servlet.spec.ServletOutputStreamImpl.close(ServletOutputStreamImpl.java:598)
    at io.undertow.servlet.spec.HttpServletResponseImpl.responseDone(HttpServletResponseImpl.java:510)
    ... 9 more

It is just a guess, but I think it could be possible that Wildfly creates a content length header with the original file size before the compression happens which reduces the size of the response. Just a guess. :)

chkal commented 10 years ago

More news on this one. With AS7 and Tomcat the response headers look like this:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Accept-Ranges: bytes
ETag: W/"27-1382866066000"
Last-Modified: Sun, 27 Oct 2013 09:27:46 GMT
Content-Type: text/css
Transfer-Encoding: chunked
Date: Sun, 27 Oct 2013 09:27:57 GMT

With Wildfly like this:

HTTP/1.1 200 OK
Connection: keep-alive
Last-Modified: Sun, 27 Oct 2013 09:26:06 GMT
Content-Type: text/css
Content-Length: 27

As you see Wildfly doesn't use chunked transfer encoding and therefore manually specified the content length. But this content length is the size of the original resource on the server. As our transform mechanism reduces the response size (in case of compression for example), this length header isn't correct and seems to lead to this error.

poikilotherm commented 1 year ago

I retested this with Wildfly 27 and Payara 6 for the EE10 release. Still seeing an empty response header for content type. Both application servers show the same error.

--> GET http://127.0.0.1:8080/rewrite-test/gzip.html
--> END GET
<-- 200 OK http://127.0.0.1:8080/rewrite-test/gzip.html (4ms)
Connection: keep-alive
Last-Modified: Tue, 25 Oct 2022 09:07:10 GMT
X-Uncompressed-Content-Length: 39
Transfer-Encoding: chunked
Content-Type: text/html
Accept-Ranges: bytes
Date: Tue, 25 Oct 2022 09:07:11 GMT

zip me to gzip please and make it zippy
<-- END HTTP (39-byte body)
[]
11:07:11,557 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 10) WFLYUT0022: Unregistered web context: '/rewrite-test' from server 'default-server'
11:07:11,557 INFO  [org.ocpsoft.rewrite.servlet.RewriteFilter] (ServerService Thread Pool -- 10) RewriteFilter shutting down...
11:07:11,558 INFO  [org.ocpsoft.rewrite.servlet.RewriteFilter] (ServerService Thread Pool -- 10) RewriteFilter deactivated.
11:07:11,573 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) WFLYSRV0028: Stopped deployment rewrite-test.war (runtime-name: rewrite-test.war) in 16ms
11:07:11,581 INFO  [org.jboss.as.repository] (management-handler-thread - 1) WFLYDR0002: Content removed from location /home/obertuch/Entwicklung/prettyfaces/impl-servlet-tests/target/container/wildfly-preview-27.0.0.Beta1/standalone/data/content/3a/997cba71decf8fb51af06b4a1b38f8ca193ac2/content
11:07:11,582 INFO  [org.jboss.as.server] (management-handler-thread - 1) WFLYSRV0009: Undeployed "rewrite-test.war" (runtime-name: "rewrite-test.war")
11:07:12,106 INFO  [org.jboss.as.repository] (management-handler-thread - 1) WFLYDR0001: Content added at location /home/obertuch/Entwicklung/prettyfaces/impl-servlet-tests/target/container/wildfly-preview-27.0.0.Beta1/standalone/data/content/dd/3356e93cc20503d7a9f4c10463f291876cc5ac/content
11:07:12,108 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) WFLYSRV0027: Starting deployment of "rewrite-test.war" (runtime-name: "rewrite-test.war")
11:07:12,263 INFO  [org.wildfly.extension.micrometer] (MSC service thread 1-3) WFLYMMTREXT0002: Micrometer Subsystem is processing deployment
11:07:12,263 INFO  [org.wildfly.extension.micrometer] (MSC service thread 1-3) WFLYMMTREXT0003: The deployment does not have Jakarta Contexts and Dependency Injection enabled. Skipping Micrometer integration.
11:07:12,280 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 4) WFLYUT0021: Registered web context: '/rewrite-test' for server 'default-server'
11:07:12,290 INFO  [org.jboss.as.server] (management-handler-thread - 1) WFLYSRV0010: Deployed "rewrite-test.war" (runtime-name : "rewrite-test.war")
[ERROR] Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.887 s <<< FAILURE! - in org.ocpsoft.rewrite.servlet.wrapper.WrappedResponseStreamIT
[ERROR] testWrappedResponseStreamToGZip(org.ocpsoft.rewrite.servlet.wrapper.WrappedResponseStreamIT)  Time elapsed: 0.016 s  <<< ERROR!
java.lang.IndexOutOfBoundsException: Empty list doesn't contain element at index 0.
    at org.ocpsoft.rewrite.servlet.wrapper.WrappedResponseStreamIT.testWrappedResponseStreamToGZip(WrappedResponseStreamIT.java:81)
lincolnthree commented 1 year ago

I wonder if this code is being executed. Could you try setting your debugger for this line (and potentially the overridden method bodies), and see if this is being called?

https://github.com/ocpsoft/rewrite/blob/878b59880de6ad40e6df00d9729580e03784d8f9/config-servlet/src/main/java/org/ocpsoft/rewrite/servlet/config/response/GZipResponseStreamWrapper.java#L38