You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by cgiera <ch...@mic-cust.com> on 2012/05/09 09:46:26 UTC

Re: ClassCastException using cxf:bean

cgiera wrote
> 
> 
> I've looked for some more information in the camel-users forum and I've
> found the following:
> http://camel.465427.n5.nabble.com/Bean-component-BeanInfo-thread-safety-td3387197.html
> 
> 

Also the changes of the MethodInfo class in CAMEL-3670 doesn't solve the
problem.

--
View this message in context: http://camel.465427.n5.nabble.com/ClassCastException-using-cxf-bean-tp5599810p5696698.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ClassCastException using cxf:bean

Posted by Willem Jiang <wi...@gmail.com>.
Just FYI, I logged a JIRA[1] and committed the patch into camel.

[1] https://issues.apache.org/jira/browse/CAMEL-5468

On Thu, Jul 26, 2012 at 5:41 AM, Christian Müller
<ch...@gmail.com> wrote:
> Cool you could resolve the issue by yourself.
>
> Best,
> Christian
>
> On Wed, Jul 25, 2012 at 1:10 PM, cgiera <ch...@mic-cust.com>wrote:
>
>> I've added the synchronized modifier to the RegistryBean.getBean() method
>> and
>> the problem is fixed for now.
>> Hopefully I can upgrade to a newer version of camel in the near future.
>>
>> kind regards,
>> Christoph
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/ClassCastException-using-cxf-bean-tp5599810p5716454.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>

Re: ClassCastException using cxf:bean

Posted by Christian Müller <ch...@gmail.com>.
Cool you could resolve the issue by yourself.

Best,
Christian

On Wed, Jul 25, 2012 at 1:10 PM, cgiera <ch...@mic-cust.com>wrote:

> I've added the synchronized modifier to the RegistryBean.getBean() method
> and
> the problem is fixed for now.
> Hopefully I can upgrade to a newer version of camel in the near future.
>
> kind regards,
> Christoph
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/ClassCastException-using-cxf-bean-tp5599810p5716454.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: ClassCastException using cxf:bean

Posted by cgiera <ch...@mic-cust.com>.
I've added the synchronized modifier to the RegistryBean.getBean() method and
the problem is fixed for now.
Hopefully I can upgrade to a newer version of camel in the near future.

kind regards,
Christoph



--
View this message in context: http://camel.465427.n5.nabble.com/ClassCastException-using-cxf-bean-tp5599810p5716454.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ClassCastException using cxf:bean

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, May 29, 2012 at 3:17 PM, cgiera <ch...@mic-cust.com> wrote:
>
> Claus Ibsen-2 wrote
>>
>> On Tue, May 29, 2012 at 2:44 PM, cgiera &lt;christoph.giera@&gt; wrote:
>>
>> You use an old version of Camel. You can upgrade to have this fixed.
>>
>>
>> When Camel start the routes it initializes the resources and thus also
>> bean / beanRef, where it will setup this logic.
>> That logic runs single threaded.
>>
>>
>
> The problem is that in some cases we are not allowed to use java 6. So camel
> 2.6.0 is the latest version we could use.
>
> Can you tell me which jira issue(s) would fix this problem so I could patch
> camel 2.6.0 by myself?
>

No, there is many JIRA tickets.

Just fix the code yourself if you want to go down that path.

Or get in touch with one of the commercial vendors of Camel. They
support the older releases much longer than what ASF does.
The last supported release currently at ASF is the 2.8.x releases.


> kind regards,
> Christoph
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/ClassCastException-using-cxf-bean-tp5599810p5713688.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: ClassCastException using cxf:bean

Posted by cgiera <ch...@mic-cust.com>.
Claus Ibsen-2 wrote
> 
> On Tue, May 29, 2012 at 2:44 PM, cgiera &lt;christoph.giera@&gt; wrote:
> 
> You use an old version of Camel. You can upgrade to have this fixed.
> 
> 
> When Camel start the routes it initializes the resources and thus also
> bean / beanRef, where it will setup this logic.
> That logic runs single threaded.
> 
> 

The problem is that in some cases we are not allowed to use java 6. So camel
2.6.0 is the latest version we could use.

Can you tell me which jira issue(s) would fix this problem so I could patch
camel 2.6.0 by myself?

kind regards,
Christoph

--
View this message in context: http://camel.465427.n5.nabble.com/ClassCastException-using-cxf-bean-tp5599810p5713688.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ClassCastException using cxf:bean

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, May 29, 2012 at 2:44 PM, cgiera <ch...@mic-cust.com> wrote:
>
> Claus Ibsen-2 wrote
>>
>> When using .bean in the DSL, then the bean is looked up / created once
>> / etc when the route is being initialized / started.
>> And thus there is no thread safe issue at runtime, as the beans is
>> already created.
>>
>> When using bean with a class type, the bean is created once (eg
>> singleton scope).
>> And that is by design.
>>
>> If you want prototype scope or something like that, then use a beanRef
>> and refer to a bean in a bean container that supports that such as
>> spring etc.
>>
>>
> Yes, I use beanRef, but when I use the cxf-Endpoint I still have multi
> threading problems. The method RegistryBean.getBean() is - as i mentioned
> above - not thread safe I think.
>
> Do you agree with that, or is something wrong with my assumptions?
>

You use an old version of Camel. You can upgrade to have this fixed.


When Camel start the routes it initializes the resources and thus also
bean / beanRef, where it will setup this logic.
That logic runs single threaded.



> kind regards,
> Christoph
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/ClassCastException-using-cxf-bean-tp5599810p5713678.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: ClassCastException using cxf:bean

Posted by cgiera <ch...@mic-cust.com>.
Claus Ibsen-2 wrote
> 
> When using .bean in the DSL, then the bean is looked up / created once
> / etc when the route is being initialized / started.
> And thus there is no thread safe issue at runtime, as the beans is
> already created.
> 
> When using bean with a class type, the bean is created once (eg
> singleton scope).
> And that is by design.
> 
> If you want prototype scope or something like that, then use a beanRef
> and refer to a bean in a bean container that supports that such as
> spring etc.
> 
> 
Yes, I use beanRef, but when I use the cxf-Endpoint I still have multi
threading problems. The method RegistryBean.getBean() is - as i mentioned
above - not thread safe I think.

Do you agree with that, or is something wrong with my assumptions?

kind regards,
Christoph

--
View this message in context: http://camel.465427.n5.nabble.com/ClassCastException-using-cxf-bean-tp5599810p5713678.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ClassCastException using cxf:bean

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, May 22, 2012 at 9:58 AM, cgiera <ch...@mic-cust.com> wrote:
>
> Willem.Jiang wrote
>>
>> What's the problem ?
>> I don't think passing the bean object instance will introduce any
>> further issue into camel-jms and camel-jpa components.
>>
>
> Perhaps I don't understand you correctly, but if i pass the object instance
> like
>
> I get problems with our whole implementation because the beans are only
> instantiated once.
>
> kind regards,
> Christoph
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/ClassCastException-using-cxf-bean-tp5599810p5713307.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

When using .bean in the DSL, then the bean is looked up / created once
/ etc when the route is being initialized / started.
And thus there is no thread safe issue at runtime, as the beans is
already created.

When using bean with a class type, the bean is created once (eg
singleton scope).
And that is by design.

If you want prototype scope or something like that, then use a beanRef
and refer to a bean in a bean container that supports that such as
spring etc.


-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: ClassCastException using cxf:bean

Posted by cgiera <ch...@mic-cust.com>.
Willem.Jiang wrote
> 
> What's the problem ?
> I don't think passing the bean object instance will introduce any 
> further issue into camel-jms and camel-jpa components.
> 

Perhaps I don't understand you correctly, but if i pass the object instance
like

I get problems with our whole implementation because the beans are only
instantiated once.

kind regards,
Christoph

--
View this message in context: http://camel.465427.n5.nabble.com/ClassCastException-using-cxf-bean-tp5599810p5713307.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ClassCastException using cxf:bean

Posted by Willem Jiang <wi...@gmail.com>.
On Wed May 16 16:29:04 2012, cgiera wrote:
>
> cgiera wrote
>>
>>
>> Willem.Jiang wrote
>>>
>>> BTW the bean DSL support to pass the object, can you use the Object
>>> instead of the Class?
>>>
>>
>> I'll give this a try and let you know. Would be nice if this works.
>>
>> kind regards,
>> Christoph
>>
>
> I have tried it. Now I don't get ClassCastExceptions but I have new problems
> with jms and jpa. So it isn't a solution for me.

