On placing a bundle (using camel) on Karaf I am seeing the below exception. The below exception comes only when the bundle is started. After that everything works fine. The exeception does not seem to effect our functionality. The issue is coming on both camel 2.16.1 (deployed on servicemix 6.1.0) and camel 2.16.3 (deployed on servicemix 7.0.0M2).
My blueprint is split into three files. A simplified version of them are shown below:-
blueprint.xml placed here.
productBeans.xml placed here.
camelContext.xml placed here.
Can some please let me know why is this exception coming during bundle start? It appears from the below stack-trace that it is because of some circular dependency. How can I get around this?
2016-07-04 11:29:37,497 | ERROR | mix-6.1.0/deploy | BlueprintCamelContext | 143 - org.apache.camel.camel-blueprint - 2.16.1 | {{bundle.id,143}{bundle.name,org.apache.camel.camel-blueprint}{bundle.version,2.16.1}} | Error occurred during starting Camel: CamelContext(camel-1) due Failed to create route orchestrator-service-route at: >>> process[ref:jsonRPCProcessor] <<< in route: Route(orchestrator-service-route)[[From[jetty:http://0.0.0.0... because of Cannot lookup: jsonRPCProcessor from registry: org.apache.camel.blueprint.BlueprintContainerRegistry#7b081b97 with expected type: interface org.apache.camel.Processor due: [BeanRecipe[name='myTemplate'], BeanRecipe[name='.camelBlueprint.bean.factory.myTemplate'], BeanRecipe[name='camel-1'], BeanRecipe[name='myTemplate']]
org.apache.camel.FailedToCreateRouteException: Failed to create route orchestrator-service-route at: >>> process[ref:jsonRPCProcessor] <<< in route: Route(orchestrator-service-route)[[From[jetty:http://0.0.0.0... because of Cannot lookup: jsonRPCProcessor from registry: org.apache.camel.blueprint.BlueprintContainerRegistry#7b081b97 with expected type: interface org.apache.camel.Processor due: [BeanRecipe[name='myTemplate'], BeanRecipe[name='.camelBlueprint.bean.factory.myTemplate'], BeanRecipe[name='camel-1'], BeanRecipe[name='myTemplate']]
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1072)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:196)
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:947)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3258)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:2981)
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:175)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2812)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2808)
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2831)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2808)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2777)
at org.apache.camel.blueprint.BlueprintCamelContext.start(BlueprintCamelContext.java:180)[143:org.apache.camel.camel-blueprint:2.16.1]
at org.apache.camel.blueprint.BlueprintCamelContext.maybeStart(BlueprintCamelContext.java:212)[143:org.apache.camel.camel-blueprint:2.16.1]
at org.apache.camel.blueprint.BlueprintCamelContext.serviceChanged(BlueprintCamelContext.java:150)[143:org.apache.camel.camel-blueprint:2.16.1]
at org.apache.felix.framework.util.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:932)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:793)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispatcher.java:543)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:4419)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.Felix.registerService(Felix.java:3423)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:346)
at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:352)
at org.apache.camel.blueprint.BlueprintCamelContext.init(BlueprintCamelContext.java:100)[143:org.apache.camel.camel-blueprint:2.16.1]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_77]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_77]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_77]
at java.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_77]
at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:299)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:956)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:712)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:824)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)[15:org.apache.aries.blueprint.core:1.4.4]
at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_77]
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:247)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintRepository.createInstance(BlueprintRepository.java:230)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintRepository.create(BlueprintRepository.java:145)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.getComponentInstance(BlueprintContainerImpl.java:754)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.camel.blueprint.CamelProducerTemplateFactoryBean.getCamelContextWithId(CamelProducerTemplateFactoryBean.java:49)
at org.apache.camel.core.xml.AbstractCamelFactoryBean.afterPropertiesSet(AbstractCamelFactoryBean.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_77]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_77]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_77]
at java.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_77]
at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:299)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:956)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:712)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:824)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)[15:org.apache.aries.blueprint.core:1.4.4]
at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_77]
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:280)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:806)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)[15:org.apache.aries.blueprint.core:1.4.4]
at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_77]
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.di.RefRecipe.internalCreate(RefRecipe.java:62)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:106)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:931)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:905)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:886)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:820)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)[15:org.apache.aries.blueprint.core:1.4.4]
at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_77]
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:247)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:682)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:377)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:269)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:294)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:263)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:253)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)[9:org.apache.aries.util:1.1.1]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)[9:org.apache.aries.util:1.1.1]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)[9:org.apache.aries.util:1.1.1]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)[9:org.apache.aries.util:1.1.1]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)[9:org.apache.aries.util:1.1.1]
at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1103)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.util.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:695)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:483)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4403)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2092)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.karaf.features.internal.FeaturesServiceImpl.startBundle(FeaturesServiceImpl.java:518)[20:org.apache.karaf.features.core:3.0.5]
at org.apache.karaf.features.internal.FeaturesServiceImpl.installFeatures(FeaturesServiceImpl.java:476)[20:org.apache.karaf.features.core:3.0.5]
at org.apache.karaf.features.internal.FeaturesServiceImpl.installFeature(FeaturesServiceImpl.java:417)[20:org.apache.karaf.features.core:3.0.5]
at Proxy1be55f4b_f63a_43b3_883f_77a48747d768.installFeature(Unknown Source)[:]
at Proxy1fa9f34f_3928_4828_8542_9d785df163bd.installFeature(Unknown Source)[:]
at org.apache.karaf.kar.internal.KarServiceImpl.installFeatures(KarServiceImpl.java:215)[160:org.apache.karaf.kar.core:3.0.5]
at org.apache.karaf.kar.internal.KarServiceImpl.install(KarServiceImpl.java:96)[160:org.apache.karaf.kar.core:3.0.5]
at org.apache.karaf.kar.internal.KarServiceImpl.install(KarServiceImpl.java:84)[160:org.apache.karaf.kar.core:3.0.5]
at Proxya6f8b1d5_e9a2_4e1b_a105_1552c365b9de.install(Unknown Source)[:]
at Proxye3575645_14c4_4cf9_8d71_16cd6e82b1a0.install(Unknown Source)[:]
at org.apache.karaf.deployer.kar.KarArtifactInstaller.install(KarArtifactInstaller.java:50)[162:org.apache.karaf.deployer.kar:3.0.5]
at Proxy6b7a1495_9239_4ff3_b9ed_1fd58a17750b.install(Unknown Source)[:]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.install(DirectoryWatcher.java:931)[7:org.apache.felix.fileinstall:3.5.0]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.install(DirectoryWatcher.java:865)[7:org.apache.felix.fileinstall:3.5.0]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:482)[7:org.apache.felix.fileinstall:3.5.0]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:358)[7:org.apache.felix.fileinstall:3.5.0]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:310)[7:org.apache.felix.fileinstall:3.5.0]
Caused by: org.apache.camel.NoSuchBeanException: Cannot lookup: jsonRPCProcessor from registry: org.apache.camel.blueprint.BlueprintContainerRegistry#7b081b97 with expected type: interface org.apache.camel.Processor due: [BeanRecipe[name='myTemplate'], BeanRecipe[name='.camelBlueprint.bean.factory.myTemplate'], BeanRecipe[name='camel-1'], BeanRecipe[name='myTemplate']]
at org.apache.camel.impl.CompositeRegistry.lookupByNameAndType(CompositeRegistry.java:62)
at org.apache.camel.impl.PropertyPlaceholderDelegateRegistry.lookupByNameAndType(PropertyPlaceholderDelegateRegistry.java:63)
at org.apache.camel.util.CamelContextHelper.lookup(CamelContextHelper.java:137)
at org.apache.camel.util.CamelContextHelper.mandatoryLookup(CamelContextHelper.java:157)
at org.apache.camel.impl.DefaultRouteContext.mandatoryLookup(DefaultRouteContext.java:151)
at org.apache.camel.model.ProcessDefinition.createProcessor(ProcessDefinition.java:95)
at org.apache.camel.model.ProcessorDefinition.makeProcessorImpl(ProcessorDefinition.java:534)
at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:495)
at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:219)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1069)
... 105 more
Caused by: org.apache.aries.blueprint.di.CircularDependencyException: [BeanRecipe[name='myTemplate'], BeanRecipe[name='.camelBlueprint.bean.factory.myTemplate'], BeanRecipe[name='camel-1'], BeanRecipe[name='myTemplate']]
at org.apache.aries.blueprint.container.BlueprintRepository.push(BlueprintRepository.java:343)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:71)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:247)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintRepository.createInstance(BlueprintRepository.java:230)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintRepository.create(BlueprintRepository.java:145)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.getComponentInstance(BlueprintContainerImpl.java:754)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.camel.blueprint.BlueprintContainerRegistry.lookupByNameAndType(BlueprintContainerRegistry.java:54)
at org.apache.camel.impl.CompositeRegistry.lookupByNameAndType(CompositeRegistry.java:56)
... 114 more
EDIT - It seems the error is because the jsonRPCProcessor is using myTemplate as shown below:-
<bean id="jsonRPCProcessor" class="com.j1.orchestratorservice.basecomponent.processor.JSONRPCProcessor">
<argument ref="myTemplate" />
<argument>
<map>
<!-- Product End Points -->
<entry key="Product.createProducts" value-ref="createProductsWFInfo" />
</map>
</argument>
<argument ref="exceptionHandler" />
</bean>
whereas myTemplate is defined in camelContext which in turn is using jsonRPCProcessor as shown below:-
<camelContext xmlns="http://camel.apache.org/schema/blueprint"
useMDCLogging="true">
<template id="myTemplate" />
<route id="orchestrator-service-route">
<from uri="jetty:http://0.0.0.0:8888/orchestratorservice" />
<process ref="jsonRPCProcessor" />
</route>
<route id="file-upload-service-route">
<from
uri="jetty:http://0.0.0.0:8889/fileuploadservice?enableMultipartFilter=true" />
<process ref="fileUploadProcessor" />
</route>
...
</camelContext>
I have tried to set the producer in my custom Processor as mentioned in this link. Can someone suggest me some other way of setting the producer in my custom jsonRPCProcessor so that it does not lead to any circular dependency?
I am able to get around this by removing myTemplate from jsonRPCProcesor and fileUploadProcessor. Now my jsonRPCProcessor look something like below:-
<bean id="jsonRPCProcessor" class="com.j1.orchestratorservice.basecomponent.processor.JSONRPCProcessor">
<argument>
<map>
<entry key="Product.createProducts" value-ref="createProductsWFInfo" />
</map>
</argument>
<argument ref="exceptionHandler" />
</bean>
Annotated the ProducerTemplate(in the base class) in my code with #EndPointInject. Something like below:-
#EndpointInject
protected ProducerTemplate myTemplate;
Related
I am migrating from camle 2 to camel 3 as below configuration
<onException>
<exception>com.sample</exception>
<redeliveryPolicy disableRedelivery="true"/>
<handled>
<constant>true</constant>
</handled>
<log message="got here, before predict, ${exchangeProperty.firstCall}" loggingLevel="INFO"/>
<choice>
<when>
<method>operation</method>
<bean ref="Procs" method="SampleCommentRequestForError"/>
<setProperty propertyName="firstCall">
<constant>false</constant>
</setProperty>
<log message="got here, after predict, ${exchangeProperty.firstCallOf}" loggingLevel="INFO"/>
<to uri="direct:sample-comment"/>
</when>
</choice>
<bean ref="abc_errorhandler" method="abcException"/>
</onException>
and getting below exception :
Failed to create route route-nsm-client-call at: >>> OnException[[com.sample] -> [Log[got here, before predict, ${exchangeProperty.firstCall], Choice[[When[bean{abc} [From[direct:bbc-call ->... because of Bean language requires bean, beanType, or ref argument
Caused by: java.lang.IllegalArgumentException: Bean language requires bean, beanType, or ref argument
Any idea on this?
This will work camel 2.x operation but if you try to upgrade camel 3.x for existing code. So, in that case you need to change this code to like below sample . but rather than myBean provide whole class package path.
Try below sample code..
for more details, please check below official website..
https://camel.apache.org/components/3.17.x/languages/bean-language.html
I have the following route definitions file (linehaul-routes.xml):
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<route id="route1" errorHandlerRef="myErrorHandler">
<from uri="amqp:queue:DSMLH_consignment_event"/> <!-- AMQP queue to which I send messages to trigger the route !-->
<to uri="https://pesho.free.beeceptor.com/"/> <!-- Returns http 500 !-->
</route>
</routes>
I also have a file with error handler in the same directory (linehaul-error-handlers.xml):
<errorHandlers>
<errorHandler id="myErrorHandler" type="DefaultErrorHandler">
<redeliveryPolicy maximumRedeliveries="5" redeliveryDelay="2000"/>
</errorHandler>
</errorHandlers>
And application.properties
camel.context.name=testContext
camel.main.routes-include-pattern=classpath:routes/linehaul-routes.xml,classpath:routes/linehaul-error-handlers.xml
When I run the code I get the following stacktrace
2022-04-27 19:44:53,657 ERROR [org.apa.cam.qua.mai.CamelMainRuntime] (Quarkus Main Thread) [{}] Failed to start application: org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> To[https://pesho.free.beeceptor.com/] <<< in route: Route(route1)[From[amqp:queue:DSMLH_consignment_event] -> [T... because of No bean could be found in the registry for: myErrorHandler of type: org.apache.camel.ErrorHandlerFactory
at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:240)
at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:74)
at org.apache.camel.impl.DefaultModelReifierFactory.createRoute(DefaultModelReifierFactory.java:49)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:868)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:758)
at org.apache.camel.impl.engine.AbstractCamelContext.doInit(AbstractCamelContext.java:2862)
at org.apache.camel.quarkus.core.FastCamelContext.doInit(FastCamelContext.java:166)
at org.apache.camel.support.service.BaseService.init(BaseService.java:83)
at org.apache.camel.impl.engine.AbstractCamelContext.init(AbstractCamelContext.java:2568)
at org.apache.camel.support.service.BaseService.start(BaseService.java:111)
at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2587)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:247)
at org.apache.camel.quarkus.main.CamelMain.doStart(CamelMain.java:94)
at org.apache.camel.support.service.BaseService.start(BaseService.java:119)
at org.apache.camel.quarkus.main.CamelMain.startEngine(CamelMain.java:140)
at org.apache.camel.quarkus.main.CamelMainRuntime.start(CamelMainRuntime.java:49)
at org.apache.camel.quarkus.core.CamelBootstrapRecorder.start(CamelBootstrapRecorder.java:45)
at io.quarkus.deployment.steps.CamelBootstrapProcessor$boot173480958.deploy_0(Unknown Source)
at io.quarkus.deployment.steps.CamelBootstrapProcessor$boot173480958.deploy(Unknown Source)
at io.quarkus.runner.ApplicationImpl.doStart(Unknown Source)
at io.quarkus.runtime.Application.start(Application.java:101)
at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:103)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:67)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:41)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:120)
at io.quarkus.runner.GeneratedMain.main(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at io.quarkus.runner.bootstrap.StartupActionImpl$1.run(StartupActionImpl.java:103)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: myErrorHandler of type: org.apache.camel.ErrorHandlerFactory
at org.apache.camel.support.CamelContextHelper.mandatoryLookup(CamelContextHelper.java:241)
at org.apache.camel.model.errorhandler.ErrorHandlerHelper.lookupErrorHandlerFactory(ErrorHandlerHelper.java:82)
at org.apache.camel.reifier.errorhandler.ErrorHandlerRefReifier.lookupErrorHandler(ErrorHandlerRefReifier.java:41)
at org.apache.camel.reifier.errorhandler.ErrorHandlerRefReifier.createErrorHandler(ErrorHandlerRefReifier.java:35)
at org.apache.camel.impl.DefaultModelReifierFactory.createErrorHandler(DefaultModelReifierFactory.java:65)
at org.apache.camel.reifier.ProcessorReifier.wrapInErrorHandler(ProcessorReifier.java:745)
at org.apache.camel.reifier.ProcessorReifier.wrapChannelInErrorHandler(ProcessorReifier.java:726)
at org.apache.camel.reifier.ProcessorReifier.wrapChannel(ProcessorReifier.java:705)
at org.apache.camel.reifier.ProcessorReifier.wrapChannel(ProcessorReifier.java:611)
at org.apache.camel.reifier.ProcessorReifier.wrapProcessor(ProcessorReifier.java:607)
at org.apache.camel.reifier.ProcessorReifier.makeProcessor(ProcessorReifier.java:854)
at org.apache.camel.reifier.ProcessorReifier.addRoutes(ProcessorReifier.java:579)
at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:236)
... 31 more
What is wrong with the route to error handler mapping ?
(My goal is to make my route to re-try several times on http 500)
Camel Quarkus only supports 'simple' XML routes. You cannot define beans directly like you can with Camel Spring XML.
Instead, you can declare a CDI bean and reference it in the XML. For example.
#Named("myErrorHandler")
public DefaultErrorHandlerBuilder createDefaultErrorHandler() {
return new DefaultErrorHandlerBuilder()
.maximumRedeliveries(5)
.redeliveryDelay(2000);
}
Then you can reference the bean via errorHandlerRef on the route tag.
<route id="route1" errorHandlerRef="myErrorHandler">
I have a simple route which looks like this:
<route handleFault="true" streamCache="true" id="routeA">
<from uri="cxfrs://bean://simpleCxf" />
<log message="The message body contains ${body}"/>
<to uri="direct-vm:RouteB" />
</route>
<route handleFault="true" streamCache="true" id="routeB">
<from uri="direct-vm:RouteB" />
<bean ref="requestValidator" method="validateRequest" />
<log message="The input message ${body}" />
<bean ref="dbClient" method="queryDatabase" />
</route>
the cxf configuration is also pretty simple:
<cxf:rsServer id="simpleCxf" address="/test"
loggingFeatureEnabled="true"
serviceClass="com.gogol.test.TestResource">
</cxf:rsServer>
This simple route fails with the below exception
No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: org.apache.camel.Exchange with value [com.gogol.test.resource.SimpleObject#773736ca]
This is the message history which suggests that it is failing at the point <bean ref="requestValidator" method="validateRequest" />
Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId ProcessorId Processor Elapsed (ms)
[routeA] [routeA] [direct-vm://routeA ] [6]
[routeB] [log12 ] [log ] [2]
[routeB] [to9 ] [direct-vm:routeA ] [4]
[routeA] [bean26] [bean[ref:requestValidator method: validateRequest]] [2]
I think the issue is that Camel is trying to convert the body generated by cxf to an Exchange object. Because the requestValidator class has a method which has a signature of:
public void validateRequest(Exchange exchange) thows SomeException.
But ideally the message generated by cxf should be set as a body inside Exchange. Am I correct, if not then what could be the reason of the above exception?
EDIT:
I am using CXF version 3.0.4.redhat-621084
and CAMEL version 2.15.1.redhat-621084
{Caused by: org.apache.camel.InvalidPayloadException: No body available of type: org.apache.camel.Exchange but has value: [com.gogol.schema.TestResourcec#6b651b67] of type: org.apache.cxf.message.MessageContentsList on: Message: [com.gogol.schema.TestResourcec#6b651b67]. Caused by: No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: org.apache.camel.Exchange with value [com.gogol.schema.TestResourcec#6b651b67]. Exchange[Message: [com.gogol.schema.TestResourcec#6b651b67]]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: org.apache.camel.Exchange with value [com.gogol.schema.TestResourcec#6b651b67]]
at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:101)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.builder.ExpressionBuilder$42.evaluate(ExpressionBuilder.java:1037)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
... 68 more
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: org.apache.camel.Exchange with value [com.gogol.schema.TestResourcec#6b651b67]
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:177)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.core.osgi.OsgiTypeConverter.mandatoryConvertTo(OsgiTypeConverter.java:122)[203:org.apache.camel.camel-spring:2.15.1.redhat-621084]
at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:99)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
... 69 more}
I am not positive on the camel xml dsl how to format this properly, but you can always explicitly tell camel to do a type conversion. You could test your theory by using a convertBodyTo call to force a type conversion.
from("myEndpoint")
.log("This is my previous object")
.convertBodyTo(TestResource.class)
.log("This is my object after a camel type conversion");
I have the onException block below that worked before I upgraded to from camel 2.14 to camel 2.16.1. Before the update, I would get my error caught and printed in the log - "Error posting to MR". After I upgraded to camel 2.16.1, I still get my error in the log, but now, always, my handled error is followed by another timestamp with what appears to be camel default error handler for the error I think I already handled. It looks like this:
"2016-01-26 15:07:09,571 [Camel (mrPostContext) thread #56 - JmsConsumer[mrPost]] ERROR org.apache.camel.processor.DefaultErrorHandler - Failed delivery for (MessageId"....
I don't know if I'm doing something wrong, I tried using java.lang.Throwable instead of java.lang.Exception but so far had no luck. Haven't found anything helpful in documentation yet. As I'm far from being good with camel, I will much appreciate some help.
<route id="mrPost">
<from uri="activemq:mrPost?concurrentConsumers=8" />
<onException>
<exception>java.lang.Exception</exception>
<redeliveryPolicy maximumRedeliveries="2" redeliveryDelay="1000"/>
<handled>
<constant>true</constant>
</handled>
<to uri="activemq:mr-post-fail" />
<log loggingLevel="ERROR" message="Error posting to MR body:${out.body} exception message: ${exception.message} body:${exception.responseBody}" />
</onException>
<setHeader headerName="CamelHttpMethod">
<constant>PUT</constant>
</setHeader>
<recipientList>
<simple>{{mr.source}}/${headers.id}</simple>
</recipientList>
</route>
Here is a much cleaner solution in case someone is looking for it:
<errorHandler id="loggingErrorHandler" type="LoggingErrorHandler" logName="LoggingErrorHandler" level="OFF"/>
<camelContext id="mrPostContext" trace="false" errorHandlerRef="loggingErrorHandler" >
I think that camel is failing where it puts the message on to the error queue mr-post-fail and is throwing an exception when doing so, hence your exception is propogating to the DefaultExceptionHandler. Since the logging is after the put queue call it is not working as you expected.
If not the case can you give the whole line of the error thats being printed.
"2016-01-26 15:07:09,571 [Camel (mrPostContext) thread #56 - JmsConsumer[mrPost]] ERROR org.apache.camel.processor.DefaultErrorHandler - Failed delivery for (MessageId"..
I got the defaultErrorHandler to collapse with these 2 adjustments:
- set messageHistory="false" on CONTEXT
- set logStackTrace="false" for onException block, like this:
<redeliveryPolicy maximumRedeliveries="2" redeliveryDelay="1000" logStackTrace="false" />
The timestamp with default error handler still shows up, but much easier on the eye, it looks like this:
2016-02-01 11:26:27,792 [Camel (mrPostContext) thread #262 - JmsConsumer[mrPost]] ERROR org.apache.camel.processor.DefaultErrorHandler - Failed delivery for (MessageId: ID-qn7nwscms01-com-44939-1454025367155-1569-4 on ExchangeId: ID-qn7nwscms01-com-44939-1454025367155-1569-5). Exhausted after delivery attempt: 3 caught: org.apache.camel.http.common.HttpOperationFailedException: HTTP operation failed invoking http://mr.cloud.dig.com/api/contents/news/30939510 with statusCode: 409. Processed by failure processor: FatalFallbackErrorHandler[Pipeline[[Channel[SetHeader(CamelExceptionCaught, Simple: Headers: ${headers} Message: ${exception.message} Body: ${exception.responseBody})], Channel[sendTo(Endpoint[activemq://mr-post-fail])], Channel[choice{when Filter[if: Simple: ${exception.message} not contains "statusCode: 409" do: Pipeline[[Channel[SetHeader(Content-Type, text/plain)], Channel[SetHeader(to, Simple: lw#ac.com)], Channel[SetHeader(subject, Simple: Error posting to MR)], Channel[SetBody(Simple: ${header.CamelExceptionCaught})]]]]}], Channel[Log(mrPost)[Error posting to MR ID: ${headers.contentId}, type:${headers.cmsContentType}, modified:${headers.lastModifiedDate}, getTime:${headers.lastModifiedGetTime}]], Channel[Log(merlinPost)[Error posting to MR body:${out.body} exception message: ${exception.message} body:${exception.responseBody}]]]]]
I hope there is a way to turn it off completely.
I also tried using defaultErrorHandler setup:
<errorHandler id="defaultErrorHandler" type="DefaultErrorHandler">
<redeliveryPolicy logStackTrace="false"/>
</errorHandler>
but it makes no impact.
You can use like the example in this page: http://camel.apache.org/exception-clause.html
<!-- setup our error handler as the deal letter channel -->
<bean id="errorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder">
<property name="deadLetterUri" value="activemq:mr-post-fail"/>
</bean>
<!-- this is the camel context where we define the routes -->
<!-- define our error handler as a global error handler -->
<camelContext errorHandlerRef="errorHandler" xmlns="http://camel.apache.org/schema/spring">
<route>
<!-- the route -->
<from uri="activemq:mrPost?concurrentConsumers=8" />
<setHeader headerName="CamelHttpMethod">
<constant>PUT</constant>
</setHeader>
<recipientList>
<simple>{{mr.source}}/${headers.id}</simple>
</recipientList>
</route>
</camelContext>
Or, set in rote, to the error handle work only with an specific route
<route errorHandlerRef="errorHandler">
...
</route>
And remove from camelContext
i'm using camel to validate an xml and in the route I'm doing the following:
<route>
<from uri="file:{{file.inbox}}?preMove=inprogress&move=../.done"/>
<doTry>
<to uri="validator:classpath:idocOrderStatus.xsd"/>
<to uri="file:{{file.outbox.valid}}"/>
<doCatch>
<exception>org.apache.camel.ValidationException</exception>
<to uri="file:{{file.outbox.invalid}}"/>
</doCatch>
</doTry>
</route>
and I'm getting the following error:
Exception in thread "SpringOsgiExtenderThread-10" org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: Failed to create route route7 at: >>> DoT
ry[[To[validator:classpath:idocOrderStatus.xsd], To[file:outbox/valid], DoCatch[ null -> [To[file:{{file.outbox.invalid}}]]]]] <<< in route: Route[[From[file:{{file.inbox}}?preMove=inprogres
s&move=../.... because of org.apache.camel.ValidationException
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1157)
at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:110)
at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:240)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:303)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:911)
at org.springframework.osgi.context.support.AbstractOsgiBundleApplicationContext.finishRefresh(AbstractOsgiBundleApplicationContext.java:235)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:358)
at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:
132)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route route7 at: >>> DoTry[[To[validator:classpath:idocOrderStatus.xsd], To[file:outbox/valid], DoCatch[ null -> [T
o[file:{{file.outbox.invalid}}]]]]] <<< in route: Route[[From[file:{{file.inbox}}?preMove=inprogress&move=../.... because of org.apache.camel.ValidationException
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:820)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:165)
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:685)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1683)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1468)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1360)
at org.apache.camel.spring.SpringCamelContext.doStart(SpringCamelContext.java:169)
at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:67)
at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:54)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1328)
at org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:213)
at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:108)
... 10 more
Caused by: java.lang.ClassNotFoundException: org.apache.camel.ValidationException
at org.apache.camel.impl.DefaultClassResolver.resolveMandatoryClass(DefaultClassResolver.java:52)
at org.apache.camel.model.CatchDefinition.createExceptionClasses(CatchDefinition.java:254)
at org.apache.camel.model.CatchDefinition.createProcessor(CatchDefinition.java:91)
at org.apache.camel.model.TryDefinition.createProcessor(TryDefinition.java:90)
at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:444)
at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:183)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:817)
... 21 more
I do not understend why I'm getting this error? There is anyway to import this class in the camel context? How should I do it?
You can find the solution on the fuse forum fuse forum