[
https://issues.apache.org/jira/browse/CAMEL-23279?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Work on CAMEL-23279 started by Federico Mariani.
------------------------------------------------
> SamplingDefinition.description() fails with NumberFormatException when
> samplePeriod uses property placeholders
> --------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-23279
> URL: https://issues.apache.org/jira/browse/CAMEL-23279
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 4.18.1
> Reporter: Dmitrii Ostapchuk
> Assignee: Federico Mariani
> Priority: Major
>
> *Bug Description*
> `samplePeriod` attribute of `<sample>` component does not support property
> placeholders (e.g., `{{{{{}value{}}}}}`), while `timePeriodMillis` attribute
> of `<throttle>` component with identical metadata works correctly.
>
> *Root Cause*
> `SamplingDefinition.description()` tries to parse `samplePeriod` via
> `TimeUtils.toDuration()` before placeholder resolution, while
> `ThrottleDefinition.description()` simply returns `timePeriodMillis` as a raw
> String.
>
> *Steps to Reproduce*
> 1. Add property to application.properties:
> sample.period=5000
> 2. Configure route:
> <sample samplePeriod="{{{{{}sample.period{}}}}}"/>
> 3. Start application
>
> *Expected Behavior*
> Route starts successfully, samplePeriod resolved to 5000
>
> *Actual Behavior*
> java.lang.NumberFormatException: For input string: "{{sample.perio"
> at org.apache.camel.util.TimeUtils.toMilliSeconds(TimeUtils.java:194)
> at org.apache.camel.util.TimeUtils.toDuration(TimeUtils.java:153)
> at
> org.apache.camel.model.SamplingDefinition.description(SamplingDefinition.java:89)
> at
> org.apache.camel.model.SamplingDefinition.toString(SamplingDefinition.java:82)
>
> *Root Cause Code*
> {code:java}
> // SamplingDefinition.description() - BROKEN:
> protected String description() {
> if (messageFrequency != null) {
> return "1 Exchange per " + getMessageFrequency() + " messages received";
>
> } else {
> // Tries to parse placeholder before resolution
> return "1 Exchange per " +
> TimeUtils.printDuration(TimeUtils.toDuration(samplePeriod));
> }
> }
> // ThrottleDefinition.description() - WORKS:
> protected String description() {
> // Just returns raw String - no parsing
> return getExpression() + " request per " + getTimePeriodMillis() + "
> millis";
> }{code}
>
> *Suggested Fix*
> {code:java}
> // In SamplingDefinition.description():
> protected String description() {
> if (messageFrequency != null) {
> return "1 Exchange per " + getMessageFrequency() + " messages
> received";
> } else {
> // Just return raw string like ThrottleDefinition does
> return "1 Exchange per " + getSamplePeriod();
> }
> }
> {code}
>
> *Environment*
> - Camel version: 4.18.1
> - Java version: 21
> - Spring version: 6
--
This message was sent by Atlassian Jira
(v8.20.10#820010)