FAQ
Hello,
I can not run camel-jdbc in java.

I defines a route with camel-blueprint, via a road builder (not in XML)
because I know the road to be built when bundle start.

when starting the bundle, I read a database that contains definitions of
endpoints. with there informations, I build the road. where in the database
I have a record defining an endpoint jdbc datasource I create a datasource
"myDataSourceName" and the uri "jdbc:myDataSourceName"

in the documentation I've read, I had to do
JndiRegistry reg = super.createRegistry();
reg.bind("testdb", db);
return reg;

but I'm in the configure method or in constructor of route builder
I can not call super.createRegistry(); the register already exists
I tried context.getRegistry (); who gets a JndiRegistry but getRegistry()
return a simple Registry.
The bind method does not exist on Registry.
I tried (JndiRegistry) context.getRegistry();
but I get a CastException.

public RouteBuilder()
super();
inUrl = getParameter("input.url");
//... read configuration datas
DataSourceName = "myDataSourceName";

DataSource DS = DataSourceFactory.create(DataSourceName, ....); //using
pooled datasource factory (c3p0)

JndiRegistry reg = (JndiRegistry) getContext().getRegistry();
//CastException
reg.bind("myDataSourceName", reg);//
//Or
Registry reg = getContext().getRegistry();
reg.bind("myDataSourceName", reg);//compil error bind is not method of
Registry

dsUri = "jdbc:" DataSourceName;
}