What's the problem ?
I don't think passing the bean object instance will introduce any 
further issue into camel-jms and camel-jpa components.

>
> kind regards,
> Christoph
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/ClassCastException-using-cxf-bean-tp5599810p5710615.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--
Willem
----------------------------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
         http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang


Re: ClassCastException using cxf:bean

Posted by cgiera <ch...@mic-cust.com>.
cgiera wrote
> 
> 
> Willem.Jiang wrote
>> 
>> BTW the bean DSL support to pass the object, can you use the Object
>> instead of the Class? 
>> 
> 
> I'll give this a try and let you know. Would be nice if this works.
> 
> kind regards,
> Christoph
> 

I have tried it. Now I don't get ClassCastExceptions but I have new problems
with jms and jpa. So it isn't a solution for me.

kind regards,
Christoph

--
View this message in context: http://camel.465427.n5.nabble.com/ClassCastException-using-cxf-bean-tp5599810p5710615.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ClassCastException using cxf:bean

Posted by cgiera <ch...@mic-cust.com>.
Willem.Jiang wrote
> 
> The bean method should be thread safe, as the method will be called 
> from different thread.
> 
The getBean() method is not thread safe:

Just try it out:



You need 2 breakpoints in this method:
1. breakpoint at last if in line value = bean
2. breakpoint at line bean = valeu

First disable the 2nd breakpoint and start a request so that debugging stops
at first breakpoint.
The value is a class and the bean is the instance, like it should be.

Now enable 2nd breakpoint ans start a second request so that debugging stops
at second breakpoint.
Step over the bean = value assignement
In this thread bean and value are classes now.

In the first request the bean has changed to a class, and if you continue
you will get the Classcastexception.


Willem.Jiang wrote
> 
> BTW the bean DSL support to pass the object, can you use the Object
> instead of the Class? 
> 

I'll give this a try and let you know. Would be nice if this works.

kind regards,
Christoph



--
View this message in context: http://camel.465427.n5.nabble.com/ClassCastException-using-cxf-bean-tp5599810p5709841.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ClassCastException using cxf:bean

Posted by Willem Jiang <wi...@gmail.com>.
The bean method should be thread safe, as the method will be called 
from different thread.
BTW the bean DSL support to pass the object, can you use the Object 
instead of the Class?

On Thu May 10 17:12:22 2012, cgiera wrote:
> I think I have found the problem:
> The RegistryBean.getBean() method is not thread safe:
>
>
> When I was debugging this method i notized that the bean member variable
> changes every now and then. I think this happens because another thread
> changes the member.
>
> In the last if block of the me method I think the following could happen:
>
> The bean member could also be a class, in this case the method tries to get
> an instance of this class.
> There is one problem in the line value=bean:
> What if another thread changes the bean to a class in just this moment?
> A class will be returned instead of an object, and so I get my
> ClassCastException later when camel tries to execute methods on the class
> instead of the object.
>
> Could someone check if the assumptions i made are correct?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/ClassCastException-using-cxf-bean-tp5599810p5699619.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--
Willem
----------------------------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
         http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang


Re: ClassCastException using cxf:bean

Posted by cgiera <ch...@mic-cust.com>.
I think I have found the problem:
The RegistryBean.getBean() method is not thread safe:


When I was debugging this method i notized that the bean member variable
changes every now and then. I think this happens because another thread
changes the member.

In the last if block of the me method I think the following could happen:

The bean member could also be a class, in this case the method tries to get
an instance of this class.
There is one problem in the line value=bean:
What if another thread changes the bean to a class in just this moment?
A class will be returned instead of an object, and so I get my
ClassCastException later when camel tries to execute methods on the class
instead of the object.

Could someone check if the assumptions i made are correct?

 

--
View this message in context: http://camel.465427.n5.nabble.com/ClassCastException-using-cxf-bean-tp5599810p5699619.html
Sent from the Camel - Users mailing list archive at Nabble.com.