[
https://issues.apache.org/activemq/browse/SM-1378?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45560#action_45560
]
Ćukasz Dywicki commented on SM-1378:
------------------------------------
Problem source - SpringCamelContext created by camel namespace handler use
ApplicationContextRegistry.
There is line 39:
{{Object value = applicationContext.getBean(name, type);}}
If we use prefix "jbi" camel will lookup for bean named jbi in
ApplicationContext. Longer workaround based on own Registry implementation. At
this moment I have a problem with correct test for camel execution, but i think
this code can be base for issue resolution.
*context.xml*
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:sm="http://servicemix.apache.org/config/1.0"
xmlns:test="http://servicemix.apache.org/test"
xmlns:camel="http://activemq.apache.org/camel/schema/spring"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://servicemix.apache.org/config/1.0
http://servicemix.apache.org/schema/servicemix-core-3.2.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://activemq.apache.org/camel/schema/spring
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
">
<bean id="camel" class="org.apache.servicemix.camel.CamelJbiComponent" />
<sm:container id="jbi" rootDir="target/data">
<sm:activationSpecs>
<sm:activationSpec service="test:camel" endpoint="endpoint">
<sm:component>
<ref bean="camel" />
</sm:component>
</sm:activationSpec>
<sm:activationSpec service="test:echo" endpoint="endpoint">
<sm:component>
<bean
class="org.apache.servicemix.components.util.EchoComponent" />
</sm:component>
</sm:activationSpec>
</sm:activationSpecs>
</sm:container>
<camelContext id="camelContext" useJmx="false"
xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
<from
uri="timer://myTimer?fixedRate=true&delay=0&period=1000" />
<to uri="jbi:service:http://servicemix.apache.org/test/echo" />
</route>
</camelContext>
<bean
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"
depends-on="camelContext"
lazy-init="false">
<property name="targetObject" ref="camelContext" />
<property name="targetMethod" value="setRegistry" />
<property name="arguments">
<bean class="org.apache.servicemix.camel.HackedRegistry">
<property name="component" ref="camel" />
</bean>
</property>
</bean>
</beans>
{quote}
*HackedRegistry.java*
package org.apache.servicemix.camel;
import org.apache.camel.spi.Registry;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
public class HackedRegistry implements Registry, ApplicationContextAware {
private CamelJbiComponent component;
private ApplicationContext applicationContext;
public Object lookup(String name) {
System.out.println("lookup for " + name);
return name.equals("jbi") ? getComponent() :
applicationContext.getBean(name);
}
public <T> T lookup(String name, Class<T> type) {
System.out.println("lookup for " + name + " type " +
type.getCanonicalName());
try {
Object value = applicationContext.getBean(name, type);
return type.cast(value);
} catch (NoSuchBeanDefinitionException e) {
return null;
}
}
public CamelJbiComponent getComponent() {
return component;
}
public void setComponent(CamelJbiComponent component) {
this.component = component;
}
public void setApplicationContext(ApplicationContext arg0)
throws BeansException {
applicationContext = arg0;
}
}
Expected result:
DEBUG DefaultComponentResolver - Found component: jbi in registry: [EMAIL
PROTECTED]
In place where previous was:
DEBUG DefaultComponentResolver - Found component: jbi in registry: [EMAIL
PROTECTED]
> JBI endpoints not available from Camel when using Embedded ServiceMix
> ---------------------------------------------------------------------
>
> Key: SM-1378
> URL: https://issues.apache.org/activemq/browse/SM-1378
> Project: ServiceMix
> Issue Type: Bug
> Components: servicemix-camel
> Affects Versions: 3.2.2
> Reporter: Sebastian Gomez
> Attachments: attachments.zip
>
>
> When declaring an embedded JBI container and a CamelContext, Camel is unable
> to reference JBI endpoints, throwing a "NoSuchEndpointException".
> I attach the files that reproduce the problem, and here is the stack trace I
> get:
> [org.springframework.web.context.ContextLoader] - Context
> initialization failed
> org.apache.camel.NoSuchEndpointException: No endpoint could be found
> for: jbi:service:http://my.namespace.com//tracker
> at
> org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:54)
> at org.apache.camel.model.RouteType.resolveEndpoint(RouteType.java:92)
> at
> org.apache.camel.impl.RouteContext.resolveEndpoint(RouteContext.java:95)
> at
> org.apache.camel.impl.RouteContext.resolveEndpoint(RouteContext.java:104)
> at org.apache.camel.model.ToType.resolveEndpoint(ToType.java:78)
> at org.apache.camel.model.ToType.createProcessor(ToType.java:72)
> at
> org.apache.camel.model.ProcessorType.makeProcessor(ProcessorType.java:1387)
> at org.apache.camel.model.ProcessorType.addRoutes(ProcessorType.java:95)
> at org.apache.camel.model.RouteType.addRoutes(RouteType.java:189)
> at org.apache.camel.model.RouteType.addRoutes(RouteType.java:83)
> at
> org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:438)
> at
> org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:430)
> at
> org.apache.camel.spring.SpringCamelContext.doStart(SpringCamelContext.java:148)
> at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:47)
> at
> org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:102)
> at
> org.springframework.context.event.SimpleApplicationEventMulticaster$1.run(SimpleApplicationEventMulticaster.java:77)
> at
> org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
> at
> org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:75)
> at
> org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:246)
> at
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:355)
> at
> org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:244)
> at
> org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:187)
> at
> org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
> at
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
> at
> org.apache.catalina.core.StandardContext.start(StandardContext.java:4350)
> at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
> at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
> at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
> at
> org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
> at
> org.apache.catalina.core.StandardService.start(StandardService.java:516)
> at
> org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
> at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
> at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.