Global config of components and Scala DSL

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

Global config of components and Scala DSL

Bruno Borges
Hi,

Have anyone had any problem trying to configure components and using Scala
DSL?

I'm trying to configure the TwitterComponent in a RouteBuilder with Scala
DSL but changes are not being picked by the component.

class DemoRouteBuilder extends RouteBuilder {

... extract twitter.properties to asign to the component

    val tc = new TwitterComponent()
    tc.setAccessToken(accessToken)
    tc.setAccessTokenSecret(accessTokenSecret)
    tc.setConsumerKey(consumerKey)
    tc.setConsumerSecret(consumerSecret)

    getContext.addComponent("twitter", tc)

    "twitter://streaming/sample?type=event" to "log:output"

}

Twitter4J tells me the the accessToken has not being informed.

The same code works fine using Java DSL

*Bruno Borges*
(11) 99564-9058
*www.brunoborges.com*
Reply | Threaded
Open this post in threaded view
|

Re: Global config of components and Scala DSL

Bruno Borges
Answering my own question, for the sake of history :-)

Blog post about this issue:
http://blog.brunoborges.com.br/2012/09/customizing-camel-components-within.html

Or simply put:

class CamelRoute extends RouteBuilder {
    val accessToken = System.getProperty("twitter.accessToken")
    ...

    val tc = new TwitterComponent()
    tc.setAccessToken(accessToken)
    ...

    override def onJavaBuilder(builder:
org.apache.camel.builder.RouteBuilder) = {
        builder.getContext().addComponent("twitter", tc)
    }
}


Best regards,

*Bruno Borges*
(11) 99564-9058
*www.brunoborges.com*



On Fri, Sep 14, 2012 at 4:15 PM, Bruno Borges <[hidden email]>wrote:

> Hi,
>
> Have anyone had any problem trying to configure components and using Scala
> DSL?
>
> I'm trying to configure the TwitterComponent in a RouteBuilder with Scala
> DSL but changes are not being picked by the component.
>
> class DemoRouteBuilder extends RouteBuilder {
>
> ... extract twitter.properties to asign to the component
>
>     val tc = new TwitterComponent()
>     tc.setAccessToken(accessToken)
>     tc.setAccessTokenSecret(accessTokenSecret)
>     tc.setConsumerKey(consumerKey)
>     tc.setConsumerSecret(consumerSecret)
>
>     getContext.addComponent("twitter", tc)
>
>     "twitter://streaming/sample?type=event" to "log:output"
>
> }
>
> Twitter4J tells me the the accessToken has not being informed.
>
> The same code works fine using Java DSL
>
> *Bruno Borges*
> (11) 99564-9058
> *www.brunoborges.com*
>
>