0
votes

I have a flow that starts with file:inbound-endpoint that unzips successfully zipped file. One or more of XML file is generated as the result of unzipping transformation ( component I have written) . The zipped file is removed after that. Another flow also started with file:inbound-endpoint that starts reading XML file and locks the file it reads. Once the processing of the current file is done, the file is not deleted by Mule even though autoDelete=true. Below is the configuration and corresponding java classes. I have Mule ESB 3.3.2 on RedHat Linux. The process works just fine on Windows machine and xml files are deleted once they are processed.

mule configuration snippet is below:

<file:connector name="zipInput"  readFromDirectory="/some/directory/input" streaming="false" workFileNamePattern="xyz-*.zip" autoDelete="true" pollingFrequency="30000"/>

<file:connector name="inputXML"  readFromDirectory="some/directory/output" streaming="false" workFileNamePattern="*.xml" autoDelete="true" pollingFrequency="30000"/>

<flow name="unzipFlow" processingStrategy="synchronous">
  <file:inbound-endpoint connector-ref="zipInput" path="/some/directory/input">
  </file:inbound-endpoint>

  <transformer ref="unzipfileTransformer"/>     
</flow>

<flow name="process_xml_files" processingStrategy="synchronous">                                             
   <file:inbound-endpoint connector-ref="inputXML" path="/some/directory/output"/>

   <file:file-to-string-transformer/>
   <transformer ref="MyFileToSomeObjectTransformer"/>

   <vm:outbound-endpoint path="some.service" exchange-pattern="request-response"/>
   <exception-strategy ref="CatchExceptionStrategy" doc:name="Reference Exception Strategy" />
</flow>

public class UnzipTransformer extends AbstractMessageTransformer {

    private String inboundDirectory;
    private String outboundDirectory;


    @Override
    public Object transformMessage(MuleMessage message, String outputEncoding)
            throws TransformerException {

        byte[] buffer = new byte[2048];
        Object payload = message.getPayload();

        InputStream is = null;

        if (payload instanceof InputStream) {
            is = (InputStream) payload;

        } else if (payload instanceof byte[]) {
            is = new ByteArrayInputStream((byte[]) payload);
        } else {
            throw new RuntimeException("Unknown payload type: " + payload.getClass().getName());
        }

        ZipInputStream zipInput = new ZipInputStream(is);
        ZipEntry entry = null;
        InputStream result = null;
        try {
            while ((entry = zipInput.getNextEntry()) != null) {
                String fileNname = entry.getName();

                if (fileNname.endsWith(".txt")) continue;
                File file = new File(outboundDirectory + File.separator + fileNname);

                        FileOutputStream fOutput = new FileOutputStream(file);
                        int count = 0;
                        while ((count = zipInput.read(buffer)) > 0) {
                            // write to the file output stream
                            fOutput.write(buffer, 0, count);
                        }

                        fOutput.flush();
                        fOutput.close();
            }
            zipInput.closeEntry();
            entry = zipInput.getNextEntry();
            zipInput.close();

        } catch (IOException e) {

            e.printStackTrace();
        } finally {
        }
        return result;
    }
}

Any help would be greatly appreciated.

1
Try increasing your polling to 60000 and check?star
I have Mule ESB 3.3.2 your Mule version si severely out of date, you should update to a recent versionPierre B.
Try to enable debug logging and see what happens when Mule poll your XML files (and post the log here). You may see additionnal details as per why they're not deleted. Maybe it is because another process is still using it.Pierre B.
Pierr B, thank you for your suggestion, I am quite novice to Mule, how do I enable debugging logging on Mule?mulequest
star, thx for reply, Increasing polling to 60000 did not help. The files are delete in windows but not in Linux RedHat.mulequest

1 Answers

0
votes

Don't know why it is happening may be issue with the linux file permission. Can you try to use intermediate file location first the source of zip and then an intermediate folder to dump the unzipped file from where you can read and process set it to auto correct. this will provide you much more clarity on the behavior. If possible please check the flow with an updated version of mule. Also you can use check an alternate way like using the Anypoint unzipp transformer to simplify the flow. Then use normal file connector to read the file with auto-delete true and then process the file this will also provide you clarity. Attaching a snap shot of a compression decompression flow try this compressed/uncompressed flow