Connector to manipulate files on a locally mounted file system

Configurations


Config

File connector used to manipulate file systems mounted on the host operation system.

This class serves as both extension definition and configuration. Operations are based on the standard BaseFileSystemOperations

Parameters

Name Type Description Default Value Required

Name

String

The name of this configuration. With this name can be later referenced.

x 

Connection

The connection types that can be provided to this configuration.

x 

Default Write Encoding

String

 

Connection Types

Local FileSystem Connection

A ConnectionProvider which provides instances of FileSystem from instances of FileConnector

Parameters
Name Type Description Default Value Required

Working Directory

String

The directory to be considered as the root of every relative path used with this connector. If not provided, it will default to the value of the user.home system property. If that system property is not set, then the connector will fail to initialise.

 

Reconnection Strategy

A retry strategy in case of connectivity errors

 

Disable Validation

Boolean

Disables connection validation

 

Associated Operations

Associated Sources

Operations

Copy

<file:copy>

Copies the file at the sourcePath into the targetPath.

If targetPath doesn't exists, and neither does its parent, then an attempt will be made to create depending on the value of the createParentFolder argument. If such argument is , then an IllegalArgumentException will be thrown.

If the target file already exists, then it will be overwritten if the overwrite argument is true. Otherwise, IllegalArgumentException will be thrown.

As for the sourcePath, it can either be a file or a directory. If it points to a directory, then it will be copied recursively.

Parameters

Name Type Description Default Value Required

Configuration

String

The name of the configuration to use.

x 

Source Path

String

the path to the file to be copied

x 

Target Path

String

the target directory where the file is going to be copied

x 

Create Parent Directories

Boolean

whether or not to attempt creating any parent directories which don't exists.

true

 

Overwrite

Boolean

whether or not overwrite the file if the target destination already exists.

false

 

For Configurations.

Throws

  • FILE:CONNECTIVITY  

  • FILE:RETRY_EXHAUSTED  

  • FILE:ILLEGAL_PATH  

  • FILE:FILE_ALREADY_EXISTS  

Create Directory

<file:create-directory>

Creates a new directory on directoryPath

Parameters

Name Type Description Default Value Required

Configuration

String

The name of the configuration to use.

x 

Directory Path

String

the new directory's name

x 

For Configurations.

Throws

  • FILE:ACCESS_DENIED  

  • FILE:CONNECTIVITY  

  • FILE:RETRY_EXHAUSTED  

  • FILE:ILLEGAL_PATH  

  • FILE:FILE_ALREADY_EXISTS  

Delete

<file:delete>

Deletes the file pointed by path, provided that it's not locked

Parameters

Name Type Description Default Value Required

Configuration

String

The name of the configuration to use.

x 

Path

String

the path to the file to be deleted

x 

For Configurations.

Throws

  • FILE:ACCESS_DENIED  

  • FILE:CONNECTIVITY  

  • FILE:RETRY_EXHAUSTED  

  • FILE:ILLEGAL_PATH  

List

<file:list>

Lists all the files in the directoryPath which match the given matcher.

If the listing encounters a directory, the output list will include its contents depending on the value of the recursive parameter.

If recursive is set to true but a found directory is rejected by the matcher, then there won't be any recursion into such directory.

Parameters

Name Type Description Default Value Required

Configuration

String

The name of the configuration to use.

x 

Directory Path

String

the path to the directory to be listed

x 

Recursive

Boolean

whether to include the contents of sub-directories. Defaults to false.

false

 

File Matching Rules

One of:

a matcher used to filter the output list

 

Target Variable

String

The name of a variable on which the operation's output will be placed

 

Output

Type

Array of Message of [Binary] payload and [Local File Attributes] attributes

For Configurations.

Throws

  • FILE:ACCESS_DENIED  

  • FILE:CONNECTIVITY  

  • FILE:RETRY_EXHAUSTED  

  • FILE:ILLEGAL_PATH  

Move

<file:move>

Moves the file at the sourcePath into the targetPath.

If targetPath doesn't exists, and neither does its parent, then an attempt will be made to create depending on the value of the createParentFolder argument. If such argument is false, then an IllegalArgumentException will be thrown.

If the target file already exists, then it will be overwritten if the overwrite argument is true. Otherwise, IllegalArgumentException will be thrown.

As for the sourcePath, it can either be a file or a directory. If it points to a directory, then it will be moved recursively.

Parameters

Name Type Description Default Value Required

Configuration

String

The name of the configuration to use.

x 