public void configure() {
RouteDefinition r = from(inUrl);
if ("sommeValue".equals(sommeParameter) {}
r.bean(MyBean.class);
//...
r.to("dsUri)



I have a similar problem in JUnit
CamelTestSupport created a camelContext and a Registry
then create the RouteBuilder (calls constructor)
and calls the configure() method

I've created an object datasource but inpossible to put it in the registry.

can you help me ?
A JYT
PS: Sorry for my approximative english

--
View this message in context: http://camel.465427.n5.nabble.com/How-to-register-a-datasource-on-configure-method-or-constructor-of-a-RoutBuilder-tp5595165p5595165.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Search Discussions

  • Christian Müller at Mar 26, 2012 at 4:58 pm
    If you are talking about unit testing, simply override the
    "createRegistry()" method as in [1].

    If you are talking about the real application, simply define the datasource
    in your spring xml and use the endpoint uri
    "jdbc:<spring_bean_id_of_your_datasource_bean>". Look at [2] and [3] for an
    example.

    [1]
    https://svn.apache.org/repos/asf/camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/AbstractJdbcTestSupport.java
    [2]
    https://svn.apache.org/repos/asf/camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcSpringAnotherRouteTest.java
    [3]
    https://svn.apache.org/repos/asf/camel/trunk/components/camel-jdbc/src/test/resources/org/apache/camel/component/jdbc/camelContext.xml

    Best,
    Christian
    On Mon, Mar 26, 2012 at 3:06 PM, sekaijin wrote:

    Hello,
    I can not run camel-jdbc in java.

    I defines a route with camel-blueprint, via a road builder (not in XML)
    because I know the road to be built when bundle start.

    when starting the bundle, I read a database that contains definitions of
    endpoints. with there informations, I build the road. where in the database
    I have a record defining an endpoint jdbc datasource I create a datasource
    "myDataSourceName" and the uri "jdbc:myDataSourceName"

    in the documentation I've read, I had to do
    JndiRegistry reg = super.createRegistry();
    reg.bind("testdb", db);
    return reg;

    but I'm in the configure method or in constructor of route builder
    I can not call super.createRegistry(); the register already exists
    I tried context.getRegistry (); who gets a JndiRegistry but getRegistry()
    return a simple Registry.
    The bind method does not exist on Registry.
    I tried (JndiRegistry) context.getRegistry();
    but I get a CastException.

    public RouteBuilder()
    super();
    inUrl = getParameter("input.url");
    //... read configuration datas
    DataSourceName = "myDataSourceName";

    DataSource DS = DataSourceFactory.create(DataSourceName, ....); //using
    pooled datasource factory (c3p0)

    JndiRegistry reg = (JndiRegistry) getContext().getRegistry();
    //CastException
    reg.bind("myDataSourceName", reg);//
    //Or
    Registry reg = getContext().getRegistry();
    reg.bind("myDataSourceName", reg);//compil error bind is not method of
    Registry

    dsUri = "jdbc:" DataSourceName;
    }

    public void configure() {
    RouteDefinition r = from(inUrl);
    if ("sommeValue".equals(sommeParameter) {}
    r.bean(MyBean.class);
    //...
    r.to("dsUri)



    I have a similar problem in JUnit
    CamelTestSupport created a camelContext and a Registry
    then create the RouteBuilder (calls constructor)
    and calls the configure() method

    I've created an object datasource but inpossible to put it in the registry.

    can you help me ?
    A JYT
    PS: Sorry for my approximative english

    --
    View this message in context:
    http://camel.465427.n5.nabble.com/How-to-register-a-datasource-on-configure-method-or-constructor-of-a-RoutBuilder-tp5595165p5595165.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Sekaijin at Mar 28, 2012 at 7:31 am
    Hello,
    My problem is I do not know the name of the datasource at design time.

    I use blueprint to create an OSGi bundle which start a RouteBuilder
    <camelContext id="hermes-journal" trace="false"
    xmlns="http://camel.apache.org/schema/blueprint">
    <package>fr.foo</package>
    </camelContext>

    when the routebuilder starts it queries a config database and reads the
    name of the datasource to use.

    if the datasource is already defined (by another bundle),
    the routebuilder creates an endpoint "jdbc:" + datasSourceName.
    otherwise it creates the datasource, register it on JNDI and creates the
    endpoint.

    the problem is to test this algorithm.
    I can actually with camelTestSuport, before creating the route builder, add
    a dataSource in the camel registry [1]. it allows me, to test the first case
    (the datasource already exists)

    but I can not test the second case that is to say: create the datasource
    after starting the routebuilder and register it in the registry.
    in this case before the creation of routebuilder, the datasource does not
    exist, (I do not know his name).
    the road builder starts, reads the configuration, Creates the dataSource and
    saves it inJNDI

    if I did
    getContext().getRegistry();
    I can not use "bind" because it is not a method of Registry (but of
    JndiRegistry).

    if I use
    NamingContext InitialContext = new InitialContext();
    I can register the datasource. but in JUnit, it creates another JndiRegistry
    and does not use one created by CamelTestSupport
    when creating the endpoint, the camel can not find datasource in its
    registry.

    This makes sense because InitialContext (); in JUnit, does not retrieved the
    camel registry. but creates another.
    While under OSGI InitialContext (); retrieves the registry JNDI and OSGI
    camel uses it.

    A + JYT
    PS: Sorry for my approximative english

    _____

    De : Christian Mueller [via Camel]

    Envoyé : lundi 26 mars 2012 18:59
    À : sekaijin
    Objet : Re: How to register a datasource, on configure() method or
    constructor of a RoutBuilder ?


    If you are talking about unit testing, simply override the
    "createRegistry()" method as in [1].

    If you are talking about the real application, simply define the datasource
    in your spring xml and use the endpoint uri
    "jdbc:<spring_bean_id_of_your_datasource_bean>". Look at [2] and [3] for an
    example.

    [1]
    https://svn.apache.org/repos/asf/camel/trunk/components/camel-jdbc/src/test/
    java/org/apache/camel/component/jdbc/AbstractJdbcTestSupport.java
    [2]
    https://svn.apache.org/repos/asf/camel/trunk/components/camel-jdbc/src/test/
    java/org/apache/camel/component/jdbc/JdbcSpringAnotherRouteTest.java
    [3]
    https://svn.apache.org/repos/asf/camel/trunk/components/camel-jdbc/src/test/
    resources/org/apache/camel/component/jdbc/camelContext.xml

    Best,
    Christian

    On Mon, Mar 26, 2012 at 3:06 PM, sekaijin <[hidden email]>wrote:

    Hello,
    I can not run camel-jdbc in java.

    I defines a route with camel-blueprint, via a road builder (not in XML)
    because I know the road to be built when bundle start.

    when starting the bundle, I read a database that contains definitions of
    endpoints. with there informations, I build the road. where in the database
    I have a record defining an endpoint jdbc datasource I create a datasource
    "myDataSourceName" and the uri "jdbc:myDataSourceName"

    in the documentation I've read, I had to do
    JndiRegistry reg = super.createRegistry();
    reg.bind("testdb", db);
    return reg;

    but I'm in the configure method or in constructor of route builder
    I can not call super.createRegistry(); the register already exists
    I tried context.getRegistry (); who gets a JndiRegistry but getRegistry()
    return a simple Registry.
    The bind method does not exist on Registry.
    I tried (JndiRegistry) context.getRegistry();
    but I get a CastException.

    public RouteBuilder()
    super();
    inUrl = getParameter("input.url");
    //... read configuration datas
    DataSourceName = "myDataSourceName";

    DataSource DS = DataSourceFactory.create(DataSourceName, ....); //using
    pooled datasource factory (c3p0)

    JndiRegistry reg = (JndiRegistry) getContext().getRegistry();
    //CastException
    reg.bind("myDataSourceName", reg);//
    //Or
    Registry reg = getContext().getRegistry();
    reg.bind("myDataSourceName", reg);//compil error bind is not method of
    Registry

    dsUri = "jdbc:" DataSourceName;
    }

    public void configure() {
    RouteDefinition r = from(inUrl);
    if ("sommeValue".equals(sommeParameter) {}
    r.bean(MyBean.class);
    //...
    r.to("dsUri)



    I have a similar problem in JUnit
    CamelTestSupport created a camelContext and a Registry
    then create the RouteBuilder (calls constructor)
    and calls the configure() method

    I've created an object datasource but inpossible to put it in the registry.
    can you help me ?
    A JYT
    PS: Sorry for my approximative english

    --
    View this message in context:
    http://camel.465427.n5.nabble.com/How-to-register-a-datasource-on-configure-
    method-or-constructor-of-a-RoutBuilder-tp5595165p5595165.html
    Sent from the Camel - Users mailing list archive at Nabble.com.


    _____

    If you reply to this email, your message will be added to the discussion
    below:
    http://camel.465427.n5.nabble.com/How-to-register-a-datasource-on-configure-
    method-or-constructor-of-a-RoutBuilder-tp5595165p5595849.html
    To unsubscribe from How to register a datasource, on configure() method or
    constructor of a RoutBuilder ?, click
    <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscrib
    e_by_code&node=5595165&code=amVhbi15dmVzLnRlcnJpZW5Ac2FwLmFwaHAuZnJ8NTU5NTE2
    NXwtNDg3MTEzOTE4> here.
    NAML
    <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_view
    er&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNa
    mespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.No
    deNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_ema
    ils%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>


    --
    View this message in context: http://camel.465427.n5.nabble.com/How-to-register-a-datasource-on-configure-method-or-constructor-of-a-RoutBuilder-tp5595165p5599729.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Bilgin Ibryam at Mar 29, 2012 at 11:00 pm

    if I did
    getContext().getRegistry();
    I can not use "bind" because it is not a method of Registry (but of
    JndiRegistry).

    Why don't you do getContext().getRegistry() and then cast the Registry to
    JndiRegistry
    Then you can bind to the registry used I think

    Bilgin
  • Sekaijin at May 17, 2012 at 1:56 pm
    the response is in my first post


    ==>CastException

    when you define your camel context Camel create a new Jndi resgisty or un
    osgi get de osgi jndiRegistry

    but when you call getContext().getRegistry(); camel do not return this
    registry but an registryProxy
    that not permit to get the real registry and not have bind method

    A+JYT

    --
    View this message in context: http://camel.465427.n5.nabble.com/How-to-register-a-datasource-on-configure-method-or-constructor-of-a-RoutBuilder-tp5595165p5711404.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Christian Müller at May 17, 2012 at 9:14 pm
    It depends on your runtime environment, which Registry is used:
    - org.apache.camel.spring.spi.ApplicationContextRegistry
    - org.apache.camel.blueprint.BlueprintContainerRegistry
    - org.apache.camel.impl.CompositeRegistry
    - org.apache.camel.impl.JndiRegistry
    - org.apache.camel.core.osgi.OsgiServiceRegistry
    - org.apache.camel.impl.PropertyPlaceholderDelegateRegistry
    - org.apache.camel.impl.SimpleRegistry

    Best,
    Christian
    On Thu, May 17, 2012 at 3:56 PM, sekaijin wrote:

    the response is in my first post


    ==>CastException

    when you define your camel context Camel create a new Jndi resgisty or un
    osgi get de osgi jndiRegistry

    but when you call getContext().getRegistry(); camel do not return this
    registry but an registryProxy
    that not permit to get the real registry and not have bind method

    A+JYT

    --
    View this message in context:
    http://camel.465427.n5.nabble.com/How-to-register-a-datasource-on-configure-method-or-constructor-of-a-RoutBuilder-tp5595165p5711404.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Christian Müller at May 17, 2012 at 9:08 pm
    If you use CamelTestSupport, you are able to bind your objects to the
    registry in this way:

    @Override
    protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry registry = super.createRegistry();
    registry.bind("ds", ds);
    return registry;
    }

    Best,
    Christian
    On Mon, Mar 26, 2012 at 3:06 PM, sekaijin wrote:

    Hello,
    I can not run camel-jdbc in java.

    I defines a route with camel-blueprint, via a road builder (not in XML)
    because I know the road to be built when bundle start.

    when starting the bundle, I read a database that contains definitions of
    endpoints. with there informations, I build the road. where in the database
    I have a record defining an endpoint jdbc datasource I create a datasource
    "myDataSourceName" and the uri "jdbc:myDataSourceName"

    in the documentation I've read, I had to do
    JndiRegistry reg = super.createRegistry();
    reg.bind("testdb", db);
    return reg;

    but I'm in the configure method or in constructor of route builder
    I can not call super.createRegistry(); the register already exists
    I tried context.getRegistry (); who gets a JndiRegistry but getRegistry()
    return a simple Registry.
    The bind method does not exist on Registry.
    I tried (JndiRegistry) context.getRegistry();
    but I get a CastException.

    public RouteBuilder()
    super();
    inUrl = getParameter("input.url");
    //... read configuration datas
    DataSourceName = "myDataSourceName";

    DataSource DS = DataSourceFactory.create(DataSourceName, ....); //using
    pooled datasource factory (c3p0)

    JndiRegistry reg = (JndiRegistry) getContext().getRegistry();
    //CastException
    reg.bind("myDataSourceName", reg);//
    //Or
    Registry reg = getContext().getRegistry();
    reg.bind("myDataSourceName", reg);//compil error bind is not method of
    Registry

    dsUri = "jdbc:" DataSourceName;
    }

    public void configure() {
    RouteDefinition r = from(inUrl);
    if ("sommeValue".equals(sommeParameter) {}
    r.bean(MyBean.class);
    //...
    r.to("dsUri)



    I have a similar problem in JUnit
    CamelTestSupport created a camelContext and a Registry
    then create the RouteBuilder (calls constructor)
    and calls the configure() method

    I've created an object datasource but inpossible to put it in the registry.

    can you help me ?
    A JYT
    PS: Sorry for my approximative english

    --
    View this message in context:
    http://camel.465427.n5.nabble.com/How-to-register-a-datasource-on-configure-method-or-constructor-of-a-RoutBuilder-tp5595165p5595165.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Sekaijin at May 18, 2012 at 9:23 am
    So

    Christian Mueller wrote
    It depends on your runtime environment, which Registry is used:
    - org.apache.camel.spring.spi.ApplicationContextRegistry
    - org.apache.camel.blueprint.BlueprintContainerRegistry
    - org.apache.camel.impl.CompositeRegistry
    - org.apache.camel.impl.JndiRegistry
    - org.apache.camel.core.osgi.OsgiServiceRegistry
    - org.apache.camel.impl.PropertyPlaceholderDelegateRegistry
    - org.apache.camel.impl.SimpleRegistry

    Best,
    Christian
    ...
    In my first post

    "Hello,
    I can not run camel-jdbc in java.

    I defines a route with *camel-blueprint* via routebuilder in java""

    the problem is how i can get the registry in java to bind an objet

    blueprint automaticly creates the camel context and registry, and does not
    allow access in java.

    in route builder the camel context does not allow acces to the registry. it
    allow access to a proxy to the registry that does not allow to bind an
    object

    if I do as you said for junit,
    I do not have the expected behavior. namely
    when the bundle starts he has no knowledge of the database.
    It queries a service that provided the datasource to use

    A+JYT




    --
    View this message in context: http://camel.465427.n5.nabble.com/How-to-register-a-datasource-on-configure-method-or-constructor-of-a-RoutBuilder-tp5595165p5711798.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Christian Müller at Jul 1, 2012 at 9:48 pm
    Could you solve your problem?
    If not, feel free to raise a JIRA (and attach a test if possible) so we can
    work on this.

    Best,
    Christian
    On Fri, May 18, 2012 at 11:22 AM, sekaijin wrote:

    So

    Christian Mueller wrote
    It depends on your runtime environment, which Registry is used:
    - org.apache.camel.spring.spi.ApplicationContextRegistry
    - org.apache.camel.blueprint.BlueprintContainerRegistry
    - org.apache.camel.impl.CompositeRegistry
    - org.apache.camel.impl.JndiRegistry
    - org.apache.camel.core.osgi.OsgiServiceRegistry
    - org.apache.camel.impl.PropertyPlaceholderDelegateRegistry
    - org.apache.camel.impl.SimpleRegistry

    Best,
    Christian
    ...
    In my first post

    "Hello,
    I can not run camel-jdbc in java.

    I defines a route with *camel-blueprint* via routebuilder in java""

    the problem is how i can get the registry in java to bind an objet

    blueprint automaticly creates the camel context and registry, and does not
    allow access in java.

    in route builder the camel context does not allow acces to the registry. it
    allow access to a proxy to the registry that does not allow to bind an
    object

    if I do as you said for junit,
    I do not have the expected behavior. namely
    when the bundle starts he has no knowledge of the database.
    It queries a service that provided the datasource to use

    A+JYT




    --
    View this message in context:
    http://camel.465427.n5.nabble.com/How-to-register-a-datasource-on-configure-method-or-constructor-of-a-RoutBuilder-tp5595165p5711798.html
    Sent from the Camel - Users mailing list archive at Nabble.com.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriescamel
postedMar 26, '12 at 1:24p
activeJul 1, '12 at 9:48p
posts9
users3
websitecamel.apache.org

People

Translate

site design / logo © 2021 Grokbase