You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by kariem_hussein <ka...@users.sf.net> on 2009/02/15 14:05:19 UTC

Re: CXF doesn't respect annotations


bimargulies wrote:
> 
> CXF uses JAXB if you configure JAXB. If you configure Aegis, it uses
> Aegis. How are you configuring?
> 

I have a similar problem as the one reported by Maxime. CXF should use JAXB
by default [1], and according to the related stack trace, I believe it does
so:

## stack trace
Caused by: org.apache.cxf.interceptor.Fault: Marshalling Error: A cycle is
detected in the object graph. This will cause infinitely deep XML:
com.example.test.cxf.xmltransient.model.Parent@0 ->
com.example.test.cxf.xmltransient.model.Child@0 ->
com.example.test.cxf.xmltransient.model.Parent@0
	at
org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:159)
	at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:169)
	at
org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:104)
	at
org.apache.cxf.interceptor.BareOutInterceptor.handleMessage(BareOutInterceptor.java:68)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:226)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:469)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:299)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:251)
	at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
	at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124)
	... 25 more
##

I use CXF 2.1.4 and changed the bundled Spring libraries to 2.5.6. I have
filed an issue in JIRA and attached a test case:
   https://issues.apache.org/jira/browse/CXF-2041

There are similar issues and appropriate documentation, but I could not find
pointers to what I was doing wrong. The most informative links I have found
regarding this problem:

  https://issues.apache.org/jira/browse/CXF-1121 (apparently resolved in
2.0.3)
  https://jaxb.dev.java.net/guide/Mapping_cyclic_references_to_XML.html
  

I hope someone can help here.

Thank you,
Kariem  




[1] See first paragraph in
http://cwiki.apache.org/CXF20DOC/jaxb.html 
-- 
View this message in context: http://www.nabble.com/CXF-doesn%27t-respect-annotations-tp19894613p22022406.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: CXF doesn't respect annotations

Posted by "kariem@sf" <ka...@users.sf.net>.

bimargulies wrote:
> 
> I think that if you read any of the stock tutorials on JAXB, you'll
> see that this is made pretty clear.  They explain that JAXB infers
> elements from fields or from get/setters, as controlled by the
> annotations on the class. By default, those annotations do not examine
> anything private.
> 
> Look at the J2SE 6.0 javadoc for XmlAccessorType to see what I'm talking
> about.
> 

Thank you for this pointer. I agree with you after reading through the
documentation and trying things out. Just want to summarize this, because it
did not seem to be obvious or intuitive to me.

Actually the JAXB guide on how to map cyclic references [1] uses field-level
annotation. I acknowledge that the field in that example (Department on
class Employee) is not private, but I don't see any indication of
restrictions on the visibility scope level. I have tried annotating the
field in the test case attached to CXF-2041 with XmlTransient, and it does
not work, even if the field is not private (similar to the example in the
JAXB guide, but not working).

It does actually work, if the class or package is annotated with the
appropriate XmlAccessorType:

## start
@XmlAccessorType(XmlAccessType.FIELD) // added this annotation
public class Child extends EntityObject {

	@XmlTransient // now this annotation is not ignored anymore
	Parent parent;
	
	...
}
## end

I don't think there is any problem in the RI. I just needed to annotate the
classes correctly. 


Thank you for your efforts and explanations,
Kariem


[1] https://jaxb.dev.java.net/guide/Mapping_cyclic_references_to_XML.html


-- 
View this message in context: http://www.nabble.com/CXF-doesn%27t-respect-annotations-tp19894613p22029423.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: CXF doesn't respect annotations

Posted by Benson Margulies <bi...@gmail.com>.
I think that if you read any of the stock tutorials on JAXB, you'll
see that this is made pretty clear.  They explain that JAXB infers
elements from fields or from get/setters, as controlled by the
annotations on the class. By default, those annotations do not examine
anything private.

Look at the J2SE 6.0 javadoc for XmlAccessorType to see what I'm talking about.

On Sun, Feb 15, 2009 at 5:59 PM, kariem@sf <ka...@users.sf.net> wrote:
>
>
> bimargulies wrote:
> >
> > This is a bug in the Jaxb RI 2.1.9.
> >
>
> Fast and very good response, Beson. Thank you very much. Everything working
> now, thanks to your suggestion on the issue: putting the annotation on the
> setter method for the property made it work. I have updated the JIRA issue
> with a working test case.
>
> The problem is resolved, but I still have a bad feeling. Do you recommend
> filing a bug with JAXB (it should work on class field level)? Should we add
> something to the documentation for CXF? Or do you think the JIRA issue and
> the comments on this list are enough?
>
> Cheers,
> Kariem
>
> --
> View this message in context: http://www.nabble.com/CXF-doesn%27t-respect-annotations-tp19894613p22028908.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

Re: CXF doesn't respect annotations

Posted by "kariem@sf" <ka...@users.sf.net>.

bimargulies wrote:
> 
> This is a bug in the Jaxb RI 2.1.9.
> 

Fast and very good response, Beson. Thank you very much. Everything working
now, thanks to your suggestion on the issue: putting the annotation on the
setter method for the property made it work. I have updated the JIRA issue
with a working test case.

The problem is resolved, but I still have a bad feeling. Do you recommend
filing a bug with JAXB (it should work on class field level)? Should we add
something to the documentation for CXF? Or do you think the JIRA issue and
the comments on this list are enough?

Cheers,
Kariem

-- 
View this message in context: http://www.nabble.com/CXF-doesn%27t-respect-annotations-tp19894613p22028908.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: CXF doesn't respect annotations

Posted by Benson Margulies <bi...@gmail.com>.
This is a bug in the Jaxb RI 2.1.9.

