Load interceptors in XML file in camel application based on spring boot

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Load interceptors in XML file in camel application based on spring boot

sridharb
I am able to separate out the route definitions and rest-dsl routes in separate XML files in the folders camel and camel-rest in my Camel Application based on Spring boot. They are also loaded successfully upon startup.

I now want to add interceptors to the routes so that I can have cross cutting concerns like caching to the routes.

For that I want to use the interceptFrom camel feature so that globally all routes are intercepted. Ido not want to pollute the routes with the intercept logic

The issue I am facing is I am not sure If adding the  the interceptFrom tags in XML file and loading them is supported or not. I want them to be loaded so that it would be read and added to the camelcontext automatically. I cannot add them as part of the route definitions which I have added them in the xml file in camel folder.

Can someone advise me on the correct approach to load interceptors in my camel boot application based on spring boot.






Reply | Threaded
Open this post in threaded view
|

Re: Load interceptors in XML file in camel application based on spring boot

Claus Ibsen-2
Hi

The <routes> and <rests> XML file do not support interceptors and the likes.

You can however use Spring Boot @ImportReource (or whatever that
annotation is named) to load a plain Spring XML file, where you can
define <camelContext> and do it the old fashion way.

On Mon, Oct 10, 2016 at 9:12 PM, sridharb <[hidden email]> wrote:

> I am able to separate out the route definitions and rest-dsl routes in
> separate XML files in the folders camel and camel-rest in my Camel
> Application based on Spring boot. They are also loaded successfully upon
> startup.
>
> I now want to add interceptors to the routes so that I can have cross
> cutting concerns like caching to the routes.
>
> For that I want to use the interceptFrom camel feature so that globally all
> routes are intercepted. Ido not want to pollute the routes with the
> intercept logic
>
> The issue I am facing is I am not sure If adding the  the interceptFrom tags
> in XML file and loading them is supported or not. I want them to be loaded
> so that it would be read and added to the camelcontext automatically. I
> cannot add them as part of the route definitions which I have added them in
> the xml file in camel folder.
>
> Can someone advise me on the correct approach to load interceptors in my
> camel boot application based on spring boot.
>
>
>
>
>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Load-interceptors-in-XML-file-in-camel-application-based-on-spring-boot-tp5788568.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2
Reply | Threaded
Open this post in threaded view
|

Re: Load interceptors in XML file in camel application based on spring boot

sridharb
Hi,


Thanks for your response. I will try importing the xml file with interceptors with the required namespace.

I need another clarification related to the interceptors. There is an intercept strategy which I see is available in camel.

Want to understand the use case for that. Is it an another alternative to using the interceptFrom tag to intercept the requests and apply cross cutting concerns like logging, caching etc. If so, is there any general recommendation on when we can use that instead of the interceptFrom tag.

Thanks
Sridhar


Reply | Threaded
Open this post in threaded view
|

Re: Load interceptors in XML file in camel application based on spring boot

sridharb
In reply to this post by Claus Ibsen-2
Hi,

I tried to use @ImportResource but I get the error as below,

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 1 in XML document from class path resource [interceptors.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 61; cvc-elt.1: Cannot find the declaration of element 'camelContext'.
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:399) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]


My interceptors.xml has the below content,

<camelContext xmlns="http://camel.apache.org/schema/spring">

        <interceptFrom>
                <log message="Inside Interceptor" />
        </interceptFrom>


</camelContext>

I used @importResource as below in my Spring Boot application class
,
@SpringBootApplication
@ImportResource("interceptors.xml")
public class CompositeApplication {
}

Can you please help me on this.

Thanks,
Sridhar
Reply | Threaded
Open this post in threaded view
|

Re: Load interceptors in XML file in camel application based on spring boot

Claus Ibsen-2
You need to do the XML as a regular spring xml file with <beans> and
all that stuff.

See
http://camel.apache.org/spring.html

On Tue, Oct 11, 2016 at 9:43 PM, sridharb <[hidden email]> wrote:

> Hi,
>
> I tried to use *@ImportResource* but I get the error as below,
>
> org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line
> 1 in XML document from class path resource [interceptors.xml] is invalid;
> nested exception is org.xml.sax.SAXParseException; lineNumber: 1;
> columnNumber: 61; cvc-elt.1: Cannot find the declaration of element
> 'camelContext'.
>         at
> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:399)
> ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
>         at
> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
> ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
>
>
> My *interceptors.xml* has the below content,
>
> <camelContext xmlns="http://camel.apache.org/schema/spring">
>
>         <interceptFrom>
>                 <log message="Inside Interceptor" />
>         </interceptFrom>
>
>
> </camelContext>
>
> I used *@importResource* as below in my Spring Boot application class
> ,
> @SpringBootApplication
> @ImportResource("interceptors.xml")
> public class CompositeApplication {
> }
>
> Can you please help me on this.
>
> Thanks,
> Sridhar
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Load-interceptors-in-XML-file-in-camel-application-based-on-spring-boot-tp5788568p5788630.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2