1

I am having weird issues with a java application unzipping files on an apache server. I have an apache server in which some other applications uploads zip files. e.g. the directory is /var/www/html/fles

When I now start my java program to unzip the files it always fails with the following exception below.

I also checked the contentType using Files.probeContentType(file) and astonishingly it returns text/plain instead of application/zip I then tested the code in another directory, e.g. the home dir and there it works flawlessly.

So it seems it has something do do with the apache config, but I already checked and disabled gzip compression for zip files: I have no clue what else I have to do

My deflate.conf:

<IfModule mod_deflate.c>
        <IfModule mod_filter.c>
                # these are known to be safe with MSIE 6
                AddOutputFilterByType DEFLATE text/html text/plain text/xml

                # everything else may cause problems with MSIE 6
                AddOutputFilterByType DEFLATE text/css
                AddOutputFilterByType DEFLATE application/x-javascript application/javascript $
                AddOutputFilterByType DEFLATE application/rss+xml
                AddOutputFilterByType DEFLATE application/xml

                SetOutputFilter DEFLATE
                SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png|zip)$" no-gzip
        </IfModule>
</IfModule>

The java code for creating a zip Filesystem: The excpetions already happens at the creation of the filesystem:

 private static FileSystem createZipFileSystem(Path zipFilename,
            boolean create)
            throws IOException {
        // convert the filename to a URI

        final URI uri = URI.create("jar:file:" + zipFilename.toUri().getPath());

        final Map<String, String> env = new HashMap<>();
        if (create) {
            env.put("create", "true");
        }
        return FileSystems.newFileSystem(uri, env);
    }

The exception I get:

  java.util.zip.ZipError: zip END header not found
            at com.sun.nio.zipfs.ZipFileSystem.zerror(ZipFileSystem.java:1605)
            at com.sun.nio.zipfs.ZipFileSystem.findEND(ZipFileSystem.java:1021)
            at com.sun.nio.zipfs.ZipFileSystem.initCEN(ZipFileSystem.java:1030)
            at com.sun.nio.zipfs.ZipFileSystem.<init>(ZipFileSystem.java:130)
            at com.sun.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:117)
            at java.nio.file.FileSystems.newFileSystem(FileSystems.java:326)
            at java.nio.file.FileSystems.newFileSystem(FileSystems.java:276)
Christoph S
  • 697
  • 1
  • 6
  • 29
  • Did you examine the file to see if it is in fact a plain text file? Perhaps the text in it will indicate what went wrong. – VGR Feb 14 '18 at 18:03
  • Yes, the file is a correct zip file. Unix file - - mime-type also returned application/zip. The same file works flawlessly in any other dir. So my conclusion that it must be related to apache – Christoph S Feb 14 '18 at 19:08
  • I still don't know the reason why java behaves odd in this case. I now rewrote the unzipping part in php and it works fine. So this issue is closed for me, but still it would be interesting to have the real reason for this weird behaviour – Christoph S Feb 15 '18 at 12:49

1 Answers1

0

I found the problem is not about the unzipping, but after a while I realized that I run into the issue as described here: Java 7 Watch Service ENTRY_CREATE triggered before file is written

Christoph S
  • 697
  • 1
  • 6
  • 29