Source Path

String

the path to the file to be copied

x 

Target Path

String

the target directory

x 

Create Parent Directories

Boolean

whether or not to attempt creating any parent directories which don't exists.

true

 

Overwrite

Boolean

whether or not overwrite the file if the target destination already exists.

false

 

For Configurations.

Throws

  • FILE:CONNECTIVITY  

  • FILE:RETRY_EXHAUSTED  

  • FILE:ILLEGAL_PATH  

  • FILE:FILE_ALREADY_EXISTS  

Read

<file:read>

Obtains the content and metadata of a file at a given path. The operation itself returns a Message which payload is a InputStream with the file's content, and the metadata is represent as a LocalFileAttributes object that's placed as the message Message#getAttributes() attributes.

If the lock parameter is set to true, then a file system level lock will be placed on the file until the input stream this operation returns is closed or fully consumed. Because the lock is actually provided by the host file system, its behavior might change depending on the mounted drive and the operation system on which mule is running. Take that into consideration before blindly relying on this lock.

This method also makes a best effort to determine the mime type of the file being read. A MimetypesFileTypeMap will be used to make an educated guess on the file's mime type. The user also has the chance to force the output encoding and mimeType through the outputEncoding and outputMimeType optional parameters.

Parameters

Name Type Description Default Value Required

Configuration

String

The name of the configuration to use.

x 

File Path

String

the path to the file to be read

x 

Lock

Boolean

whether or not to lock the file. Defaults to false.

false

 

Output Mime Type

String

The mime type of the payload that this operation outputs.

 

Output Encoding

String

The encoding of the payload that this operation outputs.

 

Streaming Strategy

Configure if repeatable streams should be used and their behaviour

 

Target Variable

String

The name of a variable on which the operation's output will be placed

 

Output

Type

Binary

Attributes Type

For Configurations.

Throws

  • FILE:FILE_LOCK  

  • FILE:ACCESS_DENIED  

  • FILE:CONNECTIVITY  

  • FILE:RETRY_EXHAUSTED  

  • FILE:ILLEGAL_PATH  

Rename

<file:rename>

Renames the file pointed by path to the name provided on the to parameter

to argument should not contain any path separator. IllegalArgumentException will be thrown if this precondition is not honored.

Parameters

Name Type Description Default Value Required

Configuration

String

The name of the configuration to use.

x 

Path

String

the path to the file to be renamed

x 

New Name

String

the file's new name

x 

Overwrite

Boolean

whether or not overwrite the file if the target destination already exists.

false

 

For Configurations.

Throws

  • FILE:ACCESS_DENIED  

  • FILE:CONNECTIVITY  

  • FILE:RETRY_EXHAUSTED  

  • FILE:ILLEGAL_PATH  

  • FILE:FILE_ALREADY_EXISTS  

Write

<file:write>

Writes the content into the file pointed by path.

If the directory on which the file is attempting to be written doesn't exist, then the operation will either throw IllegalArgumentException or create such folder depending on the value of the createParentDirectory.

If the file itself already exists, then the behavior depends on the supplied mode.

This operation also supports locking support depending on the value of the lock argument, but following the same rules and considerations as described in the read operation. not set, then it defaults to FileConnectorConfig#getDefaultWriteEncoding()

Parameters

Name Type Description Default Value Required

Configuration

String

The name of the configuration to use.

x 

Path

String

the path of the file to be written

 

Content

Binary

the content to be written into the file. Defaults to the current Message payload

#[payload]

 

Encoding

String

when content is a String, this attribute specifies the encoding to be used when writing. If

 

Create Parent Directories

Boolean

whether or not to attempt creating any parent directories which don't exists.

true

 

Lock

Boolean

whether or not to lock the file. Defaults to false

false

 

Write Mode

Enumeration, one of:

  • OVERWRITE

  • APPEND

  • CREATE_NEW

a FileWriteMode. Defaults to OVERWRITE

OVERWRITE

 

For Configurations.

Throws

  • FILE:ACCESS_DENIED  

  • FILE:CONNECTIVITY  

  • FILE:RETRY_EXHAUSTED  

  • FILE:ILLEGAL_PATH  

  • FILE:ILLEGAL_CONTENT  

  • FILE:FILE_ALREADY_EXISTS  

Sources

Directory Listener

<file:directory-listener>

Listens for near real-time events that happens on files contained inside a directory or on the directory itself. The events are not acquired by polling the filesystem but rather actually listening for operating system events.

