Author: markt
Date: Thu Nov 30 13:41:20 2017
New Revision: 1816712
URL: http://svn.apache.org/viewvc?rev=1816712&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=57870
When running on Java 7 or later, take advantage of the new syncFlush< parameter
when constructing a GZIPOutputStream rather than using the custom
FlushableGZIPOutputStream implementation as a work-around.
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/filters/GzipOutputFilter.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/Jre7Compat.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/JreCompat.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties
tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/filters/GzipOutputFilter.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/filters/GzipOutputFilter.java?rev=1816712&r1=1816711&r2=1816712&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/filters/GzipOutputFilter.java
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/filters/GzipOutputFilter.java
Thu Nov 30 13:41:20 2017
@@ -25,6 +25,7 @@ import org.apache.coyote.OutputBuffer;
import org.apache.coyote.Response;
import org.apache.coyote.http11.OutputFilter;
import org.apache.tomcat.util.buf.ByteChunk;
+import org.apache.tomcat.util.compat.JreCompat;
/**
* Gzip output filter.
@@ -74,7 +75,12 @@ public class GzipOutputFilter implements
public int doWrite(ByteChunk chunk, Response res)
throws IOException {
if (compressionStream == null) {
- compressionStream = new
FlushableGZIPOutputStream(fakeOutputStream);
+ if (JreCompat.isJre7Available()) {
+ compressionStream =
+
JreCompat.getInstance().getFlushableGZipOutputStream(fakeOutputStream);
+ } else {
+ compressionStream = new
FlushableGZIPOutputStream(fakeOutputStream);
+ }
}
compressionStream.write(chunk.getBytes(), chunk.getStart(),
chunk.getLength());
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/Jre7Compat.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/Jre7Compat.java?rev=1816712&r1=1816711&r2=1816712&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/Jre7Compat.java
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/Jre7Compat.java Thu
Nov 30 13:41:20 2017
@@ -16,27 +16,34 @@
*/
package org.apache.tomcat.util.compat;
+import java.io.OutputStream;
+import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Locale;
+import java.util.zip.GZIPOutputStream;
class Jre7Compat extends JreCompat {
private static final int RUNTIME_MAJOR_VERSION = 7;
private static final Method forLanguageTagMethod;
+ private static final Constructor<GZIPOutputStream>
gzipOutputStreamConstructor;
static {
Method m = null;
+ Constructor<GZIPOutputStream> c = null;
try {
m = Locale.class.getMethod("forLanguageTag", String.class);
+ c = GZIPOutputStream.class.getConstructor(OutputStream.class,
boolean.class);
} catch (SecurityException e) {
// Should never happen
} catch (NoSuchMethodException e) {
// Expected on Java < 7
}
forLanguageTagMethod = m;
+ gzipOutputStreamConstructor = c;
}
@@ -58,6 +65,22 @@ class Jre7Compat extends JreCompat {
}
}
+
+ @Override
+ public GZIPOutputStream getFlushableGZipOutputStream(OutputStream os) {
+ try {
+ return gzipOutputStreamConstructor.newInstance(os, Boolean.TRUE);
+ } catch (InstantiationException e) {
+ throw new UnsupportedOperationException(e);
+ } catch (IllegalAccessException e) {
+ throw new UnsupportedOperationException(e);
+ } catch (IllegalArgumentException e) {
+ throw new UnsupportedOperationException(e);
+ } catch (InvocationTargetException e) {
+ throw new UnsupportedOperationException(e);
+ }
+ }
+
@Override
public int jarFileRuntimeMajorVersion() {
Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/JreCompat.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/JreCompat.java?rev=1816712&r1=1816711&r2=1816712&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/JreCompat.java
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/JreCompat.java Thu
Nov 30 13:41:20 2017
@@ -18,11 +18,13 @@ package org.apache.tomcat.util.compat;
import java.io.File;
import java.io.IOException;
+import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Deque;
import java.util.Locale;
import java.util.jar.JarFile;
+import java.util.zip.GZIPOutputStream;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLServerSocket;
@@ -55,8 +57,7 @@ public class JreCompat {
jre9Available = true;
jre8Available = true;
jre7Available = true;
- }
- else if (Jre8Compat.isSupported()) {
+ } else if (Jre8Compat.isSupported()) {
instance = new Jre8Compat();
jre9Available = false;
jre8Available = true;
@@ -127,6 +128,12 @@ public class JreCompat {
return true;
}
+
+ @SuppressWarnings("unused")
+ public GZIPOutputStream getFlushableGZipOutputStream(OutputStream os) {
+ throw new UnsupportedOperationException(
+ sm.getString("jreCompat.noFlushableGzipOutputStream"));
+ }
// Java 6 implementation of Java 8 methods
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties?rev=1816712&r1=1816711&r2=1816712&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/compat/LocalStrings.properties
Thu Nov 30 13:41:20 2017
@@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+jreCompat.noFlushableGzipOutputStream=Java Runtime does not support flushable
GZIP output streams. You must use Java 7 or later to use this feature.
jreCompat.noServerCipherSuiteOrder=Java Runtime does not support
"useServerCipherSuitesOrder". You must use Java 8 or later to use this feature.
jre9Compat.invalidModuleUri=The module URI provided [{0}] could not be
converted to a URL for the JarScanner to process
Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1816712&r1=1816711&r2=1816712&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu Nov 30 13:41:20 2017
@@ -100,6 +100,17 @@
</fix>
</changelog>
</subsection>
+ <subsection name="Coyote">
+ <changelog>
+ <fix>
+ <bug>57870</bug>: When running on Java 7 or later, take advantage of
the
+ new <code>syncFlush</code> parameter when constructing a
+ <code>GZIPOutputStream</code> rather than using the custom
+ <code>FlushableGZIPOutputStream</code> implementation as a work-around.
+ (markt)
+ </fix>
+ </changelog>
+ </subsection>
<subsection name="Jasper">
<changelog>
<add>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]