Forum Home » Fuse Distributions » Fuse Mediation Router

Thread: Properties unavailable when Exchange originates from another Camel Context

 
This question is answered.


Permlink Replies: 7 - Last Post: Mar 4, 2012 1:29 PM Last Post By: davsclaus Threads: [ Previous | Next ]
futuredan

Posts: 40
Registered: 11/22/10
Properties unavailable when Exchange originates from another Camel Context
Posted: Mar 1, 2012 10:30 PM
 
  Click to reply to this thread Reply
I have the following routes in one camel context

<camelContext xmlns="http://camel.apache.org/schema/spring" trace="false">
<propertyPlaceholder id="properties" location="ref:main.props"/>

<route>
<from uri="file:c:/tmp/forum/MainTest?moveFailed=.camelError"/>
<inOut uri="vm:forum.futuredan.camelprop.main:realRoute"/>
</route>

<route>
<from uri="vm:forum.futuredan.camelprop.main:realRoute"/>
<setHeader headerName="forum.futuredan.example">
<simple>${properties:exampleProp}</simple>
</setHeader>
<log message="Example property - ${in.header.forum.futuredan.example}"></log>
<inOut uri="file:c:/tmp/forum/MainOut"/>
</route>

</camelContext>

<osgix:cm-properties id="main.props" persistent-id="forum.futuredan.camelprop.main">
<prop key="exampleProp">PropertyExample</prop>
</osgix:cm-properties>
<context:property-placeholder properties-ref="main.props" />

The route works fine when files are dropped in c:/tmp/forum/MainTest.

I have another Camel context that has the following route:

<route>
<from uri="file:c:/tmp/forum/RemoteTest?moveFailed=.camelError"/>
<inOut uri="vm:forum.futuredan.camelprop.main:realRoute"/>
</route>

The Exchange fails when files are dropped in c:/tmp/forum/RemoteTest.
The error is 'java.lang.IllegalArgumentException: Property with key exampleProp not found in properties for uri: {{exampleProp}}'

Why is the behavior different between the two?
Is there any workaround?

davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Properties unavailable when Exchange originates from another Camel Context
Posted: Mar 2, 2012 7:58 AM   in response to: futuredan in response to: futuredan
 
  Click to reply to this thread Reply
You need to setup property placeholder for both your camel contexts, as they are looked up at runtime as well when using Camel.
futuredan

Posts: 40
Registered: 11/22/10
Re: Properties unavailable when Exchange originates from another Camel Context
Posted: Mar 2, 2012 1:56 PM   in response to: davsclaus in response to: davsclaus
 
  Click to reply to this thread Reply
Both have placeholders defined.

Main has the following:

<osgix:cm-properties id="main.props" persistent-id="forum.futuredan.camelprop.main">
<prop key="exampleProp">PropertyExample</prop>
</osgix:cm-properties>
<context:property-placeholder properties-ref="main.props" />

Remote has the following:

<osgix:cm-properties id="remote.props" persistent-id="forum.futuredan.camelprop.remote">
<prop key="remoteProp">vm:forum.futuredan.camelprop.main:realRoute</prop>
</osgix:cm-properties>
<context:property-placeholder properties-ref="remote.props" />
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Properties unavailable when Exchange originates from another Camel Context
Posted: Mar 2, 2012 4:04 PM   in response to: futuredan in response to: futuredan
Helpful
  Click to reply to this thread Reply
There was a bug in an older Camel release when sending an Exchange over VM between properties.

Are you using a recent version of Camel? What version are you using? You may try to upgrade.
futuredan

Posts: 40
Registered: 11/22/10
Re: Properties unavailable when Exchange originates from another Camel Context
Posted: Mar 2, 2012 4:09 PM   in response to: davsclaus in response to: davsclaus
 
  Click to reply to this thread Reply
Thank you for the information.

I tried to remind myself to include version information, but forgot by the time I reached the end of my post. :(

We are using FUSE 4.3.1-01-15, which uses Camel 2.6.0-fuse-01-15 (I believe).

Do you know when it was fixed?
Is there some workaround besides upgrading Camel?

We are being used as a framework, so upgrading would be quite disruptive and we'd like to avoid that as a solution if at all possible.
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Properties unavailable when Exchange originates from another Camel Context
Posted: Mar 2, 2012 5:04 PM   in response to: futuredan in response to: futuredan
Correct
  Click to reply to this thread Reply
When sending between CamelContext over VM, then you possible have to copy the Exchange and set a the correct CamelContext.

See the preapareExchange method of the seda endpoint
https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
futuredan

Posts: 40
Registered: 11/22/10
Re: Properties unavailable when Exchange originates from another Camel Context
Posted: Mar 2, 2012 7:46 PM   in response to: davsclaus in response to: davsclaus
 
  Click to reply to this thread Reply
Thanks once again for the information.

Let me just make sure I understand your advice.

Would I create a bean that contains the code from the prepareExchange method?

And then insert it into my existing route like the following:

<from uri="vm:forum.futuredan.camelprop.main:hiddenRoute"/>
<inOut uri="bean:workaroundBean?method=prepareExchange"/>
<setHeader headerName="forum.futuredan.example">
<simple>${properties:exampleProp}</simple>
</setHeader>

I think I would create a custom Camel endpoint so that I could have access to the correct Camel context.

Does the above sound correct?

davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Properties unavailable when Exchange originates from another Camel Context
Posted: Mar 4, 2012 1:29 PM   in response to: futuredan in response to: futuredan
 
  Click to reply to this thread Reply
I suggest to test that each of the camel applications works independetly. For example kicking off a route using a timer endpoint. And make sure the properties resolver works.

Then you know that its when you send from one camel to another over VM that you have this problem. If thats the case then its most likely due to that bug I talked above before.