[
https://issues.apache.org/jira/browse/CAMEL-15560?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17276445#comment-17276445
]
Luca Burgazzoli edited comment on CAMEL-15560 at 2/1/21, 4:26 PM:
------------------------------------------------------------------
As today the mechanic to load routes from external definitions is a little bit
convoluted, here an extract from a test:
{code:java}
InputStream is = getClass().getResourceAsStream("barRoute.xml");
ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
RoutesDefinition routes = (RoutesDefinition)
ecc.getXMLRoutesDefinitionLoader().loadRoutesDefinition(ecc, is);
context.addRouteDefinitions(routes.getRoutes());
{code}
So we need:
1. to get an instance of the route loader
2. create a definition
3. add the definition to the context
This procedure can be simplified to something like:
{code:java}
context.adapt(ExtendedCamelContext.class).getRoutesDefinitionLoader().load(...);
{code}
As alternative we can use the extension mechanism:
{code:java}
context.getExtension(RoutesDefinitionLoader.class).load(...);
{code}
was (Author: lb):
As today the mechanic to load routes from external definitions is a little bit
convoluted, here an extract from a test:
{code:java}
InputStream is = getClass().getResourceAsStream("barRoute.xml");
ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
RoutesDefinition routes = (RoutesDefinition)
ecc.getXMLRoutesDefinitionLoader().loadRoutesDefinition(ecc, is);
context.addRouteDefinitions(routes.getRoutes());
{code}
This can be simplified to something like:
{code:java}
context.adapt(ExtendedCamelContext.class).getRoutesDefinitionLoader().load(...);
{code}
As alternative we can use the extension mechanism:
{code:java}
context.getExtension(RoutesDefinitionLoader.class).load(...);
{code}
> generic route loader
> --------------------
>
> Key: CAMEL-15560
> URL: https://issues.apache.org/jira/browse/CAMEL-15560
> Project: Camel
> Issue Type: New Feature
> Components: camel-core-api, camel-core-engine
> Reporter: Luca Burgazzoli
> Assignee: Luca Burgazzoli
> Priority: Major
> Fix For: 3.9.0
>
>
> In camel-k we have a mechanism to load routes written in different languages,
> in camel instead we only support XML.
> We should move the generic loader to Camel from Camel K and leave the
> implementations where they fit better.
> I'm proposing to remove the following methods from the ExtendedCamelContext
> and replace them with a generic discovery mechanism similar to the one used
> for components & co to find the appropriate loader based on the file
> extension.
> {code:java}
> /**
> * Sets a custom {@link XMLRoutesDefinitionLoader} to be used.
> */
> void setXMLRoutesDefinitionLoader(XMLRoutesDefinitionLoader
> xmlRoutesDefinitionLoader);
> /**
> * Gets the {@link XMLRoutesDefinitionLoader} to be used.
> */
> XMLRoutesDefinitionLoader getXMLRoutesDefinitionLoader();
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)