You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by Benson Margulies <bi...@basistech.com> on 2007/11/25 17:05:36 UTC

JAXWS + JAXB + CXF's auto-wrapper feature

As of a few days ago, we had a defect in JAXB+JAXWS for generated
wrappers in the case where one or more params are of class type with
XmlRootElement annotations. The concreteName in the MessagePartInfo
didn't agree with the XmlSchema. The result was that generated
Javascript based on the schema made XML that was rejected by the
DocLitInterceptor, which looks at the parts.
 
I pushed them closer together, and then discovered a further question or
problem.
 
When JAX-WS has @WebParam(name = "foo") 
 
but the XmlRootElement has no name (but has a namespace), the code was
creating XML schema with ref= to the global element for the
XmlRootElement. Which, of course, had a completely different QName than
then part which derived from the @WebParam.
 
I then fiddled ReflectionServiceFactoryBean to generate schema based on
the @WebParam. Essentially, I made it ignore the @XmlRootElement in this
case and just create a local element based on the type.
 
That make my Javascript get along with the interceptor, and looked very
nice and symmetrical to me. However, it broke the JRA tests, which seem
to really badly want the other behavior. What really confused me was
that the JRA code ends up expecting one less level of element in the XML
altogether.
 
So, I think that the problem here is that I need to suppress the
'isElement' flag in the message part info for the ordinary
auto-generation case so that whatever floated JRA's boat still works.
 
 

Re: JAXWS + JAXB + CXF's auto-wrapper feature

Posted by Daniel Kulp <dk...@apache.org>.
On Friday 30 November 2007, Benson Margulies wrote:
> 1) So, this legitimatized my JIRA calling for preferring WebParam to
> XmlRootElement.
>
> 2) This sure is an argument for Bare. JAX-WS doesn't touch
> elementForm, so all these people who want to control the elementForm
> are going to stay sad.

Well, with 2.0.3, I threw in some config things on the RSFB to control 
this.   With spring config (or a custom subclass of RSFB or similar), 
you can get it to generate qualified schema.   See my comments in 
CXF-1144 and CXF-1226.  The default needs to stay unqualified for the 
TCK to pass, but it's at least now semi-controllable.

Dan



>
> > -----Original Message-----
> > From: Daniel Kulp [mailto:dkulp@apache.org]
> > Sent: Friday, November 30, 2007 1:13 PM
> > To: cxf-dev@incubator.apache.org
> > Cc: Benson Margulies
> > Subject: Re: JAXWS + JAXB + CXF's auto-wrapper feature
> >
> >
> > Just FYI:  the JAXWS spec specifically avoids any mention of
> > having XmlRootElement on beans for the java first case,
> > probably due to the
> > issues you are seeing.
> >
> > The spec REALLY want's all the top level element names and such to
> > be controlled with the JWS/JAXWS annotions and not the jaxb
> > annotations.
> > Thus, we need to use that information instead and more or
> > less ignore the XmlRootElement annotation when we can.
> >
> > If the type has a XmlRootElement and an XmlType with a name
> > attribute,
> > we're kind of OK as the type is non-anonymous and we can
> > point to it.
> > However, if the type has no name attribute, it does blow
> > things up pretty badly and is definitely outside the stuff
> > the JAX-WS tck would be testing.
> >
> > Dan
> >
> > On Sunday 25 November 2007, Benson Margulies wrote:
> > > I have a little more information on this to offer.
> > >
> > > Leaving the current schema generation alone, I end up with
> >
> > a complex
> >
> > > type containing two elements refs to the same element (one with
> > > maxOccurs and minOccurs).
> > >
> > > As an experiment, I fed this to wsdl2java, which told me
> >
> > that this was
> >
> > > very sad and encouraged me to 'apply a customization to fix the
> > > names'.
> > >
> > > Well, OK, then, that would seem to favor my theory that
> >
> > auto-generated
> >
> > > wrapper types should favor @WebParam names over XmlRootElement
> > > refs.
> >
> > --
> > J. Daniel Kulp
> > Principal Engineer
> > IONA
> > P: 781-902-8727    C: 508-380-7194
> > daniel.kulp@iona.com
> > http://www.dankulp.com/blog



