You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Eugene Berman (Jira)" <ji...@apache.org> on 2021/12/29 17:45:00 UTC

[jira] [Comment Edited] (CAMEL-17393) Source locations are not available in Spring Boot configurations

    [ https://issues.apache.org/jira/browse/CAMEL-17393?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17466545#comment-17466545 ] 

Eugene Berman edited comment on CAMEL-17393 at 12/29/21, 5:44 PM:
------------------------------------------------------------------

Thanks, Claus, this resolved the problem - however, there's still one issue. I have a route configurations file separately from he routes file, and I use the following code to load it in my app (for some reason, if I comment out this code, SpringBoot does not find it):

{code:java}
@Bean
    public void initRouteConfigurations() throws Exception {
        SpringCamelContext springCamelContext = (SpringCamelContext) camelContext;

        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        Resource[] routeConfigurations = resolver.getResources("camel/defaultRouteConfigurations.xml");

        for (Resource r : routeConfigurations) {
            InputStream is = r.getURL().openStream();
            ModelParser parser = new ModelParser(is, "http://camel.apache.org/schema/spring");
            Optional<RouteConfigurationsDefinition> definitionsOptional = parser.parseRouteConfigurationsDefinition();
            RouteConfigurationsDefinition routeConfigurationsDefinition = definitionsOptional.get();
            springCamelContext.addRouteConfigurations(routeConfigurationsDefinition.getRouteConfigurations());
        }
    }
{code}

This works, however, the source location of nodes defined in the route configuration is not showing up correctly, instead the location points to the routes file.



was (Author: JIRAUSER281980):
Thanks, Claus, this resolved the problem - however, there's still one issue. I have a route configurations file separately from he routes file, and I use the following code to load it in my app (for some reason, if I comment out this code, SpringBoot does not find it):

{code:java}
@Bean
    public void initRouteConfigurations() throws Exception {
        SpringCamelContext springCamelContext = (SpringCamelContext) camelContext;

        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        Resource[] routeConfigurations = resolver.getResources("camel/defaultRouteConfigurations.xml");

        for (Resource r : routeConfigurations) {
            InputStream is = r.getURL().openStream();
            ModelParser parser = new ModelParser(is, "http://camel.apache.org/schema/spring");
            Optional<RouteConfigurationsDefinition> definitionsOptional = parser.parseRouteConfigurationsDefinition();
            RouteConfigurationsDefinition routeConfigurationsDefinition = definitionsOptional.get();
            springCamelContext.addRouteConfigurations(routeConfigurationsDefinition.getRouteConfigurations());
        }
    }
{code}

This works, however, the source location of nodes defined in the route configuration is not showing up correctly, instead the location points to the routes file and the line number is wrong.


> Source locations are not available in Spring Boot configurations
> ----------------------------------------------------------------
>
>                 Key: CAMEL-17393
>                 URL: https://issues.apache.org/jira/browse/CAMEL-17393
>             Project: Camel
>          Issue Type: Bug
>          Components: came-core, jmx
>    Affects Versions: 3.15.0
>            Reporter: Eugene Berman
>            Priority: Minor
>
> I modified the SpringBoot XML example so that it configures routes and route contexts as Spring beans, e.g.:
> {code:xml}
> <?xml version="1.0" encoding="UTF-8"?>
> <spring:beans xmlns:spring="http://www.springframework.org/schema/beans" 
>               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
>               xmlns="http://camel.apache.org/schema/spring" 
>               xsi:schemaLocation="                     
>                   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
>                   http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd 
> ">
>     <routeContext id="test">
>         <route id="hello">
>             <from uri="timer:hello?period={{timer.period}}"/>
>             <transform>
>                 <method ref="myBean" method="saySomething"/>
>             </transform>
>             <setProperty name="testRouteURI">
>                 <constant>direct:test</constant>
>             </setProperty>
>             <setHeader name="number">
>                 <simple>${random(0,10)}</simple>
>             </setHeader>
>             <filter>
>                 <simple>${header.number} &gt; 4</simple>
>                 <transform>
>                     <simple>Random ${body}</simple>
>                 </transform>
>             </filter>
>             <to uri="stream:out"/>
>         </route>
>     </routeContext>
> </spring:beans>
> {code}
> I ran the application and called dumpRouteSourceLocationsAsXml from Jconsole. The response was:
> {code:xml}
> <routeLocations>
>     <routeLocation routeId="hello" id="hello" index="0" sourceLocation="file:/Users/foobar/camel-spring-boot-examples/xml/target/classes/camel/my-route.xml" sourceLineNumber="-1"/>
>     <routeLocation routeId="hello" id="transform1" index="25" sourceLocation="file:/Users/foobar/camel-spring-boot-examples/xml/target/classes/camel/my-route.xml" sourceLineNumber="-1"/>
>     <routeLocation routeId="hello" id="setProperty1" index="26" sourceLocation="file:/Users/foobar/camel-spring-boot-examples/xml/target/classes/camel/my-route.xml" sourceLineNumber="-1"/>
>     <routeLocation routeId="hello" id="setHeader1" index="27" sourceLocation="file:/Users/foobar/camel-spring-boot-examples/xml/target/classes/camel/my-route.xml" sourceLineNumber="-1"/>
>     <routeLocation routeId="hello" id="filter1" index="28" sourceLocation="file:/Users/foobar/camel-spring-boot-examples/xml/target/classes/camel/my-route.xml" sourceLineNumber="-1"/>
>     <routeLocation routeId="hello" id="transform2" index="29" sourceLocation="" sourceLineNumber="-1"/>
>     <routeLocation routeId="hello" id="to1" index="30" sourceLocation="file:/Users/foobar/camel-spring-boot-examples/xml/target/classes/camel/my-route.xml" sourceLineNumber="-1"/>
> </routeLocations>
> {code}
> I also wanted to have a custom Camel context configuration, so I explicitly created a Camel context XML file and added an annotation to the application class to exclude the CamelAutoConfiguration. This time source locations looked like this:
> {code:xml}
> <routeLocations>
>     <routeLocation routeId="hello" id="hello" index="0" sourceLocation="" sourceLineNumber="-1"/>
>     <routeLocation routeId="hello" id="transform1" index="4" sourceLocation="" sourceLineNumber="-1"/>
>     <routeLocation routeId="hello" id="setProperty1" index="5" sourceLocation="" sourceLineNumber="-1"/>
>     <routeLocation routeId="hello" id="setHeader1" index="6" sourceLocation="" sourceLineNumber="-1"/>
>     <routeLocation routeId="hello" id="filter1" index="7" sourceLocation="" sourceLineNumber="-1"/>
>     <routeLocation routeId="hello" id="transform2" index="8" sourceLocation="" sourceLineNumber="-1"/>
>     <routeLocation routeId="hello" id="to1" index="9" sourceLocation="" sourceLineNumber="-1"/>
> </routeLocations>
> {code}
> So it seems like a bit more work is needed to support Spring configurations.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)