You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by akcameluser <ay...@gmail.com> on 2013/07/03 10:35:22 UTC

MongoDB endpoint created before beans are being registered when deployed on ServiceMix

Hi 

I am getting this weird error stating that Bean can't be found in registry.
Looks like the mongodb endpoint is being created before  beans are
registered. I can run it perfectly on IDE and experienced the same issues on
my local ServiceMix but it seems to have gone away now. But the still
failing on test environment. so this is clearly a random loading orders
issue. How do I force the beans are registered first before endpoints are
being created?

I have tried to add: DependsOn() annotation on the Router but stil the issue
persist. 

See details of my set up below. Your help is very much appreciated.

*ROUTER*

@DependsOn("mongoBean")
public class ArchivaQARouter extends ArchivaBaseRouter {


    /*
     * (non-Javadoc)
     *
     * @see org.apache.camel.builder.RouteBuilder#configure()
     */
    @Override
    public void configure() throws Exception {

        // Initialise all the properties and set the error handler.
        super.configure();

        /**
         *   FTP endpoint
         */
        from("{{jetty.qa.endPoint}}").routeId("qa endpoint")//
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception
{
                        String body = "{ \"doi\": \"" +
exchange.getIn().getHeader(Constants.DOI) + "\" }";
                        exchange.setProperty(Constants.QAReport,
exchange.getIn().getBody());
                        exchange.getOut().setBody(body);
                    }
                })

                //.setBody().constant("{ \"doi\": \"" +
simple("${in.header.doi}") + "\" }")
                .to("{{mongodb.endpoint}}") //
mongodb.endpoint=mongodb:mongoBean?database=archiva&collection=submission&operation=findOneByQuery

                .beanRef("ftpHandler", "handleQAReport")
                .to("{{ftp.qa.endpoint}}").id("qa.ftp.endpoint");

    }
}

*CAMEL CONTEXT
*

<context:component-scan
base-package="com.nature.archiva.service.configuration" />

	<context:property-placeholder
location="file:${karaf.home}/etc/archiva.properties" />


	
	<camel:camelContext id="camel">
		<camel:template id="template" />
		<camel:routeBuilder ref="archivaRouter" />
		<camel:routeBuilder ref="archivaBaseRouter" />
		<camel:routeBuilder ref="archivaStatusRouter"/>
        <camel:routeBuilder ref="archivaQARouter"/>
        <camel:routeBuilder ref="deadLetterChannel" />
	</camel:camelContext>