-- 
J. Daniel Kulp
Principal Engineer
IONA
P: 781-902-8727    C: 508-380-7194
daniel.kulp@iona.com
http://www.dankulp.com/blog

RE: JAXWS + JAXB + CXF's auto-wrapper feature

Posted by Benson Margulies <bi...@basistech.com>.
Let's wait until you excavate your way to the JIRA I filed about
elementForm. It may amount to a case in which this stuff doesn't quite
work on the trunk, or it may be that this stuff is exactly the intended
answer and I just didn't use it. 

> -----Original Message-----
> From: Daniel Kulp [mailto:dkulp@apache.org] 
> Sent: Friday, November 30, 2007 1:50 PM
> To: cxf-dev@incubator.apache.org
> Cc: Benson Margulies
> Subject: Re: JAXWS + JAXB + CXF's auto-wrapper feature
> 
> On Friday 30 November 2007, Benson Margulies wrote:
> > 1) So, this legitimatized my JIRA calling for preferring 
> WebParam to 
> > XmlRootElement.
> >
> > 2) This sure is an argument for Bare. JAX-WS doesn't touch 
> > elementForm, so all these people who want to control the 
> elementForm 
> > are going to stay sad.
> 
> Actually, there are other ways to control it as well without 
> resorting to 
> Bare.   You can use handcoded @Request/@ResponseWrappers and throw a 
> package-info.java thing into the same package as the wrappers 
> to force 
> them into a Qualified schema.    I think with the targetNamespace on 
> @RequestWrapper, you may be able to set the elementname and 
> namespace to a namespace of the other JAXB types that have a 
> package-info thing as well without the actual creation of the 
> wrappers classes.  Thus, the 
> wrapper types would be generated into a schema that is set to 
> qualified.   
> 
> Dan
> 
> 
> 
> > > -----Original Message-----
> > > From: Daniel Kulp [mailto:dkulp@apache.org]
> > > Sent: Friday, November 30, 2007 1:13 PM
> > > To: cxf-dev@incubator.apache.org
> > > Cc: Benson Margulies
> > > Subject: Re: JAXWS + JAXB + CXF's auto-wrapper feature
> > >
> > >
> > > Just FYI:  the JAXWS spec specifically avoids any mention 
> of having 
> > > XmlRootElement on beans for the java first case, probably 
> due to the 
> > > issues you are seeing.
> > >
> > > The spec REALLY want's all the top level element names 
> and such to 
> > > be controlled with the JWS/JAXWS annotions and not the jaxb 
> > > annotations.
> > > Thus, we need to use that information instead and more or less 
> > > ignore the XmlRootElement annotation when we can.
> > >
> > > If the type has a XmlRootElement and an XmlType with a name 
> > > attribute, we're kind of OK as the type is non-anonymous 
> and we can 
> > > point to it.
> > > However, if the type has no name attribute, it does blow 
> things up 
> > > pretty badly and is definitely outside the stuff the JAX-WS tck 
> > > would be testing.
> > >
> > > Dan
> > >
> > > On Sunday 25 November 2007, Benson Margulies wrote:
> > > > I have a little more information on this to offer.
> > > >
> > > > Leaving the current schema generation alone, I end up with
> > >
> > > a complex
> > >
> > > > type containing two elements refs to the same element (one with 
> > > > maxOccurs and minOccurs).
> > > >
> > > > As an experiment, I fed this to wsdl2java, which told me
> > >
> > > that this was
> > >
> > > > very sad and encouraged me to 'apply a customization to fix the 
> > > > names'.
> > > >
> > > > Well, OK, then, that would seem to favor my theory that
> > >
> > > auto-generated
> > >
> > > > wrapper types should favor @WebParam names over XmlRootElement 
> > > > refs.
> > >
> > > --
> > > J. Daniel Kulp
> > > Principal Engineer
> > > IONA
> > > P: 781-902-8727    C: 508-380-7194
> > > daniel.kulp@iona.com
> > > http://www.dankulp.com/blog
> 
> 
> 
> --
> J. Daniel Kulp
> Principal Engineer
> IONA
> P: 781-902-8727    C: 508-380-7194
> daniel.kulp@iona.com
> http://www.dankulp.com/blog
> 

