Tomcat with compression enabled causes error on OS X High Sierra

£可爱£侵袭症+ 提交于 2019-12-03 05:37:52

This is a bug in how the Java SDK setLevel() method is implemented. It is reported that compressed data resulting from setting the level is discarded by the SDK. That will result in corrupted compressed data. The fix for the bug can be found here, written by xuemingshen.

cedric

Workaround till an actual fix is found for this: turn off compression in your tomcat project's server.xml configuration.

PF.

Workarround/Hack for Windows: Unfortunately I am not familiar with OS X, but I am facing the same problem on Windows and have been able to find a little bit dirty solution for it. The deflate.c error has been fixed in 8u162-ea, see https://bugs.openjdk.java.net/browse/JDK-8189789

Unfortunately 8u162-ea may not contain all fixes or is probably not good enough for a production environment.

To fix it under 8u152, download and install the latest update from http://jdk.java.net/8/

Go to the installation folder (for instance C:\Java\jdk8-162-ea\jre\bin\) and copy the zip.dll which contains the fix (see JDK 9 deflate.c fix) and paste it on the same place under the jdk 8u152.

I hope you can find something similar under OS X.

Fyi, OS X users, I tried installing JDK 8u162-ea from http://jdk.java.net/8/, and it did not fix the issue. I think the reason is that, unlike the Windows JDK, the OS X JDK does not bundle zlib, but rather uses the zlib that is included with OS X (/usr/lib/libz.1.dylib). This can be seen by looking at the shared libraries the java executable depends on:

$ otool -L /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/bin/java
/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/bin/java:
    /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 19.0.0)
    /System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 55179.0.2)
    /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 45.0.0)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 744.1.0)
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 945.11.0)

So I think we need a fix for this issue from Apple in the form of an update for High Sierra.

Our workaround for local dev: We use spring boot and have an EmbeddedServletContainerCustomizer. After updated to High Sierra, same issue. The problem only exists for local development, so not something to push to production. As mentioned above we turned off compressing in our MainConfiguration as follows:

    @Bean
    public EmbeddedServletContainerCustomizer servletContainerCustomizer() {
    return new EmbeddedServletContainerCustomizer() {
        @Override
        public void customize(ConfigurableEmbeddedServletContainerFactory servletContainer) {
            ((TomcatEmbeddedServletContainerFactory) servletContainer).addConnectorCustomizers(
                    new TomcatConnectorCustomizer() {
                        @Override
                        public void customize(Connector connector) {
                            AbstractHttp11Protocol httpProtocol = (AbstractHttp11Protocol) connector.getProtocolHandler();
                            httpProtocol.setCompression("off");
                            httpProtocol.setCompressionMinSize(256);
                            String mimeTypes = httpProtocol.getCompressableMimeTypes();
                            mimeTypes += "," + MediaType.APPLICATION_JSON_VALUE;
                            mimeTypes += "," + "text/css";
                            mimeTypes += "," + "application/javascript";
                            httpProtocol.setCompressableMimeTypes(mimeTypes);
                        }
                    });
        };
    };
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!