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.
I have Mule ESB 3.3.2
your Mule version si severely out of date, you should update to a recent version – Pierre B.