Whenever a file (or the directory) is created, updated or deleted, this Source will fire a Message which payload reference the affected file and the attributes will be a ListenerFileAttributes instance.

There're however some special cases to be considered:

  • If the file has been deleted, then it's not possible to obtain its content so the message payload will be null
  • Also in the case of file deletion, all its attributes are also not available. Thus, the message attributes will actually be an instance of DeletedFileAttributes which throws IllegalStateException whenever a non available attribute is requested
  • When the event references a directory, then the payload is also a null

When to use it

This source is useful in cases in which a flow should respond to changes done on the filesystem, examples being trigger files, transaction files being added on a drop folder, settings files updated, etc. All of the above cases could be done using a operation inside a poll scope (maybe also combined with a .

However, although polling is a powerful and reliable solution, it's not an efficient one. Because this listener relies on operating system notifications, it's much more efficient in terms of resources.

Reliability

The trade-off between a poll reliability and this listener's performance is reliability. Because operating system events don't generally include the concept of transaction or replay, there's no way to guarantee that no event is going to be lost in case of failure or server crash. Although you can always use mule to implement a reliable acquisition pattern, there's no fallback is such acquisition fails. What this means is that this listener is no silver bullet and it should not been seen as the recommended approach over a poll+list+watermark approach. Users should analyse each use case and environment to determine which the best option is.

Operating system limitations

This component's behaviour might be slightly different depending on the OS on which it is deployed. The main differences are usually (but not exclusively) related to:

  • Overflows: In highly concurrent scenarios a given file might be associated to hundreds of events per second. Some OS might not be able to handle that gracefully and decide to drop some of those events or even fail.
  • Polling: Some operation systems (like older versions of OSX) don't actually support file system notifications. In those cases, the JRE decides to compensate by using a high frequency poll, in which case the listener becomes pretty much the same as using a poll element

Parameters

Name Type Description Default Value Required

Configuration

String

The name of the configuration to use.

x 

Directory

String

The directory on which notifications are being listened to

 

Notify On Create

Boolean

Whether to react to creation notifications. Defaults to true

true

 

Notify On Update

Boolean

Whether to react to update notifications. Defaults to true

true

 

Notify On Delete

Boolean

Whether to react to deletion notifications. Defaults to true

false

 

Recursive

Boolean

Whether or not to also listen for notification which happen on sub directories which are also contained on the main one.

This option is set to false by default. Consider that when enabled, some operating systems might fire many notifications when an event happens on a subdirectory. One per each watched directory on the notification's path.

false

 

Match with

One of:

A matcher used to filter events on files which do not meet the matcher's criteria

 

Redelivery Policy

Defines a policy for processing the redelivery of the same message

 

Streaming Strategy

Configure if repeatable streams should be used and their behaviour

 

Reconnection Strategy

A retry strategy in case of connectivity errors

 

Output

Type

Binary

Attributes Type

For Configurations.

Types

Reconnect

Field Type

Frequency

Number

Count

Number

Blocking

Boolean

Reconnect Forever

Field Type

Frequency

Number

Listener File Attributes

Field Type

Creation Time

DateTime

Directory

Boolean

Event Type

String

Last Access Time

DateTime

Last Modified Time

DateTime

Name

String

Path

String

Regular File

Boolean

Size

Number

Symbolic Link

Boolean

Redelivery Policy

Field Type

Max Redelivery Count

Number

Use Secure Hash

Boolean

Message Digest Algorithm

String

Id Expression

String

Object Store Ref

String

Repeatable In Memory Stream

Field Type

Initial Buffer Size

Number

Buffer Size Increment

Number

Max In Memory Size

Number

Buffer Unit

Enumeration, one of:

  • BYTE

  • KB

  • MB

  • GB

Repeatable File Store Stream

Field Type

Max In Memory Size

Number

Buffer Unit

Enumeration, one of:

  • BYTE

  • KB

  • MB

  • GB

Local File Attributes

Field Type

Creation Time

DateTime

Directory

Boolean

Last Access Time

DateTime

Last Modified Time

DateTime

Name

String

Path

String

Regular File

Boolean

Size

Number

Symbolic Link

Boolean

Matcher

Field Type

Created Since

DateTime

Created Until

DateTime

Updated Since

DateTime

Updated Until

DateTime

Accessed Since

DateTime

Accessed Until

DateTime

Filename Pattern

String

Path Pattern

String

Directory

Boolean

Regular File

Boolean

Symbolic Link

Boolean

Min Size

Number

Max Size

Number