Re: JAXWS + JAXB + CXF's auto-wrapper feature

Posted by Daniel Kulp <dk...@apache.org>.
On Friday 30 November 2007, Benson Margulies wrote:
> 1) So, this legitimatized my JIRA calling for preferring WebParam to
> XmlRootElement.
>
> 2) This sure is an argument for Bare. JAX-WS doesn't touch
> elementForm, so all these people who want to control the elementForm
> are going to stay sad.

Actually, there are other ways to control it as well without resorting to 
Bare.   You can use handcoded @Request/@ResponseWrappers and throw a 
package-info.java thing into the same package as the wrappers to force 
them into a Qualified schema.    I think with the targetNamespace on 
@RequestWrapper, you may be able to set the elementname and namespace to 
a namespace of the other JAXB types that have a package-info thing as 
well without the actual creation of the wrappers classes.  Thus, the 
wrapper types would be generated into a schema that is set to qualified.   

Dan



> > -----Original Message-----
> > From: Daniel Kulp [mailto:dkulp@apache.org]
> > Sent: Friday, November 30, 2007 1:13 PM
> > To: cxf-dev@incubator.apache.org
> > Cc: Benson Margulies
> > Subject: Re: JAXWS + JAXB + CXF's auto-wrapper feature
> >
> >
> > Just FYI:  the JAXWS spec specifically avoids any mention of
> > having XmlRootElement on beans for the java first case,
> > probably due to the
> > issues you are seeing.
> >
> > The spec REALLY want's all the top level element names and such to
> > be controlled with the JWS/JAXWS annotions and not the jaxb
> > annotations.
> > Thus, we need to use that information instead and more or
> > less ignore the XmlRootElement annotation when we can.
> >
> > If the type has a XmlRootElement and an XmlType with a name
> > attribute,
> > we're kind of OK as the type is non-anonymous and we can
> > point to it.
> > However, if the type has no name attribute, it does blow
> > things up pretty badly and is definitely outside the stuff
> > the JAX-WS tck would be testing.
> >
> > Dan
> >
> > On Sunday 25 November 2007, Benson Margulies wrote:
> > > I have a little more information on this to offer.
> > >
> > > Leaving the current schema generation alone, I end up with
> >
> > a complex
> >
> > > type containing two elements refs to the same element (one with
> > > maxOccurs and minOccurs).
> > >
> > > As an experiment, I fed this to wsdl2java, which told me
> >
> > that this was
> >
> > > very sad and encouraged me to 'apply a customization to fix the
> > > names'.
> > >
> > > Well, OK, then, that would seem to favor my theory that
> >
> > auto-generated
> >
> > > wrapper types should favor @WebParam names over XmlRootElement
> > > refs.
> >
> > --
> > J. Daniel Kulp
> > Principal Engineer
> > IONA
> > P: 781-902-8727    C: 508-380-7194
> > daniel.kulp@iona.com
> > http://www.dankulp.com/blog



-- 
J. Daniel Kulp
Principal Engineer
IONA
P: 781-902-8727    C: 508-380-7194
daniel.kulp@iona.com
http://www.dankulp.com/blog

RE: JAXWS + JAXB + CXF's auto-wrapper feature

Posted by Benson Margulies <bi...@basistech.com>.
1) So, this legitimatized my JIRA calling for preferring WebParam to
XmlRootElement.

2) This sure is an argument for Bare. JAX-WS doesn't touch elementForm,
so all these people who want to control the elementForm are going to
stay sad.

