[ 
https://issues.apache.org/activemq/browse/SM-1378?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=43126#action_43126
 ] 

Sebastian Gomez commented on SM-1378:
-------------------------------------

I found a solution to this issue, but if there is no other workaround to it, I 
think it should be at least documented somewhere to prevent people getting 
stuck in the same place as I have.

When creating a route to a jbi:service, the camel context factory looks for a 
bean called "jbi" (because of the prefix of the service). This bean must be a 
Component. So the first part of the workaround is to declare such bean (of 
class org.apache.servicemix.camel.CamelJbiComponent) in the servicemix.xml 
file. The problem comes when the message is about to be delivered: as it has 
been declared outside the jbi container, the component has no context. To fix 
this, the way to go is to declare a component inside the jbi container 
referencing the declared bean. So finally the servicemix.xml file should look 
like this:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xbean.org/schemas/spring/1.0";
           xmlns:sm="http://servicemix.apache.org/config/1.0";
           xmlns:bean="http://servicemix.apache.org/bean/1.0";
           xmlns:camel="http://activemq.apache.org/camel/schema/spring";
           xmlns:myproject="http://my.namespace.com/";>

        <!-- the JBI container -->
        <sm:container id="jbiContainer" embedded="true">
                <sm:activationSpecs>
                        <sm:activationSpec id="bean">
                                <sm:component>
                                        <bean:component>
                                                <bean:endpoints>
                                                        <bean:endpoint 
service="myproject:tracker" endpoint="tracker" bean="#tracker" />
                                                </bean:endpoints>
                                        </bean:component>
                                </sm:component>
                        </sm:activationSpec>
                        <sm:activationSpec id="camel" service="camel:camel" 
endpoint="camelEndpoint">
                                <sm:component>
                                    <ref bean="jbi" />
                                </sm:component>
                        </sm:activationSpec>
                </sm:activationSpecs>
        </sm:container>
        
        <bean id="jbi" class="org.apache.servicemix.camel.CamelJbiComponent" />
        
        <camelContext id="camelContext" useJmx="true" 
xmlns="http://activemq.apache.org/camel/schema/spring";>
                <package>my.project.routeBuilders</package>
        </camelContext>
        
        <bean id="client"
                class="org.apache.servicemix.client.DefaultServiceMixClient">
                <constructor-arg ref="jbiContainer" />
        </bean>
        
        <bean id="tracker" class="my.project.Tracker" />

</beans>

> 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.

Reply via email to