Hi
In Camel 2.x we have a file component with a filter bean and now migrating to
Camel 3 the bean is not found and program crashes upon start.
The migration has been only with the route converting to use
EndpointRoutebuilder, the config, bean and class is unchanged.
Config
@Bean
public static
HouseKeepingFileFilter
<
String
>
houseKeepingFileFilter
() {
return new
HouseKeepingFileFilter
<>()
;
}
Impl
@CommonsLog
public class
HouseKeepingFileFilter
<T>
implements
GenericFileFilter
<
String
> {
public boolean
accept
(
GenericFile
file) {
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
)
;
final boolean
isValid
=
file
.
isDirectory
()
?
true
:
file
.
getLastModified
()
<
LocalDateTime
.
now
()
.
minusMonths
(1L)
.
atZone
(
ZoneId
.
systemDefault
())
.
toInstant
()
.
toEpochMilli
()
;
log
.
trace
(
MessageFormat
.
format
(
"File :{0}, with modification date: {1} is {2} for archive"
,
file
.
getFileName
()
,
sdf
.
format
(file
.
getLastModified
())
,
isValid
?
"valid"
:
"NOT valid"
))
;
return
isValid
;
}
}
Camel 3
@Override
public void
configure
()
throws
Exception
{
from
(
file
(
"mifir/"
)
.
antInclude
(
"{{housekeeping.files.include}}"
)
.
antExclude
(
"**/archive/**,**/data/**,**/LegalReportingModuleTransporterBridge/**,**/MAPPING/**,{{housekeeping.files.exclude}}"
)
.
recursive
(
true
)
.
filter
(
"#houseKeepingFileFilter"
)
.
scheduler
(
"quartz"
)
.
schedulerProperties
(
"cron"
,
"{{housekeeping.cron}}"
)
.
schedulerProperties
(
"triggerId"
,
"houseKeepingId"
)
.
schedulerProperties
(
"triggerGroup"
,
"houseKeepingGroup"
))
.
description
(
"HOUSEKEEPING-ROUTE"
,
"Archive files older than a month"
,
"en"
)
.
process
(s
->
{
long
houseKeepingSize
=
0L
;
final
Message
in
=
s
.
getIn
()
;
try
{
houseKeepingSize
=
in
.
getHeader
(
"HouseKeepingSize"
,
Long
.
class
)
;
}
catch
(
Exception
ignored) {
}
final
File
body
=
in
.
getBody
(
File
.
class
)
;
houseKeepingSize
+=
body
.
length
()
;
in
.
setHeader
(
"HouseKeepingSize"
,
houseKeepingSize
)
;
})
.
aggregate
(
constant
(
true
)
,
new
ZipAggregationStrategy
(
true
))
.
to
(
log
(
"HouseKeeping"
)
.
level
(
"INFO"
)
.
groupInterval
(5_000L)
.
groupActiveOnly
(
true
))
.
completionFromBatchConsumer
()
.
eagerCheckCompletion
()
.
to
(
file
(
"mifir/archive"
))
.
log
(
"Monthly housekeeping is done! Archived ${exchangeProperty.CamelAggregatedSize}
files and saved ${header.HouseKeepingSize} bytes"
)
.
end
()
;
}
Camel 2
@Override
public void
configure
()
throws
Exception
{
from
(
"file:mifir/"
+
"?antInclude={{housekeeping.files.include}}"
+
"&antExclude=**/archive/**,**/data/**,**/LegalReportingModuleTransporterBridge/**,**/MAPPING/**,{{housekeeping.files.exclude}}"
+
"&recursive=true"
+
"&filter=#houseKeepingFileFilter"
+
"&scheduler=quartz2"
+
"&scheduler.cron={{housekeeping.cron}}"
+
"&scheduler.triggerId=houseKeepingId"
+
"&scheduler.triggerGroup=houseKeepingGroup"
)
.
description
(
"HOUSEKEEPING-ROUTE"
,
"Archive files older than a month"
,
"en"
)
.
process
(s
->
{
long
houseKeepingSize
=
0L
;
final
Message
in
=
s
.
getIn
()
;
try
{
houseKeepingSize
=
in
.
getHeader
(
"HouseKeepingSize"
,
Long
.
class
)
;
}
catch
(
Exception
ignored) {
}
final
File
body
=
in
.
getBody
(
File
.
class
)
;
houseKeepingSize
+=
body
.
length
()
;
in
.
setHeader
(
"HouseKeepingSize"
,
houseKeepingSize
)
;
})
.
aggregate
(
constant
(
true
)
,
new
ZipAggregationStrategy
(
true
))
.
to
(
"log:HouseKeeping?level=INFO&groupInterval=5000&groupActiveOnly=true"
)
.
completionFromBatchConsumer
()
.
eagerCheckCompletion
()
.
to
(
"file:mifir/archive"
)
.
log
(
"Monthly housekeeping is done! Archived ${property.CamelAggregatedSize} files
and saved ${header.HouseKeepingSize} bytes"
)
.
end
()
;
}
Read the migration guide but not finding any clues…
From Camel 2.25.3 to 3.6.0
/M