Skip to content

Add ability to set a filename generator on a ZipTransformer #9452

@michaelwiles

Description

@michaelwiles

Right now when using the zip transformer it is not possible to set the name of the new generated zip file.

Observing the code of doZipTransform:

  protected Object doZipTransform(Message<?> message) {
        Object payload = message.getPayload();
        String baseFileName = this.fileNameGenerator.generateFileName(message);
        String zipEntryName;
        if (message.getHeaders().containsKey("zip_entryFilename")) {
            zipEntryName = (String)message.getHeaders().get("zip_entryFilename");
        } else {
            zipEntryName = baseFileName;
        }

        String zipFileName;
        if (message.getHeaders().containsKey("file_name")) {
            zipFileName = (String)message.getHeaders().get("file_name");
        } else {
            zipFileName = baseFileName + ".zip";
        }

Notice that if a file_name header is not found, then the name from the fileNameGenerator is used and .zip is appended. This behaviour would be great. However, there is a file_name header present (there should be) and that is what the defaultFileNameGenerator uses to generate the file name (and you can't change the filename generator from the default one). So the alternative zipFileName = baseFileName + ".zip"; would never be used if there's a file_name header.

So please can the zip transformers be changed so that the file name generator can be set?

I know I could manually set the file_name to add the zip extension before hand but I'd argue it makes more sense to allow me to set the file name generator to automatically change the file name so that the zip extension is included once the zip transformer has run. If I do this and then remove the zip transformer I will also need to set the file_name back to the one without the zip extension.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions