You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Andrei Shakirin <as...@talend.com> on 2011/09/23 11:22:56 UTC

Camel uses old context to resolve endpoint by routing

Hi,

I have discovered strange behavior for Camel 2.7.3 in following scenario:

Two camel routes configured via Spring are deployed into different OSGi bundles and communicate using VM component.

1. Configuration in first bundle:
       <cxf:cxfEndpoint id="wsFacadeEndpoint"
             xmlns:tns="http://com.dpdhl/cig/facade/v1"
             endpointName="tns:WSFacadePort"
             serviceName="tns:WSFacade"
             serviceClass="com.dpdhl.cig.facade.WebServiceFacade"
             address="/cig"/>

       <camel:camelContext id="wsFacadeContext"
             xmlns="http://camel.apache.org/schema/spring">
             <camel:route>
                    <camel:from uri="cxf:bean:wsFacadeEndpoint" />
                    <camel:to uri="vm:cig-generic-routing?concurrentConsumers=10" />
             </camel:route>
       </camel:camelContext>
Camel exposes generic SOAP service, receives requests and forwards them to VM endpoint.

2. Configuration in second bundle:
       <bean id="tracingBean" class="com.dpdhl.cig.routing.TracingBean" />
       <bean id="nsRouting" class="com.dpdhl.cig.routing.NSRoutingSlip" />

       <camel:camelContext id="genericContext"
             xmlns="http://camel.apache.org/schema/spring">
             <camel:route>
                    <camel:from uri="vm:cig-generic-routing?concurrentConsumers=10" />
                    <camel:to uri="bean:nsRouting?method=route" />
             </camel:route>
       </camel:camelContext>

Route receives exchange from first bundle and pass it to the router.

3. Router code:
public class NSRoutingSlip {
       private static final Logger LOG = Logger.getLogger(NSRoutingSlip.class
                    .getName());
       @RoutingSlip
       public final String route(final Exchange exchange) {
             LOG.info("Called router: " + exchange);
             return "bean:tracingBean?method=process";
       }
}

Router just forwarded exchange to bean declared in second configuration and located in second bundle.

4. Result:
The code works except the last step: forwarding to the tracingBean. Here I have an Exception: "Bean is not found in the registry".

Interesting is the following:
A) as far as I define the same bean endpoint in second route configuration directly it works
       <bean id="tracingBean" class="com.dpdhl.cig.routing.TracingBean" />
       <bean id="nsRouting" class="com.dpdhl.cig.routing.NSRoutingSlip" />

       <camel:camelContext id="genericContext"
             xmlns="http://camel.apache.org/schema/spring">
             <camel:route>
                    <camel:from uri="vm:cig-generic-routing?concurrentConsumers=10" />
                    <camel:to uri=" bean:tracingBean?method=process" />
             </camel:route>
       </camel:camelContext>

B) as far as I declare the bean in FIRST configuration and import package with the TracingBean in first bundle, code also works.

Conclusion: it seems that Camel uses context from the first bundle (it is stored in exchange) to resolve endpoint returned by NSRoutingSlip. It is unexpected behaviour.

Question: does it work as designed or is it bug?

OSGi container is Karaf with equinox.
Fulll source code is attached.

Regards,
Andrei.

RE: Camel uses old context to resolve endpoint by routing

Posted by Andrei Shakirin <as...@talend.com>.
Hi Willem,

Yep, it is exactly the reason.
Of course exchange comes with "old" camel context.
Do you interpret it as normal behavior?
Are there any workarounds to solve it?

Regards,
Andrei.

-----Original Message-----
From: Willem Jiang [mailto:willem.jiang@gmail.com] 
Sent: 23 September 2011 15:27
To: users@camel.apache.org
Subject: Re: Camel uses old context to resolve endpoint by routing

Hi,

I just checked the code and found the RoutingSlip is using the camel context from the exchange to resolve the endpoint.
That can explain what you find :)
 