On Sun, Feb 15, 2009 at 9:31 AM, Benson Margulies <bi...@gmail.com>wrote:

> Well, my first question will be whether you have found a bug in the JAXB
> reference implementation. I am trying to remember how to quickly investigate
> that, I think I have an idea which I will try (running their java-to-schema
> tool and see if it includes your wayward element).
>
>
> On Sun, Feb 15, 2009 at 8:58 AM, kariem@sf <ka...@users.sf.net> wrote:
>
>>
>>
>> bimargulies wrote:
>> >
>> > JAXB is the default. I can't tell if someone us using the default unless
>> I
>> > ask them, now, can I?
>> >
>>
>> My message was not intended to criticize your query. I just wanted to pick
>> up this old conversation from where it was left, and thought the right way
>> would be to answer to your question first. I am sorry, if my message
>> offended you.
>>
>> Now that we are sure that JAXB is used, at least in my scenario, does
>> anyone
>> see a problem in the described setup, or something I might have missed and
>> could share his/her experience or thoughts? Please also have a look at the
>> test project I have attached to the issue in JIRA
>>
>>  https://issues.apache.org/jira/browse/CXF-2041
>>
>> Thank you,
>> Kariem
>> --
>> View this message in context:
>> http://www.nabble.com/CXF-doesn%27t-respect-annotations-tp19894613p22022881.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
>>
>

Re: CXF doesn't respect annotations

Posted by Benson Margulies <bi...@gmail.com>.
Well, my first question will be whether you have found a bug in the JAXB
reference implementation. I am trying to remember how to quickly investigate
that, I think I have an idea which I will try (running their java-to-schema
tool and see if it includes your wayward element).

On Sun, Feb 15, 2009 at 8:58 AM, kariem@sf <ka...@users.sf.net> wrote:

>
>
> bimargulies wrote:
> >
> > JAXB is the default. I can't tell if someone us using the default unless
> I
> > ask them, now, can I?
> >
>
> My message was not intended to criticize your query. I just wanted to pick
> up this old conversation from where it was left, and thought the right way
> would be to answer to your question first. I am sorry, if my message
> offended you.
>
> Now that we are sure that JAXB is used, at least in my scenario, does
> anyone
> see a problem in the described setup, or something I might have missed and
> could share his/her experience or thoughts? Please also have a look at the
> test project I have attached to the issue in JIRA
>
>  https://issues.apache.org/jira/browse/CXF-2041
>
> Thank you,
> Kariem
> --
> View this message in context:
> http://www.nabble.com/CXF-doesn%27t-respect-annotations-tp19894613p22022881.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
>

Re: CXF doesn't respect annotations

Posted by "kariem@sf" <ka...@users.sf.net>.

bimargulies wrote:
> 
> JAXB is the default. I can't tell if someone us using the default unless I
> ask them, now, can I?
> 

My message was not intended to criticize your query. I just wanted to pick
up this old conversation from where it was left, and thought the right way
would be to answer to your question first. I am sorry, if my message
offended you.

Now that we are sure that JAXB is used, at least in my scenario, does anyone
see a problem in the described setup, or something I might have missed and
could share his/her experience or thoughts? Please also have a look at the
test project I have attached to the issue in JIRA

  https://issues.apache.org/jira/browse/CXF-2041

Thank you,
Kariem
-- 
View this message in context: http://www.nabble.com/CXF-doesn%27t-respect-annotations-tp19894613p22022881.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: CXF doesn't respect annotations

Posted by Benson Margulies <bi...@gmail.com>.
JAXB is the default. I can't tell if someone us using the default unless I
ask them, now, can I?

On Sun, Feb 15, 2009 at 8:05 AM, kariem_hussein <ka...@users.sf.net> wrote:

>
>
> bimargulies wrote:
> >
> > CXF uses JAXB if you configure JAXB. If you configure Aegis, it uses
> > Aegis. How are you configuring?
> >
>
> I have a similar problem as the one reported by Maxime. CXF should use JAXB
> by default [1], and according to the related stack trace, I believe it does
> so:
>
> ## stack trace
> Caused by: org.apache.cxf.interceptor.Fault: Marshalling Error: A cycle is
> detected in the object graph. This will cause infinitely deep XML:
> com.example.test.cxf.xmltransient.model.Parent@0 ->
> com.example.test.cxf.xmltransient.model.Child@0 ->
> com.example.test.cxf.xmltransient.model.Parent@0
>        at
>
> org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:159)
>        at
> org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:169)
>        at
>
> org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:104)
>        at
>
> org.apache.cxf.interceptor.BareOutInterceptor.handleMessage(BareOutInterceptor.java:68)
>        at
>
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:226)
>        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:469)
>        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:299)
>        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:251)
>        at
> org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
>        at
> org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124)
>        ... 25 more
> ##
>
> I use CXF 2.1.4 and changed the bundled Spring libraries to 2.5.6. I have
> filed an issue in JIRA and attached a test case:
>   https://issues.apache.org/jira/browse/CXF-2041
>
> There are similar issues and appropriate documentation, but I could not
> find
> pointers to what I was doing wrong. The most informative links I have found
> regarding this problem:
>
>  https://issues.apache.org/jira/browse/CXF-1121 (apparently resolved in
> 2.0.3)
>  https://jaxb.dev.java.net/guide/Mapping_cyclic_references_to_XML.html
>
>
> I hope someone can help here.
>
> Thank you,
> Kariem
>
>
>
>
> [1] See first paragraph in
> http://cwiki.apache.org/CXF20DOC/jaxb.html
> --
> View this message in context:
> http://www.nabble.com/CXF-doesn%27t-respect-annotations-tp19894613p22022406.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
>