> -----Original Message-----
> From: Daniel Kulp [mailto:dkulp@apache.org] 
> Sent: Friday, November 30, 2007 1:13 PM
> To: cxf-dev@incubator.apache.org
> Cc: Benson Margulies
> Subject: Re: JAXWS + JAXB + CXF's auto-wrapper feature
> 
> 
> Just FYI:  the JAXWS spec specifically avoids any mention of 
> having XmlRootElement on beans for the java first case, 
> probably due to the 
> issues you are seeing.   
> 
> The spec REALLY want's all the top level element names and such to be 
> controlled with the JWS/JAXWS annotions and not the jaxb 
> annotations.   
> Thus, we need to use that information instead and more or 
> less ignore the XmlRootElement annotation when we can.  
> 
> If the type has a XmlRootElement and an XmlType with a name 
> attribute, 
> we're kind of OK as the type is non-anonymous and we can 
> point to it.   
> However, if the type has no name attribute, it does blow 
> things up pretty badly and is definitely outside the stuff 
> the JAX-WS tck would be testing.
> 
> Dan
> 
> 
> On Sunday 25 November 2007, Benson Margulies wrote:
> > I have a little more information on this to offer.
> >
> > Leaving the current schema generation alone, I end up with 
> a complex 
> > type containing two elements refs to the same element (one with 
> > maxOccurs and minOccurs).
> >
> > As an experiment, I fed this to wsdl2java, which told me 
> that this was 
> > very sad and encouraged me to 'apply a customization to fix the 
> > names'.
> >
> > Well, OK, then, that would seem to favor my theory that 
> auto-generated 
> > wrapper types should favor @WebParam names over XmlRootElement refs.
> 
> 
> 
> --
> J. Daniel Kulp
> Principal Engineer
> IONA
> P: 781-902-8727    C: 508-380-7194
> daniel.kulp@iona.com
> http://www.dankulp.com/blog
> 

Re: JAXWS + JAXB + CXF's auto-wrapper feature

Posted by Daniel Kulp <dk...@apache.org>.
Just FYI:  the JAXWS spec specifically avoids any mention of having 
XmlRootElement on beans for the java first case, probably due to the 
issues you are seeing.   

The spec REALLY want's all the top level element names and such to be 
controlled with the JWS/JAXWS annotions and not the jaxb annotations.   
Thus, we need to use that information instead and more or less ignore 
the XmlRootElement annotation when we can.  

If the type has a XmlRootElement and an XmlType with a name attribute, 
we're kind of OK as the type is non-anonymous and we can point to it.   
However, if the type has no name attribute, it does blow things up 
pretty badly and is definitely outside the stuff the JAX-WS tck would be 
testing.

Dan


On Sunday 25 November 2007, Benson Margulies wrote:
> I have a little more information on this to offer.
>
> Leaving the current schema generation alone, I end up with a complex
> type containing two elements refs to the same element (one with
> maxOccurs and minOccurs).
>
> As an experiment, I fed this to wsdl2java, which told me that this was
> very sad and encouraged me to 'apply a customization to fix the
> names'.
>
> Well, OK, then, that would seem to favor my theory that auto-generated
> wrapper types should favor @WebParam names over XmlRootElement refs.



-- 
J. Daniel Kulp
Principal Engineer
IONA
P: 781-902-8727    C: 508-380-7194
daniel.kulp@iona.com
http://www.dankulp.com/blog

RE: JAXWS + JAXB + CXF's auto-wrapper feature

Posted by Benson Margulies <bi...@basistech.com>.
I have a little more information on this to offer.

Leaving the current schema generation alone, I end up with a complex
type containing two elements refs to the same element (one with
maxOccurs and minOccurs).

As an experiment, I fed this to wsdl2java, which told me that this was
very sad and encouraged me to 'apply a customization to fix the names'.

Well, OK, then, that would seem to favor my theory that auto-generated
wrapper types should favor @WebParam names over XmlRootElement refs.