Skip to content

Commit

Permalink
MULE-8420: FileMessageDispatcher return subfolders when no files found
Browse files Browse the repository at this point in the history
  • Loading branch information
pablokraan committed Mar 20, 2015
1 parent ffcd445 commit 03e6ef6
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ else if (filter instanceof FilenameFilter)
}
if (files.length > 0)
{
result = files[0];
result = getFirstFile(files);
}
}
}
Expand All @@ -146,6 +146,19 @@ else if (filter instanceof FilenameFilter)
}
}

private static File getFirstFile(File[] files)
{
for (File file : files)
{
if (file.isFile())
{
return file;
}
}

return null;
}

@Override
protected MuleMessage doSend(MuleEvent event) throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/

package org.mule.transport.file;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import org.mule.api.MuleMessage;
import org.mule.api.client.MuleClient;
import org.mule.tck.junit4.FunctionalTestCase;
import org.mule.tck.junit4.rule.SystemPropertyTemporaryFolder;

import org.junit.Rule;
import org.junit.Test;

public class RecursiveWorkDirectoryTestCase extends FunctionalTestCase
{

@Rule
public SystemPropertyTemporaryFolder temporaryFolder = new SystemPropertyTemporaryFolder("temp");


@Override
protected String getConfigFile()
{
return "recursive-work-directory-config.xml";
}

@Test
public void ignoresWorkDirectoryOnRequest() throws Exception
{
MuleClient client = muleContext.getClient();

MuleMessage response = client.request("file://" + temporaryFolder.getRoot(), RECEIVE_TIMEOUT);

assertThat(response, is(nullValue()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<mule
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">

<file:connector name="fileConnector" autoDelete="true" streaming="true" validateConnections="true" workDirectory="${temp}/work" recursive="true"/>

<flow name="main" >
<file:inbound-endpoint path="${temp}" pollingFrequency="1000"/>

<echo-component/>
</flow>
</mule>

0 comments on commit 03e6ef6

Please sign in to comment.