[
https://issues.apache.org/jira/browse/CAMEL-25178?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18121200#comment-18121200
]
Claus Ibsen commented on CAMEL-25178:
-------------------------------------
Two findings about the Switch EIP, for this issue. Both are in the Switch model
classes, so they are left to this issue rather than changed from
CAMEL-25192/CAMEL-25193.
*1. Endpoint DSL overloads are missing*
SwitchDefinition takes destinations as String only:
* doCase(String value, String uri)
* doCase(String value).to(String uri) (SwitchDefinition.CaseBuilder)
* otherwise(String uri)
to(...) in ProcessorDefinition also takes an EndpointProducerBuilder, so with
the endpoint DSL this does not compile today:
{code:java}
from(direct("tickets"))
.doSwitch(header("department"))
.doCase("billing", direct("billing"))
.doCase("technical").to(direct("technical"))
.otherwise(direct("review"))
.end();
{code}
Suggested: add doCase(String, EndpointProducerBuilder),
CaseBuilder.to(EndpointProducerBuilder) and otherwise(EndpointProducerBuilder),
resolving the uri the same way ToDefinition does for an
EndpointProducerBuilder. Also document it on switch-eip.adoc. The Java DSL
parser (LwJavaParser, camel-java-io) replays these methods, so add a case to
LwJavaParserTest, and the endpoint DSL variant to the switch tests of
JavaRouteScannerTest / ProjectOverviewTest if wanted.
*2. route-structure dev console does not show where a case goes*
For this route:
{code:java}
from("direct:tickets").routeId("tickets")
.doSwitch(header("department"))
.doCase("billing", "direct:billing")
.doCase("technical").to("direct:technical")
.otherwise("direct:review")
.end();
{code}
the route-structure console (RouteStructureDevConsole) prints:
{noformat}
switch[header{department}]
case[billing]
case[technical]
to[direct:review]
{noformat}
The case uri is not shown, and the fallback reads as a plain to. Suggested
labels: case[billing -> direct:billing] (or similar) from
SwitchCaseDefinition.getLabel(), and otherwise[direct:review] for the fallback.
The fallback currently appears through
SwitchDefinition.getOtherwiseDefinition() (a ToDefinition) in getChildren().
The route-topology console is fine: it shows tickets --> billing / technical /
review via direct:..., as it finds the EndpointRequiredDefinition children.
*Already done elsewhere, for reference*
* CAMEL-25192 (TUI Source tab jump links): Java and YAML switch cases and
otherwise link to the route of their uri; LwJavaParser gives switch cases and
the fallback the line of their call.
* CAMEL-25193 (project overview): the Java, YAML and XML readers take the case
and otherwise uris as endpoints the route sends to, so the TUI Architecture and
Topology views connect routes through a switch.
_Claude Code on behalf of davsclaus_
> Improve Switch EIP discoverability and DSL round-trip coverage
> --------------------------------------------------------------
>
> Key: CAMEL-25178
> URL: https://issues.apache.org/jira/browse/CAMEL-25178
> Project: Camel
> Issue Type: Improvement
> Components: camel-core, camel-jbang-mcp, camel-spring-xml,
> camel-xml-io, camel-yaml-dsl
> Reporter: Luigi De Masi
> Assignee: Luigi De Masi
> Priority: Major
>
> Expand Switch EIP documentation and AI discoverability, and add
> resource-based loading and round-trip coverage across XML, YAML, and Spring
> XML.
> Document that Switch cases route through direct:/seda: endpoints, while
> Choice supports predicates, ranges, and inline branches. Add appropriate EIP
> and AI pattern index entries, model aliases, and catalog/prompt mappings.
> Include a concise semantic selector example with a single reference and
> scalar result; reserve refs:department,urgent for documentation about batched
> semantic results.
> Add coverage for XML namespace serialization, YAML printing and route
> loading, Spring XML schema/namespace handling, and YAML schema
> acceptance/rejection.
> Comment written by Codex on behalf of [~ldemasi]
--
This message was sent by Atlassian Jira
(v8.20.10#820010)