Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

JCIFS

...

Component

...

Available

...

as

...

of

...

Camel

...

2.

...

11.0

This component provides access to remote file systems over the CIFS/SMB

...

networking

...

protocol.

...

The

...

camel-jcifs

...

library

...

is

...

provided

...

by

...

the

...

Camel

...

Extra

...

project

...

which

...

hosts

...

all

...

*GPL

...

related

...

components

...

for

...

Camel.

...

Maven

...

users

...

will

...

need

...

to

...

add

...

the

...

following

...

dependency

...

to

...

their

...

pom.xml

...

for

...

this

...

component:

...

...

Make

...

sure

...

you

...

read

...

the

...

section

...

titled

...

Default

...

when

...

consuming

...

files

...

further

...

below

...

for

...

details

...

related

...

to

...

consuming

...

files.

...

URI format

...

Where share represents the share to connect to and dir is optionaly any underlying directory. Can contain nested folders.

You can append query options to the URI in the following format, ?option=value&option=value&...

...

This

...

component

...

uses

...

the

...

JCIFS

...

library

...

for

...

the

...

actual

...

CIFS/SMB

...

work.

...

URI

...

Options

...

The

...

options

...

below

...

are

...

exclusive

...

for

...

the

...

JCIFS

...

component.

...

...

Name

Default Value

Description

password

null

Mandatory Specifies the password to use to log in to the remote file system.

localWorkDirectory

null

When consuming, a local work directory can be used to store the remote file content directly in local files, to avoid loading the content into memory. This is beneficial, if you consume a very big remote file and thus can conserve memory. See below for more details.

...

See File for more options as all the options from File is inherited.

...

For example to set the localWorkDirectory to ''/tmp'' you can do:

...

You can have as many of these options as you like.

Examples

smb://foo@myserver.example.com/sharename?password=secret

...


smb://companydomain;foo@myserver.company.com/sharename?password=secret

...

...

This component is an extension of the File component. So there are more samples and details on the File component page.

...

Message Headers

The following message headers can be used to affect the behavior of the component

...

Header

Description

CamelFileName

Specifies the output file name (relative to the endpoint directory) to be used for the output message when sending to the endpoint. If this is not present and no expression either, then a generated message ID is used as the filename instead.

CamelFileNameProduced

The actual absolute filepath (path + name) for the output file that was written. This header is set by Camel and its purpose is providing end-users the name of the file that was written.

CamelFileBatchIndex

Current index out of total number of files being consumed in this batch.

CamelFileBatchSize

Total number of files being consumed in this batch.

CamelFileHost

The remote hostname.

CamelFileLocalWorkPath

Path to the local work file, if local work directory is used.

...

Using Local Work Directory

Camel JCIFS supports consuming from remote servers and downloading the files directly into a local work directory. This avoids reading the entire remote file content into memory as it is streamed directly into the local file using FileOutputStream.

Camel JCIFS will store to a local file with the same name as the remote file. And finally, when the Exchange is complete the local file is deleted.

So if you want to download files from a remote server and store it as files then you need to route to a file endpoint such as:

...

The

...

route

...

above

...

is

...

ultra

...

efficient

...

as

...

it

...

avoids

...

reading

...

the

...

entire

...

file

...

content

...

into

...

memory.

...

It

...

will

...

download

...

the

...

remote

...

file

...

directly

...

to

...

a

...

local

...

file

...

stream.

...

The

...

java.io.File

...

handle

...

is

...

then

...

used

...

as

...

the

...

Exchange

...

body.

...

The

...

file

...

producer

...

leverages

...

this

...

fact

...

and

...

can

...

work

...

directly

...

on

...

the

...

work

...

file

...

java.io.File

...

handle

...

and

...

perform

...

a

...

java.io.File.rename

...

to

...

the

...

target

...

filename.

...

As

...

Camel

...

knows

...

it's

...

a

...

local

...

work

...

file,

...

it

...

can

...

optimize

...

and

...

use

...

a

...

rename

...

instead

...

of

...

a

...

file

...

copy,

...

as

...

the

...

work

...

file

...

is

...

meant

...

to

...

be

...

deleted

...

anyway.

...

Samples

In the sample below we set up Camel to download all the reports from the SMB/CIFS server once every hour (60 min) and store it as files on the local file system.

...

And the route using Spring DSL:

...

Filter using org.apache.camel.component.file.GenericFileFilter

...

Camel

...

supports

...

pluggable

...

filtering

...

strategies.

...

This

...

strategy

...

it

...

to

...

use

...

the

...

build

...

in

...

org.apache.camel.component.file.GenericFileFilter

...

in

...

Java.

...

You

...

can

...

then

...

configure

...

the

...

endpoint

...

with

...

such

...

a

...

filter

...

to

...

skip

...

certain

...

filters

...

before

...

being

...

processed.

...

In

...

the

...

sample

...

we

...

have

...

built

...

our

...

own

...

filter

...

that

...

only

...

accepts

...

files

...

starting

...

with

...

report

...

in

...

the

...

filename.

...

...

And

...

then

...

we

...

can

...

configure

...

our

...

route

...

using

...

the

...

filter

...

attribute

...

to

...

reference

...

our

...

filter

...

(using

...

#

...

notation)

...

that

...

we

...

have

...

defined

...

in

...

the

...

spring

...

XML

...

file:

...

...

Filtering using ANT path matcher

The ANT path matcher is a filter that is shipped out-of-the-box

...

in

...

the

...

camel-spring

...

jar.

...

So

...

you

...

need

...

to

...

depend

...

on

...

camel-spring

...

if

...

you

...

are

...

using

...

Maven.

...


The

...

reason

...

is

...

that

...

we

...

leverage

...

Spring's

...

AntPathMatcher

...

to

...

do

...

the

...

actual

...

matching.

...

The

...

file

...

paths

...

are

...

matched

...

with

...

the

...

following

...

rules:

...

  • ? matches one character
  • * matches zero or more characters
  • ** matches zero or more directories in a path

The sample below demonstrates how to use it:

...