zumult-org / zumultapi

1 stars 0 forks source link

Weird way of creating temp file in DefaultQuerySerializer #182

Open berndmoos opened 10 months ago

berndmoos commented 10 months ago

@EleFri : What is the target good for in...

Lines 402ff in DefaultQuerySerializer:

    private File createTmpFile(String fileType) throws IOException{
        File file = null;
        String actualPath = DefaultQuerySerializer.class.getProtectionDomain().getCodeSource().getLocation().getPath();

        File target = new File(IOHelper.getProjectFile(actualPath), "downloads"); 
            try {         
                file = File.createTempFile("tmp", "." + fileType, target);
                file.deleteOnExit();
            } catch(IOException ex){
                throw new IOException("Temporary file with KWIC could not be created: " + target.getAbsolutePath() + " does not exist ", ex);
            }

        return file;
    }

The method is called from createKWICDownloadFile(...) elsewhere in the same class. It is not working for me because the path for the tempFile calculated in this way does not exist in my setup. If the purpose is to place the file directly into the download directory, I think this is wrong. The backend should not have to know about the (server) context in which the file sits.

I think it would be better to just create an "ordinary" temp file here (i.e. in the default temp folder of the system) and to make that available via the download folder once a server context is known. The download directory can then be determined like so:

File downloadDirectory = new File(getServletContext().getRealPath("/downloads/"));

berndmoos commented 10 months ago

I'll start by overriding the method createKWICDownloadFile() in DGD2QuerySerializer and then copy the code from DefaultQuerySerializer there. Then I should be free to change the code in DefaultQuerySerializer (or so I think...)

berndmoos commented 9 months ago

Afaik, there is nothing open here, but I am not sure if I should close the issue...

EleFri commented 4 months ago

I will test this in the AGDZuMultBackend and close this issue if everything works.