0

On Linux(openSUSE) machine I'm trying to deploy on Tomcat 8 application(war file) that contains a files with names with Unicode characters.

Inside of the war file the name looks like:

бжк-природний-1496336830201.xml

but after deploy the file looks like:

???-?????????????-1496336830201.xml

How to tell Tomcat to properly deploy the file names ?

UPDATED

This is a sample war file with Unicode file name inside: war file

What is wrong with the file name of the file inside in this war ?

UPDATED

I have installed unzip-rcc as it was suggested here https://superuser.com/questions/1215670/opensuse-unzip-unicode-issue and now unzip(console command) on the WAR file is working fine but Tomcat still deploy the files with the same issue.

6
  • If you unzip the war into a directory, does the filename with special characters preserved? Another thing to try is to ensure JAVA has the right encoding. Commented Jun 3, 2017 at 11:45
  • yeah.. unzip kills the filenames Commented Jun 3, 2017 at 11:55
  • This suggests that the Operating System does not have the font or character set to handle such encoding. So its not Java fault :) Commented Jun 3, 2017 at 11:57
  • yes, but I have no idea what can be wrong. Is it also possible that my Jenkins/Maven build destroys the file names ? If zip/unzip raw files downloaded from Git - everything works fine.. only files from war file generated by Jenkins/Maven doesn't work properly. Commented Jun 3, 2017 at 13:33
  • I have installed unzip-rcc as it was suggested here superuser.com/questions/1215670/opensuse-unzip-unicode-issue and now unzip(console command) on the WAR file is working fine but Tomcat still deploy the files with the same issue. How to configure Tomcat 8 in order to properly deploy the files ? Commented Jun 4, 2017 at 15:07

2 Answers 2

2

Try putting these settings in Tomcat startup script:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8

From experience, Java will print up-side-down question mark for characters it does not know how to encode.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much ! I was struggling with this issue for a few days and now with your help it is solved! I have added these properties to my tomcat.conf file
2

The filename is indeed in UTF-8 in the zip .war file.

try (ZipFile zipFile = new ZipFile(path, StandardCharsets.UTF_8)) {
    zipFile.stream()
        .forEachOrdered(entry -> System.out.printf("- %s%n", entry.getName()));
} catch (IOException e) {
    e.printStackTrace();
}

However the zip does not has added the encoding (as bytes[] extra information).

Three solutions would be imaginable:

  • One short solution might be to run TomCat under a UTF-8 locale.
  • The best would be to have maven build a war with UTF-8 encoding. (<onfiguration><encoding>UTF-8</encoding></configuration>)
  • Repairing the war by converting it.

With the first two solutions I have no experience. A quick search didn't yield anything ("encoding" is a bit ubiquitous).

The repair code is simple:

Path path = Paths.get(".../api.war").toAbsolutePath().normalize();
Path path2 = Paths.get(".../api2.war").toAbsolutePath().normalize();

URI uri = URI.create("jar:file://" + path.toString());
Map<String,String> env = new HashMap<String,String>();
env.put("create", "false");
env.put("encoding", "UTF-8");

URI uri2 = URI.create("jar:file://" + path2.toString());
Map<String,String> env2 = new HashMap<String,String>();
env2.put("create", "true");
env2.put("encoding", "UTF-8");

try (FileSystem zipFS = FileSystems.newFileSystem(uri, env);
     FileSystem zipFS2 = FileSystems.newFileSystem(uri2, env2)) {

    Files.walkFileTree(zipFS.getPath("/"), new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
                    throws IOException {
            System.out.println("* File: " + file);
            Path file2 = zipFS2.getPath(file.toString());
            Files.createDirectories(file2.getParent());
            Files.copy(file, file2);
            return FileVisitResult.CONTINUE;
        }
    });

} catch(IOException e) {
    e.printStackTrace();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.