( I tried to define the template in camel-context, but didn't help)

@Configuration
public class ApplicationContextConfiguration {

	private final Logger log = Logger.getLogger(this.getClass());

	@Bean(name = "marshaller")
	public Jaxb2Marshaller getMarshaller() {
		final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
		marshaller.setClassesToBeBound(Response.class, Reports.class,
				Articles.class);
		return marshaller;
	}

/**
     *
     * @return
     * @throws UnknownHostException
     */
    @Bean(name = "mongoBean")
    public Mongo getMongoInstance(@Value("${db.host}") String host) throws
UnknownHostException {
        return new Mongo(host);
    }
}


Stacktrace:

at java.lang.Thread.run(Thread.java:722)
Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create
route qa endpoint at: >>>
To[mongodb:mongoBean?database=archiva&collection=submission&operation=findOneByQuery]
<<< in route: Route[[From[{{jetty.qa.endPoint}}]] ->
[process[com.nature.a... because of Failed to resolve endpoint:
mongodb://mongoBean?collection=submission&database=archiva&operation=findOneByQuery
due to: No bean could be found in the registry for: mongoBean of type:
com.mongodb.Mongo



--
View this message in context: http://camel.465427.n5.nabble.com/MongoDB-endpoint-created-before-beans-are-being-registered-when-deployed-on-ServiceMix-tp5735128.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: MongoDB endpoint created before beans are being registered when deployed on ServiceMix

Posted by akcameluser <ay...@gmail.com>.
Raul, you were spot on thinking I had an old version of mongo driver jar. Got
rid of it and all seems to work fine now. 

Many thanks for your help.



--
View this message in context: http://camel.465427.n5.nabble.com/MongoDB-endpoint-created-before-beans-are-being-registered-when-deployed-on-ServiceMix-tp5735128p5735145.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: MongoDB endpoint created before beans are being registered when deployed on ServiceMix

Posted by Raul Kripalani <ra...@evosent.com>.
Try using the mvn dependency:build-classpath goal and check if you have
multiple versions of the MongoDB driver.

What server environment are you running Camel on? ServiceMix, Tomcat,
JBoss, etc.? If applicable, also check the lib/ directories everywhere
(server, instance, WAR, etc.) to make sure nothing fishy is leaking in.

Regards,

*Raúl Kripalani*
Enterprise Architect, Open Source Integration specialist, Program
Manager | Apache
Camel Committer
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk

On Wed, Jul 3, 2013 at 11:51 AM, Raul Kripalani <ra...@evosent.com> wrote:

> I wonder if maybe you have several versions of the Java MongoDB driver in
> your classpath? That could justify why you observe different behaviour on
> different environments.
>
> *Raúl Kripalani*
> Enterprise Architect, Open Source Integration specialist, Program Manager
> | Apache Camel Committer
> http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
> http://blog.raulkr.net | twitter: @raulvk
>
> On Wed, Jul 3, 2013 at 11:30 AM, akcameluser <ay...@gmail.com>wrote:
>
>> Thanks Raul. I did tried that, but same issue I am afraid. Same code was
>> running fine on my local smx though, but wasn't running earlier.
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/MongoDB-endpoint-created-before-beans-are-being-registered-when-deployed-on-ServiceMix-tp5735128p5735135.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>

Re: MongoDB endpoint created before beans are being registered when deployed on ServiceMix

Posted by Raul Kripalani <ra...@evosent.com>.
I wonder if maybe you have several versions of the Java MongoDB driver in
your classpath? That could justify why you observe different behaviour on
different environments.

*Raúl Kripalani*
Enterprise Architect, Open Source Integration specialist, Program
Manager | Apache
Camel Committer
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk

On Wed, Jul 3, 2013 at 11:30 AM, akcameluser <ay...@gmail.com>wrote:

> Thanks Raul. I did tried that, but same issue I am afraid. Same code was
> running fine on my local smx though, but wasn't running earlier.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/MongoDB-endpoint-created-before-beans-are-being-registered-when-deployed-on-ServiceMix-tp5735128p5735135.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: MongoDB endpoint created before beans are being registered when deployed on ServiceMix

Posted by akcameluser <ay...@gmail.com>.
Thanks Raul. I did tried that, but same issue I am afraid. Same code was
running fine on my local smx though, but wasn't running earlier.



--
View this message in context: http://camel.465427.n5.nabble.com/MongoDB-endpoint-created-before-beans-are-being-registered-when-deployed-on-ServiceMix-tp5735128p5735135.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: MongoDB endpoint created before beans are being registered when deployed on ServiceMix

Posted by Raul Kripalani <ra...@evosent.com>.
Just out of curiosity, could you define the Mongo bean in the same Spring
Application Context XML where the Camel Context is configured? (using the
XML config style instead of the Java style).

*Raúl Kripalani*
Enterprise Architect, Open Source Integration specialist, Program
Manager | Apache
Camel Committer
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk

On Wed, Jul 3, 2013 at 9:35 AM, akcameluser <ay...@gmail.com>wrote:

> Hi
>
> I am getting this weird error stating that Bean can't be found in registry.
> Looks like the mongodb endpoint is being created before  beans are
> registered. I can run it perfectly on IDE and experienced the same issues
> on
> my local ServiceMix but it seems to have gone away now. But the still
> failing on test environment. so this is clearly a random loading orders
> issue. How do I force the beans are registered first before endpoints are
> being created?
>
> I have tried to add: DependsOn() annotation on the Router but stil the
> issue
> persist.
>
> See details of my set up below. Your help is very much appreciated.
>
> *ROUTER*
>
> @DependsOn("mongoBean")
> public class ArchivaQARouter extends ArchivaBaseRouter {
>
>
>     /*
>      * (non-Javadoc)
>      *
>      * @see org.apache.camel.builder.RouteBuilder#configure()
>      */
>     @Override
>     public void configure() throws Exception {
>
>         // Initialise all the properties and set the error handler.
>         super.configure();
>
>         /**
>          *   FTP endpoint
>          */
>         from("{{jetty.qa.endPoint}}").routeId("qa endpoint")//
>                 .process(new Processor() {
>                     @Override
>                     public void process(Exchange exchange) throws Exception
> {
>                         String body = "{ \"doi\": \"" +
> exchange.getIn().getHeader(Constants.DOI) + "\" }";
>                         exchange.setProperty(Constants.QAReport,
> exchange.getIn().getBody());
>                         exchange.getOut().setBody(body);
>                     }
>                 })
>
>                 //.setBody().constant("{ \"doi\": \"" +
> simple("${in.header.doi}") + "\" }")
>                 .to("{{mongodb.endpoint}}") //
>
> mongodb.endpoint=mongodb:mongoBean?database=archiva&collection=submission&operation=findOneByQuery
>
>                 .beanRef("ftpHandler", "handleQAReport")
>                 .to("{{ftp.qa.endpoint}}").id("qa.ftp.endpoint");
>
>     }
> }
>
> *CAMEL CONTEXT
> *
>
> <context:component-scan
> base-package="com.nature.archiva.service.configuration" />
>
>         <context:property-placeholder
> location="file:${karaf.home}/etc/archiva.properties" />
>
>
>
>         <camel:camelContext id="camel">
>                 <camel:template id="template" />
>                 <camel:routeBuilder ref="archivaRouter" />
>                 <camel:routeBuilder ref="archivaBaseRouter" />
>                 <camel:routeBuilder ref="archivaStatusRouter"/>
>         <camel:routeBuilder ref="archivaQARouter"/>
>         <camel:routeBuilder ref="deadLetterChannel" />
>         </camel:camelContext>
>
> ( I tried to define the template in camel-context, but didn't help)
>
> @Configuration
> public class ApplicationContextConfiguration {
>
>         private final Logger log = Logger.getLogger(this.getClass());
>
>         @Bean(name = "marshaller")
>         public Jaxb2Marshaller getMarshaller() {
>                 final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
>                 marshaller.setClassesToBeBound(Response.class,
> Reports.class,
>                                 Articles.class);
>                 return marshaller;
>         }
>
> /**
>      *
>      * @return
>      * @throws UnknownHostException
>      */
>     @Bean(name = "mongoBean")
>     public Mongo getMongoInstance(@Value("${db.host}") String host) throws
> UnknownHostException {
>         return new Mongo(host);
>     }
> }
>
>
> Stacktrace:
>
> at java.lang.Thread.run(Thread.java:722)
> Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create
> route qa endpoint at: >>>
>
> To[mongodb:mongoBean?database=archiva&collection=submission&operation=findOneByQuery]
> <<< in route: Route[[From[{{jetty.qa.endPoint}}]] ->
> [process[com.nature.a... because of Failed to resolve endpoint:
>
> mongodb://mongoBean?collection=submission&database=archiva&operation=findOneByQuery
> due to: No bean could be found in the registry for: mongoBean of type:
> com.mongodb.Mongo
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/MongoDB-endpoint-created-before-beans-are-being-registered-when-deployed-on-ServiceMix-tp5735128.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>