On Fri Sep 23 19:15:18 2011, Andrei Shakirin wrote:
> Hi Ioannis,
>
> Hmm ... I do not think so.
> If camel-core.jar loaded in the same classloader (http://camel.apache.org/vm.html) it works. And it is exactly the case if both bundles uses the same version of camel-core bundle.
> Basically communication works, I have my RoutingSlip called with correct exchange.
> The confusing point is why endpoint returned by RoutingSlip is trying to resolve using old Camel Context (from the first bundle).
> If the same endpoint is defined statically in camel route spring configuration - it resolved using actual Camel Context  (from the second bundle).
> For me is unexpected behaviour.
>
> Regards,
> Andrei.
>
>
> -----Original Message-----
> From: Ioannis Canellos [mailto:iocanel@gmail.com]
> Sent: 23 September 2011 12:28
> To: users@camel.apache.org
> Subject: Re: Camel uses old context to resolve endpoint by routing
>
> I think that the vm can only be used to bridge contexts that are in the same bundle.
> --
> *Ioannis Canellos*
> *
> FuseSource<http://fusesource.com>
>
> **
> Blog: http://iocanel.blogspot.com
> **
> Apache Karaf<http://karaf.apache.org/>  Committer&  PMC Apache ServiceMix<http://servicemix.apache.org/>   Committer Apache Gora<http://incubator.apache.org/gora/>  Committer
> *
>



--
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
         http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang 


Re: Camel uses old context to resolve endpoint by routing

Posted by Willem Jiang <wi...@gmail.com>.
Hi,

I just checked the code and found the RoutingSlip is using the camel 
context from the exchange to resolve the endpoint.
That can explain what you find :)
 
On Fri Sep 23 19:15:18 2011, Andrei Shakirin wrote:
> Hi Ioannis,
>
> Hmm ... I do not think so.
> If camel-core.jar loaded in the same classloader (http://camel.apache.org/vm.html) it works. And it is exactly the case if both bundles uses the same version of camel-core bundle.
> Basically communication works, I have my RoutingSlip called with correct exchange.
> The confusing point is why endpoint returned by RoutingSlip is trying to resolve using old Camel Context (from the first bundle).
> If the same endpoint is defined statically in camel route spring configuration - it resolved using actual Camel Context  (from the second bundle).
> For me is unexpected behaviour.
>
> Regards,
> Andrei.
>
>
> -----Original Message-----
> From: Ioannis Canellos [mailto:iocanel@gmail.com]
> Sent: 23 September 2011 12:28
> To: users@camel.apache.org
> Subject: Re: Camel uses old context to resolve endpoint by routing
>
> I think that the vm can only be used to bridge contexts that are in the same bundle.
> --
> *Ioannis Canellos*
> *
> FuseSource<http://fusesource.com>
>
> **
> Blog: http://iocanel.blogspot.com
> **
> Apache Karaf<http://karaf.apache.org/>  Committer&  PMC Apache ServiceMix<http://servicemix.apache.org/>   Committer Apache Gora<http://incubator.apache.org/gora/>  Committer
> *
>



-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
         http://jnn.javaeye.com (Chinese)
Twitter: willemjiang 
Weibo: willemjiang 


RE: Camel uses old context to resolve endpoint by routing

Posted by Andrei Shakirin <as...@talend.com>.
Hi Ioannis,

Hmm ... I do not think so.
If camel-core.jar loaded in the same classloader (http://camel.apache.org/vm.html) it works. And it is exactly the case if both bundles uses the same version of camel-core bundle.
Basically communication works, I have my RoutingSlip called with correct exchange.
The confusing point is why endpoint returned by RoutingSlip is trying to resolve using old Camel Context (from the first bundle).
If the same endpoint is defined statically in camel route spring configuration - it resolved using actual Camel Context  (from the second bundle).
For me is unexpected behaviour.

Regards,
Andrei.


-----Original Message-----
From: Ioannis Canellos [mailto:iocanel@gmail.com] 
Sent: 23 September 2011 12:28
To: users@camel.apache.org
Subject: Re: Camel uses old context to resolve endpoint by routing

I think that the vm can only be used to bridge contexts that are in the same bundle.
--
*Ioannis Canellos*
*
FuseSource <http://fusesource.com>

**
Blog: http://iocanel.blogspot.com
**
Apache Karaf <http://karaf.apache.org/> Committer & PMC Apache ServiceMix <http://servicemix.apache.org/>  Committer Apache Gora <http://incubator.apache.org/gora/> Committer
*

Re: Camel uses old context to resolve endpoint by routing

Posted by Ioannis Canellos <io...@gmail.com>.
I think that the vm can only be used to bridge contexts that are in the same
bundle.
-- 
*Ioannis Canellos*
*
FuseSource <http://fusesource.com>

**
Blog: http://iocanel.blogspot.com
**
Apache Karaf <http://karaf.apache.org/> Committer & PMC
Apache ServiceMix <http://servicemix.apache.org/>  Committer
Apache Gora <http://incubator.apache.org/gora/> Committer
*