You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Charles Moulliard <ch...@gmail.com> on 2013/01/10 11:29:07 UTC

Question camel cxf & CXF_MESSAGE

Hi,

Why do I get this cast error message using CXF_MESSAGE as dataformat for my
camel cxf endpoint

Here is the SOAP enveloppe created by camel using SOAP Dataformat

qtp521246104-20 INFO [cxf-to-client] - >>> Response generated : <?xml
version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:Envelope xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns3="http://training.fusesource.com/">
    <ns2:Body>
        <ns3:getCustomerByNameResponse>
            <return>
                <name>Fuse</name>
                <address>FuseSource Office</address>
                <numOrders>38</numOrders>
                <revenue>7179.0</revenue>
                <test>100.0</test>
                <type>BUSINESS</type>
            </return>
        </ns3:getCustomerByNameResponse>
    </ns2:Body>
</ns2:Envelope>

But camel generates this error during call
of org.apache.camel.component.cxf.DefaultCxfBinding.populateCxfResponseFromExchange(DefaultCxfBinding.java:344)

qtp521246104-20 WARN [org.apache.cxf.phase.PhaseInterceptorChain] -
Interceptor for {
http://training.fusesource.com/}CustomerServiceService#{http://training.fusesource.com/}getCustomerByNamehas
thrown exception, unwinding now
java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;
at
org.apache.camel.component.cxf.DefaultCxfBinding.populateCxfResponseFromExchange(DefaultCxfBinding.java:344)
at
org.apache.camel.component.cxf.CxfConsumer$1.setResponseBack(CxfConsumer.java:180)
at
org.apache.camel.component.cxf.CxfConsumer$1.asyncInvoke(CxfConsumer.java:107)
at org.apache.camel.component.cxf.CxfConsumer$1.invoke(CxfConsumer.java:72)

Regards,

-- 
Charles Moulliard
Apache Committer / Sr. Enterprise Architect (RedHat)
Twitter : @cmoulliard | Blog : http://cmoulliard.blogspot.com

Re: Question camel cxf & CXF_MESSAGE

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Jan 10, 2013 at 12:24 PM, Charles Moulliard <ch...@gmail.com> wrote:
> Should we raise a ticket to solve this issue ?
>

Yeah the class cast exception should not happen. Its a bug in camel-cxf.


>
> On Thu, Jan 10, 2013 at 12:04 PM, Claus Ibsen <cl...@gmail.com> wrote:
>
>> On Thu, Jan 10, 2013 at 11:54 AM, Babak Vahdat
>> <ba...@swissonline.ch> wrote:
>> > Hi
>> >
>> > Don't know much about CXF itself but this is more than obvious as the
>> code
>> > (DefaultCxfBinding line 344) is buggy because one can not simply cast an
>> > array of *primitive* type ("[B" means array of byte) to Object[] which
>> is an
>> > array of *reference* type!
>> >
>> > You would get the same stack trace if you would try to run the crappy
>> code
>> > below:
>> >
>> >     public static void main(String[] args) {
>> >         byte[] bytes = new byte[] {3, 4};
>> >
>> >         if (bytes.getClass().isArray()) {
>> >             System.out.println("yes it's an array BUT of the primitive
>> > type!");
>> >             Object array = bytes;
>> >             Object[] casted = (Object[]) array; // BOOM
>> >         }
>> >     }
>> >
>>
>> Yes there is some code in ObjectHelper or one of the helper/util
>> classes in the util package
>> that can check for array and primitives.
>>
>> And better yet there is an iterator that can deal with that too.
>> So can can more safely grab the data.
>>
>>
>> > Babak
>> >
>> >
>> >
>> >
>> > --
>> > View this message in context:
>> http://camel.465427.n5.nabble.com/Question-camel-cxf-CXF-MESSAGE-tp5725227p5725230.html
>> > Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> FuseSource is now part of Red Hat
>> Email: cibsen@redhat.com
>> Web: http://fusesource.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>>
>
>
>
> --
> Charles Moulliard
> Apache Committer / Sr. Enterprise Architect (RedHat)
> Twitter : @cmoulliard | Blog : http://cmoulliard.blogspot.com



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Question camel cxf & CXF_MESSAGE

Posted by Charles Moulliard <ch...@gmail.com>.
Should we raise a ticket to solve this issue ?


On Thu, Jan 10, 2013 at 12:04 PM, Claus Ibsen <cl...@gmail.com> wrote:

> On Thu, Jan 10, 2013 at 11:54 AM, Babak Vahdat
> <ba...@swissonline.ch> wrote:
> > Hi
> >
> > Don't know much about CXF itself but this is more than obvious as the
> code
> > (DefaultCxfBinding line 344) is buggy because one can not simply cast an
> > array of *primitive* type ("[B" means array of byte) to Object[] which
> is an
> > array of *reference* type!
> >
> > You would get the same stack trace if you would try to run the crappy
> code
> > below:
> >
> >     public static void main(String[] args) {
> >         byte[] bytes = new byte[] {3, 4};
> >
> >         if (bytes.getClass().isArray()) {
> >             System.out.println("yes it's an array BUT of the primitive
> > type!");
> >             Object array = bytes;
> >             Object[] casted = (Object[]) array; // BOOM
> >         }
> >     }
> >
>
> Yes there is some code in ObjectHelper or one of the helper/util
> classes in the util package
> that can check for array and primitives.
>
> And better yet there is an iterator that can deal with that too.
> So can can more safely grab the data.
>
>
> > Babak
> >
> >
> >
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/Question-camel-cxf-CXF-MESSAGE-tp5725227p5725230.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: cibsen@redhat.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>



-- 
Charles Moulliard
Apache Committer / Sr. Enterprise Architect (RedHat)
Twitter : @cmoulliard | Blog : http://cmoulliard.blogspot.com

Re: Question camel cxf & CXF_MESSAGE

Posted by Babak Vahdat <ba...@swissonline.ch>.
I logged a ticket for ObjectHelper:

https://issues.apache.org/jira/browse/CAMEL-5948

Babak


Babak Vahdat wrote
> Claus
> 
> unfortunatly the iterator being returned there has got exactly the same
> bug marked with a TODO!
> 
> See ObjectHelper lines 516..519
> 
>         } else if (value.getClass().isArray()) {
>             // TODO we should handle primitive array types?
>             List

>  list = Arrays.asList((Object[])value);
>             return list.iterator();
> 
> IMHO a possible solution would be to grap into the array content (e.g.
> array[0] if it's size > 0) and check for e.g.:
> 
>   (array[0] != null && array[0].getClass().isPrimitive())
> 
> Or something like that, e.g. byte.class.isPrimitive() returns true.
> 
> Babak
> Claus Ibsen-2 wrote
>> On Thu, Jan 10, 2013 at 11:54 AM, Babak Vahdat
>> &lt;

>> babak.vahdat@

>> &gt; wrote:
>>> Hi
>>>
>>> Don't know much about CXF itself but this is more than obvious as the
>>> code
>>> (DefaultCxfBinding line 344) is buggy because one can not simply cast an
>>> array of *primitive* type ("[B" means array of byte) to Object[] which
>>> is an
>>> array of *reference* type!
>>>
>>> You would get the same stack trace if you would try to run the crappy
>>> code
>>> below:
>>>
>>>     public static void main(String[] args) {
>>>         byte[] bytes = new byte[] {3, 4};
>>>
>>>         if (bytes.getClass().isArray()) {
>>>             System.out.println("yes it's an array BUT of the primitive
>>> type!");
>>>             Object array = bytes;
>>>             Object[] casted = (Object[]) array; // BOOM
>>>         }
>>>     }
>>>
>> 
>> Yes there is some code in ObjectHelper or one of the helper/util
>> classes in the util package
>> that can check for array and primitives.
>> 
>> And better yet there is an iterator that can deal with that too.
>> So can can more safely grab the data.
>> 
>> 
>>> Babak
>>>
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://camel.465427.n5.nabble.com/Question-camel-cxf-CXF-MESSAGE-tp5725227p5725230.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>> 
>> 
>> 
>> -- 
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> FuseSource is now part of Red Hat
>> Email: 

>> cibsen@

>> Web: http://fusesource.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen





--
View this message in context: http://camel.465427.n5.nabble.com/Question-camel-cxf-CXF-MESSAGE-tp5725227p5725251.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Question camel cxf & CXF_MESSAGE

Posted by Babak Vahdat <ba...@swissonline.ch>.
Claus

unfortunatly the iterator being returned there has got exactly the same bug
marked with a TODO!

See ObjectHelper lines 516..519

        } else if (value.getClass().isArray()) {
            // TODO we should handle primitive array types?
            List list = Arrays.asList((Object[])value);
            return list.iterator();

IMHO a possible solution would be to grap into the array content (e.g.
array[0] if it's size > 0) and check for e.g.:

  (array[0] != null && array[0].getClass().isPrimitive())

Or something like that, e.g. byte.class.isPrimitive() returns true.

Babak


Claus Ibsen-2 wrote
> On Thu, Jan 10, 2013 at 11:54 AM, Babak Vahdat
> &lt;

> babak.vahdat@

> &gt; wrote:
>> Hi
>>
>> Don't know much about CXF itself but this is more than obvious as the
>> code
>> (DefaultCxfBinding line 344) is buggy because one can not simply cast an
>> array of *primitive* type ("[B" means array of byte) to Object[] which is
>> an
>> array of *reference* type!
>>
>> You would get the same stack trace if you would try to run the crappy
>> code
>> below:
>>
>>     public static void main(String[] args) {
>>         byte[] bytes = new byte[] {3, 4};
>>
>>         if (bytes.getClass().isArray()) {
>>             System.out.println("yes it's an array BUT of the primitive
>> type!");
>>             Object array = bytes;
>>             Object[] casted = (Object[]) array; // BOOM
>>         }
>>     }
>>
> 
> Yes there is some code in ObjectHelper or one of the helper/util
> classes in the util package
> that can check for array and primitives.
> 
> And better yet there is an iterator that can deal with that too.
> So can can more safely grab the data.
> 
> 
>> Babak
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Question-camel-cxf-CXF-MESSAGE-tp5725227p5725230.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: 

> cibsen@

> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen





--
View this message in context: http://camel.465427.n5.nabble.com/Question-camel-cxf-CXF-MESSAGE-tp5725227p5725245.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Question camel cxf & CXF_MESSAGE

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Jan 10, 2013 at 11:54 AM, Babak Vahdat
<ba...@swissonline.ch> wrote:
> Hi
>
> Don't know much about CXF itself but this is more than obvious as the code
> (DefaultCxfBinding line 344) is buggy because one can not simply cast an
> array of *primitive* type ("[B" means array of byte) to Object[] which is an
> array of *reference* type!
>
> You would get the same stack trace if you would try to run the crappy code
> below:
>
>     public static void main(String[] args) {
>         byte[] bytes = new byte[] {3, 4};
>
>         if (bytes.getClass().isArray()) {
>             System.out.println("yes it's an array BUT of the primitive
> type!");
>             Object array = bytes;
>             Object[] casted = (Object[]) array; // BOOM
>         }
>     }
>

Yes there is some code in ObjectHelper or one of the helper/util
classes in the util package
that can check for array and primitives.

And better yet there is an iterator that can deal with that too.
So can can more safely grab the data.


> Babak
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Question-camel-cxf-CXF-MESSAGE-tp5725227p5725230.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Question camel cxf & CXF_MESSAGE

Posted by Babak Vahdat <ba...@swissonline.ch>.
Hi

Don't know much about CXF itself but this is more than obvious as the code
(DefaultCxfBinding line 344) is buggy because one can not simply cast an
array of *primitive* type ("[B" means array of byte) to Object[] which is an
array of *reference* type!

You would get the same stack trace if you would try to run the crappy code
below: 

    public static void main(String[] args) {
        byte[] bytes = new byte[] {3, 4};
        
        if (bytes.getClass().isArray()) {
            System.out.println("yes it's an array BUT of the primitive
type!");
            Object array = bytes;
            Object[] casted = (Object[]) array; // BOOM
        }
    }
    
Babak




--
View this message in context: http://camel.465427.n5.nabble.com/Question-camel-cxf-CXF-MESSAGE-tp5725227p5725230.html
Sent from the Camel - Users mailing list archive at Nabble.com.