You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by fordm <fo...@gmail.com> on 2013/05/29 14:53:56 UTC

Intermittent NoSuchBeanException in a Camel Route Test

Hi,

I've got a pretty simple Blueprint Camel route, e.g.

<blueprint>
<Code omitted for brevity>
<camelContext id="blueprintContext"
xmlns="http://camel.apache.org/schema/blueprint">
	<template id="producerTemplate" />
	
	<route id="myRoute">
		<from uri="fabric:key:queue" />
		<split parallelProcessing="true">
			<simple>${body.getMyRequest}</simple>
			<log message="Single My Request is ${body}"/>
			<to uri="direct:processMyRequest" />
		</split>
	</route>
</camelContext>
</blueprint>

When deployed into a Fuse ESB Fabric messages route correctly. Like a good
developer, I've written a route test (which extends
CamelBlueprintTestSupport), e.g.

public class MyRouteTest extends CamelBlueprintTestSupport {
	private static final String MESSAGE = "Some message";

	@Produce
	protected ProducerTemplate producerTemplate;

	@Test
	public void messageSuccessfullyRouted() throws Exception {
		getMockEndpoint(MOCK_TO_QUEUE).expectedMessageCount(1);
		producerTemplate.requestBody("fabric:key:queue", MESSAGE);
		assertMockEndpointsSatisfied();
	}

	@Override
	protected String getBlueprintDescriptor() {
		return "/OSGI-INF/blueprint/blueprint.xml";
	}

	// Code omitted for brevity
}

Now, running the test (as part of my maven build) occasionally gives me a
NoSuchBeanException:

org.apache.camel.NoSuchBeanException: Found bean: producerTemplate in
BlueprintContainer:
org.apache.aries.blueprint.container.BlueprintContainerImpl@67ae0c6e of
type: org.apache.camel.impl.DefaultProducerTemplate expected type was:
interface org.apache.camel.Endpoint
        at java.lang.Class.cast(Class.java:3005)
        at
org.apache.camel.blueprint.BlueprintContainerRegistry.lookup(BlueprintContainerRegistry.java:58)
        at
org.apache.camel.impl.CompositeRegistry.lookup(CompositeRegistry.java:49)
        at
org.apache.camel.impl.PropertyPlaceholderDelegateRegistry.lookup(PropertyPlaceholderDelegateRegistry.java:62)
        at
org.apache.camel.util.CamelContextHelper.lookup(CamelContextHelper.java:108)
        at
org.apache.camel.util.CamelContextHelper.getEndpointInjection(CamelContextHelper.java:158)
        at
org.apache.camel.impl.CamelPostProcessorHelper.getEndpointInjection(CamelPostProcessorHelper.java:135)
        at
org.apache.camel.impl.CamelPostProcessorHelper.createInjectionProducerTemplate(CamelPostProcessorHelper.java:177)
        at
org.apache.camel.impl.CamelPostProcessorHelper.getInjectionValue(CamelPostProcessorHelper.java:144)
        at
org.apache.camel.impl.DefaultCamelBeanPostProcessor.injectField(DefaultCamelBeanPostProcessor.java:182)
        at
org.apache.camel.impl.DefaultCamelBeanPostProcessor$1.doWith(DefaultCamelBeanPostProcessor.java:175)
        at
org.apache.camel.util.ReflectionHelper.doWithFields(ReflectionHelper.java:73)
        at
org.apache.camel.impl.DefaultCamelBeanPostProcessor.injectFields(DefaultCamelBeanPostProcessor.java:166)
        at
org.apache.camel.impl.DefaultCamelBeanPostProcessor.postProcessBeforeInitialization(DefaultCamelBeanPostProcessor.java:80)
        at
org.apache.camel.test.junit4.CamelTestSupport.postProcessTest(CamelTestSupport.java:404)
        at
org.apache.camel.test.junit4.CamelTestSupport.doSetUp(CamelTestSupport.java:291)
        at
org.apache.camel.test.junit4.CamelTestSupport.setUp(CamelTestSupport.java:217)
        at
org.apache.camel.test.blueprint.CamelBlueprintTestSupport.setUp(CamelBlueprintTestSupport.java:107)

Anyone got any ideas?

Many thanks



--
View this message in context: http://camel.465427.n5.nabble.com/Intermittent-NoSuchBeanException-in-a-Camel-Route-Test-tp5733405.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Intermittent NoSuchBeanException in a Camel Route Test

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I think only in a recent Camel release the camel-blueprint supports
the IoC in your unit test classes and whatnot.
So upgrading Camel may help.



On Wed, May 29, 2013 at 3:18 PM, fordm <fo...@gmail.com> wrote:
> Thanks for the prompt response Claus, it seems to have done the trick.
>
> Out of interest, any thoughts on what makes it an intermittent problem? Is
> it something in the way / order the bean lookup occurs?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Intermittent-NoSuchBeanException-in-a-Camel-Route-Test-tp5733405p5733408.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Intermittent NoSuchBeanException in a Camel Route Test

Posted by fordm <fo...@gmail.com>.
Thanks for the prompt response Claus, it seems to have done the trick.

