Skip to content

Commit 45c22ff

Browse files
committed
CAMEL-23033: camel-yaml-dsl - Setting routePolicy on route should be routePolicyRef. Also polished docs, and made onException route dumper correct for handled/continued
1 parent 1af05c0 commit 45c22ff

File tree

12 files changed

+209
-51
lines changed

12 files changed

+209
-51
lines changed

core/camel-core-model/src/main/java/org/apache/camel/model/OnExceptionDefinition.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@
3131
import org.apache.camel.LoggingLevel;
3232
import org.apache.camel.Predicate;
3333
import org.apache.camel.Processor;
34-
import org.apache.camel.builder.ExpressionBuilder;
34+
import org.apache.camel.model.language.ConstantExpression;
3535
import org.apache.camel.spi.AsPredicate;
3636
import org.apache.camel.spi.Metadata;
37-
import org.apache.camel.support.ExpressionToPredicateAdapter;
3837
import org.apache.camel.util.ObjectHelper;
3938

4039
/**
@@ -222,8 +221,8 @@ public OnExceptionDefinition onException(Class<? extends Throwable> exceptionTyp
222221
* @return the builder
223222
*/
224223
public OnExceptionDefinition handled(boolean handled) {
225-
Expression expression = ExpressionBuilder.constantExpression(Boolean.toString(handled));
226-
return handled(expression);
224+
setHandled(new ExpressionSubElementDefinition(new ConstantExpression(Boolean.toString(handled))));
225+
return this;
227226
}
228227

229228
/**
@@ -233,7 +232,7 @@ public OnExceptionDefinition handled(boolean handled) {
233232
* @return the builder
234233
*/
235234
public OnExceptionDefinition handled(@AsPredicate Predicate handled) {
236-
setHandledPolicy(handled);
235+
setHandled(new ExpressionSubElementDefinition(handled));
237236
return this;
238237
}
239238

@@ -244,7 +243,7 @@ public OnExceptionDefinition handled(@AsPredicate Predicate handled) {
244243
* @return the builder
245244
*/
246245
public OnExceptionDefinition handled(@AsPredicate Expression handled) {
247-
setHandledPolicy(ExpressionToPredicateAdapter.toPredicate(handled));
246+
setHandled(new ExpressionSubElementDefinition(handled));
248247
return this;
249248
}
250249

@@ -257,8 +256,8 @@ public OnExceptionDefinition handled(@AsPredicate Expression handled) {
257256
* @return the builder
258257
*/
259258
public OnExceptionDefinition continued(boolean continued) {
260-
Expression expression = ExpressionBuilder.constantExpression(Boolean.toString(continued));
261-
return continued(expression);
259+
setContinued(new ExpressionSubElementDefinition(new ConstantExpression(Boolean.toString(continued))));
260+
return this;
262261
}
263262

264263
/**
@@ -270,7 +269,7 @@ public OnExceptionDefinition continued(boolean continued) {
270269
* @return the builder
271270
*/
272271
public OnExceptionDefinition continued(@AsPredicate Predicate continued) {
273-
setContinuedPolicy(continued);
272+
setContinued(new ExpressionSubElementDefinition(continued));
274273
return this;
275274
}
276275

@@ -283,7 +282,7 @@ public OnExceptionDefinition continued(@AsPredicate Predicate continued) {
283282
* @return the builder
284283
*/
285284
public OnExceptionDefinition continued(@AsPredicate Expression continued) {
286-
setContinuedPolicy(ExpressionToPredicateAdapter.toPredicate(continued));
285+
setContinued(new ExpressionSubElementDefinition(continued));
287286
return this;
288287
}
289288

@@ -310,7 +309,7 @@ public OnExceptionDefinition onWhen(@AsPredicate Predicate predicate) {
310309
* @return the builder
311310
*/
312311
public OnExceptionDefinition retryWhile(@AsPredicate Predicate retryWhile) {
313-
setRetryWhilePolicy(retryWhile);
312+
setRetryWhile(new ExpressionSubElementDefinition(retryWhile));
314313
return this;
315314
}
316315

docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_18.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ Note that manual migration is still required.
1111
See the xref:camel-upgrade-recipes-tool.adoc[documentation] page for details.
1212
====
1313

14+
== Upgrading from 4.18.0 to 4.18.1
15+
16+
In the YAML DSL we have renamed `routePolicy` to `routePolicyRef` on the `route` node,
17+
as that is the correct name.
18+
19+
1420
== Upgrading Camel 4.17 to 4.18
1521

1622
=== camel-simple

docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_19.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Removed 2 deprecated methods in Java DSL for `throttler` EIP.
2222

2323
=== camel-yaml-io / camel-xml-io
2424

25+
In the YAML DSL we have renamed `routePolicy` to `routePolicyRef` on the `route` node,
26+
as that is the correct name.
27+
2528
When dumping routes in YAML or XML format via `camel-yaml-io` or `camel-xml-io` then the structure of routes
2629
and all the EIP options now respect the intended order in the model.
2730

docs/user-manual/modules/ROOT/pages/cronscheduledroutepolicy.adoc

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ information must be provided.
2626
=== Starting a route
2727

2828
[width="100%",cols="25%,25%,25%,25%",options="header",]
29-
|=======================================================================
29+
|===
3030
|Parameter Name |Type |Default Value |Description
3131
|routeStartTime |String | |the initial scheduled date and time as a
3232
Cron Expression for route start
33-
|=======================================================================
33+
|===
3434

3535
=== Stopping a route
3636

3737
[width="100%",cols="25%,25%,25%,25%",options="header",]
38-
|=======================================================================
38+
|===
3939
|Parameter Name |Type |Default Value |Description
4040
|routeStopTime |String | |the initial scheduled date and time as a Cron
4141
Expression for route stop
@@ -45,33 +45,36 @@ initiating graceful route stop
4545

4646
|routeStopTimeUnit |long |TimeUnit.MILLISECONDS |the time unit for the
4747
grace period expressed as `java.util.concurrent.TimeUnit`
48-
|=======================================================================
48+
|===
4949

5050
=== Suspending a route
5151

5252
[width="100%",cols="25%,25%,25%,25%",options="header",]
53-
|=======================================================================
53+
|===
5454
|Parameter Name |Type |Default Value |Description
5555
|routeSuspendTime |String | |the initial scheduled date and time as a
5656
Cron Expression for route suspension
57-
|=======================================================================
57+
|===
5858

5959
=== Resuming a route
6060

6161
[width="100%",cols="25%,25%,25%,25%",options="header",]
62-
|=======================================================================
62+
|===
6363
|Parameter Name |Type |Default Value |Description
6464
|routeResumeTime |String | |the initial scheduled date and time as a
6565
Cron Expression for route resumption
66-
|=======================================================================
66+
|===
6767

6868
== Configuring the route policy
6969

7070
Once the `org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy`
7171
is created it can be wired into the Camel route as follows:
7272

73-
In Java:
73+
[tabs]
74+
====
7475
76+
Java::
77+
+
7578
[source,java]
7679
----
7780
CronScheduledRoutePolicy startPolicy = new CronScheduledRoutePolicy();
@@ -82,8 +85,8 @@ from("direct:start")
8285
.to("mock:success");
8386
----
8487
85-
And with Spring XML:
86-
88+
Spring XML::
89+
+
8790
[source,xml]
8891
----
8992
<bean id="startPolicy" class="org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy">
@@ -98,6 +101,27 @@ And with Spring XML:
98101
</camelContext>
99102
----
100103
104+
YAML::
105+
+
106+
[source,yaml]
107+
----
108+
- beans:
109+
- name: startPolicy
110+
type: org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy
111+
properties:
112+
routeStartTime: "*/3 * * * * ?"
113+
- route:
114+
id: testRoute
115+
autoStartup: "false"
116+
routePolicyRef: startPolicy
117+
from:
118+
uri: direct:start
119+
steps:
120+
- to:
121+
uri: mock:success
122+
----
123+
====
124+
101125
IMPORTANT: Notice how the route to be scheduled *MUST* be configured to not
102126
xref:configuring-route-startup-ordering-and-autostartup.adoc[auto-startup], to let
103127
the route scheduler take control of starting and stopping the route accordingly.

docs/user-manual/modules/ROOT/pages/debugger.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ method and return `true`.
1515
In this unit test
1616

1717
[source,java]
18-
-----------------------------------------------
18+
----
1919
public class DebugTest extends CamelTestSupport
20-
-----------------------------------------------
20+
----
2121

2222
We want to debug the following route
2323

2424
[source,java]
25-
-----------------------------------------------
25+
----
2626
@Override
2727
protected RouteBuilder createRouteBuilder() throws Exception {
2828
return new RouteBuilder() {
@@ -36,7 +36,7 @@ protected RouteBuilder createRouteBuilder() throws Exception {
3636
}
3737
};
3838
}
39-
-----------------------------------------------
39+
----
4040

4141
Which can easily done by overriding the `debugBefore` method as shown
4242

@@ -83,7 +83,7 @@ A trick to debug a Camel route written with Java DSL is to modify the route to i
8383
For instance:
8484

8585
[source,java]
86-
-----------------------------------------------
86+
----
8787
public class MyRouteBuilder extends RouteBuilder {
8888
8989
@Override
@@ -101,7 +101,7 @@ public class MyRouteBuilder extends RouteBuilder {
101101
.log("${body}");
102102
}
103103
}
104-
-----------------------------------------------
104+
----
105105

106106
=== Implementing a custom debugger
107107

docs/user-manual/modules/ROOT/pages/defaulterrorhandler.adoc

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,111 @@ In this route below, any exception thrown in, such as the `validateOrder`
3030
bean, will be propagated back to the caller via the jetty endpoint, which
3131
then returns an HTTP error message back to the client.
3232

33+
[tabs]
34+
====
35+
36+
Java::
37+
+
3338
[source,java]
3439
----
3540
from("jetty:http://localhost/myservice/order")
3641
.to("bean:validateOrder")
3742
.to("jms:queue:order");
3843
----
3944
45+
XML::
46+
+
47+
[source,xml]
48+
----
49+
<route>
50+
<from uri="jetty:http://localhost/myservice/order"/>
51+
<to uri="bean:validateOrder"/>
52+
<to uri="jms:queue:order"/>
53+
</route>
54+
----
55+
56+
YAML::
57+
+
58+
[source,yaml]
59+
----
60+
- route:
61+
from:
62+
uri: jetty:http://localhost/myservice/order
63+
steps:
64+
- to:
65+
uri: bean:validateOrder
66+
- to:
67+
uri: jms:queue:order
68+
----
69+
====
70+
4071
We can add an `onException` in case we want to catch certain exceptions
4172
and route them differently, for instance to catch a
42-
`ValidationException` and return a fixed response to the caller.
73+
`org.apache.camel.ValidationException` and return a fixed response to the caller.
74+
75+
[tabs]
76+
====
4377
78+
Java::
79+
+
4480
[source,java]
4581
----
4682
onException(ValidationException.class)
4783
.handled(true)
48-
.transform(body(constant("INVALID ORDER")));
84+
.transform(constant("INVALID ORDER"));
4985
5086
from("jetty:http://localhost/myservice/order")
5187
.to("bean:validateOrder")
5288
.to("jms:queue:order");
5389
----
5490
91+
XML::
92+
+
93+
[source,xml]
94+
----
95+
<onException>
96+
<exception>org.apache.camel.ValidationException</exception>
97+
<handled>
98+
<constant>true</constant>
99+
</handled>
100+
<transform>
101+
<constant>INVALID ORDER</constant>
102+
</transform>
103+
</onException>
104+
105+
<route>
106+
<from uri="jetty:http://localhost/myservice/order"/>
107+
<to uri="bean:validateOrder"/>
108+
<to uri="jms:queue:order"/>
109+
</route>
110+
----
111+
112+
YAML::
113+
+
114+
[source,yaml]
115+
----
116+
- onException:
117+
exception:
118+
- org.apache.camel.ValidationException
119+
handled:
120+
constant:
121+
expression: "true"
122+
steps:
123+
- transform:
124+
expression:
125+
constant:
126+
expression: INVALID ORDER
127+
- route:
128+
from:
129+
uri: jetty:http://localhost/myservice/order
130+
steps:
131+
- to:
132+
uri: bean:validateOrder
133+
- to:
134+
uri: jms:queue:order
135+
----
136+
====
137+
55138
When the `ValidationException` is thrown from the `validateOrder` bean,
56139
it is intercepted by Camel error handler which lets the
57140
`onException(ValidationException.class)` handle the exception.

0 commit comments

Comments
 (0)