Out of interest, any thoughts on what makes it an intermittent problem? Is
it something in the way / order the bean lookup occurs?



--
View this message in context: http://camel.465427.n5.nabble.com/Intermittent-NoSuchBeanException-in-a-Camel-Route-Test-tp5733405p5733408.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Intermittent NoSuchBeanException in a Camel Route Test

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Remove the <template> from your xml.

And the ProducerTemplate from your unit test. There is already an
template out of the box, with the name template.

See the unit tests in camel-test-blueprint for examples.

On Wed, May 29, 2013 at 2:53 PM, fordm <fo...@gmail.com> wrote:
> Hi,
>
> I've got a pretty simple Blueprint Camel route, e.g.
>
> <blueprint>
> <Code omitted for brevity>
> <camelContext id="blueprintContext"
> xmlns="http://camel.apache.org/schema/blueprint">
>         <template id="producerTemplate" />
>
>         <route id="myRoute">
>                 <from uri="fabric:key:queue" />
>                 <split parallelProcessing="true">
>                         <simple>${body.getMyRequest}</simple>
>                         <log message="Single My Request is ${body}"/>
>                         <to uri="direct:processMyRequest" />
>                 </split>
>         </route>
> </camelContext>
> </blueprint>
>
> When deployed into a Fuse ESB Fabric messages route correctly. Like a good
> developer, I've written a route test (which extends
> CamelBlueprintTestSupport), e.g.
>
> public class MyRouteTest extends CamelBlueprintTestSupport {
>         private static final String MESSAGE = "Some message";
>
>         @Produce
>         protected ProducerTemplate producerTemplate;
>
>         @Test
>         public void messageSuccessfullyRouted() throws Exception {
>                 getMockEndpoint(MOCK_TO_QUEUE).expectedMessageCount(1);
>                 producerTemplate.requestBody("fabric:key:queue", MESSAGE);
>                 assertMockEndpointsSatisfied();
>         }
>
>         @Override
>         protected String getBlueprintDescriptor() {
>                 return "/OSGI-INF/blueprint/blueprint.xml";
>         }
>
>         // Code omitted for brevity
> }
>
> Now, running the test (as part of my maven build) occasionally gives me a
> NoSuchBeanException:
>
> org.apache.camel.NoSuchBeanException: Found bean: producerTemplate in
> BlueprintContainer:
> org.apache.aries.blueprint.container.BlueprintContainerImpl@67ae0c6e of
> type: org.apache.camel.impl.DefaultProducerTemplate expected type was:
> interface org.apache.camel.Endpoint
>         at java.lang.Class.cast(Class.java:3005)
>         at
> org.apache.camel.blueprint.BlueprintContainerRegistry.lookup(BlueprintContainerRegistry.java:58)
>         at
> org.apache.camel.impl.CompositeRegistry.lookup(CompositeRegistry.java:49)
>         at
> org.apache.camel.impl.PropertyPlaceholderDelegateRegistry.lookup(PropertyPlaceholderDelegateRegistry.java:62)
>         at
> org.apache.camel.util.CamelContextHelper.lookup(CamelContextHelper.java:108)
>         at
> org.apache.camel.util.CamelContextHelper.getEndpointInjection(CamelContextHelper.java:158)
>         at
> org.apache.camel.impl.CamelPostProcessorHelper.getEndpointInjection(CamelPostProcessorHelper.java:135)
>         at
> org.apache.camel.impl.CamelPostProcessorHelper.createInjectionProducerTemplate(CamelPostProcessorHelper.java:177)
>         at
> org.apache.camel.impl.CamelPostProcessorHelper.getInjectionValue(CamelPostProcessorHelper.java:144)
>         at
> org.apache.camel.impl.DefaultCamelBeanPostProcessor.injectField(DefaultCamelBeanPostProcessor.java:182)
>         at
> org.apache.camel.impl.DefaultCamelBeanPostProcessor$1.doWith(DefaultCamelBeanPostProcessor.java:175)
>         at
> org.apache.camel.util.ReflectionHelper.doWithFields(ReflectionHelper.java:73)
>         at
> org.apache.camel.impl.DefaultCamelBeanPostProcessor.injectFields(DefaultCamelBeanPostProcessor.java:166)
>         at
> org.apache.camel.impl.DefaultCamelBeanPostProcessor.postProcessBeforeInitialization(DefaultCamelBeanPostProcessor.java:80)
>         at
> org.apache.camel.test.junit4.CamelTestSupport.postProcessTest(CamelTestSupport.java:404)
>         at
> org.apache.camel.test.junit4.CamelTestSupport.doSetUp(CamelTestSupport.java:291)
>         at
> org.apache.camel.test.junit4.CamelTestSupport.setUp(CamelTestSupport.java:217)
>         at
> org.apache.camel.test.blueprint.CamelBlueprintTestSupport.setUp(CamelBlueprintTestSupport.java:107)
>
> Anyone got any ideas?
>
> Many thanks
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Intermittent-NoSuchBeanException-in-a-Camel-Route-Test-tp5733405.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen