You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Anthony Webster <aw...@gmail.com> on 2011/07/20 18:51:22 UTC

WSDL2JAVA results in JAXBElements everywhere...

Hi,

I have generated a webservice using wsdl2java and it all works fine. The
problem is that I'm exchanging PersonEndPoint objects and wsdl2java has set
all the properties to JAXBElement<...> (usually Strings). This makes
manipulating the objects received on the server side rather painful. So
instead of

Person person = new Person();
person.setName("Bob");

I have to go through

ObjectFactory of = new ObjectFactory();
PersonEndPoint person = of.createPersonEndPoint();
person.setFirstName(of.createPersonEndPointFirstName("Bob"));

Seems strange. Am I doing something wrong?

Many Thanks,

Anthony

Re: WSDL2JAVA results in JAXBElements everywhere...

Posted by Daniel Kulp <dk...@apache.org>.
 

There are a variety of constructs that do it.   Using substitution groups 
sometimes does it.  If you have elements that are BOTH nillable and 
minOccurs=0, that will also do it. (that's likely the most common)  Other 
things like:

       <xs:choice>
		<xs:sequence>
			<xs:element name="a" type="xs:int" />
			<xs:element name="b" type="xs:int" />
		</xs:sequence>
		<xs:sequence>
			<xs:element name="b" type="xs:int" />
			<xs:element name="c" type="xs:int" />
		</xs:sequence>
	</xs:choice>

(element "b" is in a couple sequences) will do it.   Etc.... 

In SOME cases, you can try the JAXB simple binding:

http://jaxb.java.net/2.1.2/docs/vendorCustomizations.html#simple

that sometimes will simplify things.


Dan




On Thursday, July 21, 2011 2:15:17 PM Anthony Webster wrote:
> Does anyone know what determines whether wsdl2java translates a
> complexType's element to an @XmlElementRef annotated JAXBElement<String> or
> an @XmlElement annotated String?
> 
> I was using Eclipse's WSDL editor to make a simple service project to
> illustrate another problem I've been having (duplicating @Policies in
> generated WSDLs). When I put this simple wsdl through SoapUI (which uses
> cxf's wsdl2java) in order to generate stubs etc.. it generated @XmlElement
> annotations for Strings whereas doing exactly the same with my client's WSDL
> results in @XmlElementRef JAXBElement<String> thus requiring an
> @XmlRegistry...
> 
> Any help would be most appreciated.
> 
> Many Thanks,
> 
> Anthony
> 
> On 21 July 2011 10:01, Anthony Webster <aw...@gmail.com> wrote:
> > Sorry I don't quite follow. You're saying that in my service impl I
> > shouldn't use an ObjectFactory to build/modify recieved/sent
> > PersonEndPoint objects?
> > 
> > I'm going to look around for more info about wrapper style vs
> > non-wrapper style (I'm quite new to all this). I was trying to find a
> > contract-first example using conposite custom objects rather than just
> > primitives (like the doubleit example) but no luck so far. Would you
> > happen to know of one?
> > 
> > Many Thanks,
> > 
> > Anthony
> > 
> > On Wednesday, 20 July 2011, Glen Mazza <gm...@talend.com> wrote:
> > > I'm not certain, you should be able to instantiate PersonEndPoint
> > > objects
> > 
> > directly.  The matter *might* be related to this:
> > https://cwiki.apache.org/CXF20DOC/wsdl-to-java.html#WSDLtoJava-wrapperst
> > yle(you may need to switch to wrapper style).
> > 
> > > HTH,
> > > Glen
> > > 
> > > On 07/20/2011 12:51 PM, Anthony Webster wrote:
> > > 
> > > Hi,
> > > 
> > > I have generated a webservice using wsdl2java and it all works fine.
> > > The problem is that I'm exchanging PersonEndPoint objects and
> > > wsdl2java has
> > 
> > set
> > 
> > > all the properties to JAXBElement<...>  (usually Strings). This
> > > makes
> > > manipulating the objects received on the server side rather painful.
> > > So
> > > instead of
> > > 
> > > Person person = new Person();
> > > person.setName("Bob");
> > > 
> > > I have to go through
> > > 
> > > ObjectFactory of = new ObjectFactory();
> > > PersonEndPoint person = of.createPersonEndPoint();
> > > person.setFirstName(of.createPersonEndPointFirstName("Bob"));
> > > 
> > > Seems strange. Am I doing something wrong?
> > > 
> > > Many Thanks,
> > > 
> > > Anthony
> > > 
> > > 
> > > 
> > > --
> > > Glen Mazza
> > > Application Integration Division
> > > Talend (http://www.talend.com/ai)
> > > blog: http://www.jroller.com/gmazza
-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
Talend - http://www.talend.com

Re: WSDL2JAVA results in JAXBElements everywhere...

Posted by Anthony Webster <aw...@gmail.com>.
Does anyone know what determines whether wsdl2java translates a
complexType's element to an @XmlElementRef annotated JAXBElement<String> or
an @XmlElement annotated String?

I was using Eclipse's WSDL editor to make a simple service project to
illustrate another problem I've been having (duplicating @Policies in
generated WSDLs). When I put this simple wsdl through SoapUI (which uses
cxf's wsdl2java) in order to generate stubs etc.. it generated @XmlElement
annotations for Strings whereas doing exactly the same with my client's WSDL
results in @XmlElementRef JAXBElement<String> thus requiring an
@XmlRegistry...

Any help would be most appreciated.

Many Thanks,

Anthony

On 21 July 2011 10:01, Anthony Webster <aw...@gmail.com> wrote:

> Sorry I don't quite follow. You're saying that in my service impl I
> shouldn't use an ObjectFactory to build/modify recieved/sent
> PersonEndPoint objects?
>
> I'm going to look around for more info about wrapper style vs
> non-wrapper style (I'm quite new to all this). I was trying to find a
> contract-first example using conposite custom objects rather than just
> primitives (like the doubleit example) but no luck so far. Would you
> happen to know of one?
>
> Many Thanks,
>
> Anthony
>
> On Wednesday, 20 July 2011, Glen Mazza <gm...@talend.com> wrote:
> > I'm not certain, you should be able to instantiate PersonEndPoint objects
> directly.  The matter *might* be related to this:
> https://cwiki.apache.org/CXF20DOC/wsdl-to-java.html#WSDLtoJava-wrapperstyle(you may need to switch to wrapper style).
> >
> > HTH,
> > Glen
> >
> > On 07/20/2011 12:51 PM, Anthony Webster wrote:
> >
> > Hi,
> >
> > I have generated a webservice using wsdl2java and it all works fine. The
> > problem is that I'm exchanging PersonEndPoint objects and wsdl2java has
> set
> > all the properties to JAXBElement<...>  (usually Strings). This makes
> > manipulating the objects received on the server side rather painful. So
> > instead of
> >
> > Person person = new Person();
> > person.setName("Bob");
> >
> > I have to go through
> >
> > ObjectFactory of = new ObjectFactory();
> > PersonEndPoint person = of.createPersonEndPoint();
> > person.setFirstName(of.createPersonEndPointFirstName("Bob"));
> >
> > Seems strange. Am I doing something wrong?
> >
> > Many Thanks,
> >
> > Anthony
> >
> >
> >
> > --
> > Glen Mazza
> > Application Integration Division
> > Talend (http://www.talend.com/ai)
> > blog: http://www.jroller.com/gmazza
> >
> >
> >
>

Re: WSDL2JAVA results in JAXBElements everywhere...

Posted by Anthony Webster <aw...@gmail.com>.
Sorry I don't quite follow. You're saying that in my service impl I
shouldn't use an ObjectFactory to build/modify recieved/sent
PersonEndPoint objects?

I'm going to look around for more info about wrapper style vs
non-wrapper style (I'm quite new to all this). I was trying to find a
contract-first example using conposite custom objects rather than just
primitives (like the doubleit example) but no luck so far. Would you
happen to know of one?

Many Thanks,

Anthony

On Wednesday, 20 July 2011, Glen Mazza <gm...@talend.com> wrote:
> I'm not certain, you should be able to instantiate PersonEndPoint objects directly.  The matter *might* be related to this:  https://cwiki.apache.org/CXF20DOC/wsdl-to-java.html#WSDLtoJava-wrapperstyle (you may need to switch to wrapper style).
>
> HTH,
> Glen
>
> On 07/20/2011 12:51 PM, Anthony Webster wrote:
>
> Hi,
>
> I have generated a webservice using wsdl2java and it all works fine. The
> problem is that I'm exchanging PersonEndPoint objects and wsdl2java has set
> all the properties to JAXBElement<...>  (usually Strings). This makes
> manipulating the objects received on the server side rather painful. So
> instead of
>
> Person person = new Person();
> person.setName("Bob");
>
> I have to go through
>
> ObjectFactory of = new ObjectFactory();
> PersonEndPoint person = of.createPersonEndPoint();
> person.setFirstName(of.createPersonEndPointFirstName("Bob"));
>
> Seems strange. Am I doing something wrong?
>
> Many Thanks,
>
> Anthony
>
>
>
> --
> Glen Mazza
> Application Integration Division
> Talend (http://www.talend.com/ai)
> blog: http://www.jroller.com/gmazza
>
>
>

Re: WSDL2JAVA results in JAXBElements everywhere...

Posted by Glen Mazza <gm...@talend.com>.
I'm not certain, you should be able to instantiate PersonEndPoint 
objects directly.  The matter *might* be related to this:  
https://cwiki.apache.org/CXF20DOC/wsdl-to-java.html#WSDLtoJava-wrapperstyle 
(you may need to switch to wrapper style).

HTH,
Glen

On 07/20/2011 12:51 PM, Anthony Webster wrote:
> Hi,
>
> I have generated a webservice using wsdl2java and it all works fine. The
> problem is that I'm exchanging PersonEndPoint objects and wsdl2java has set
> all the properties to JAXBElement<...>  (usually Strings). This makes
> manipulating the objects received on the server side rather painful. So
> instead of
>
> Person person = new Person();
> person.setName("Bob");
>
> I have to go through
>
> ObjectFactory of = new ObjectFactory();
> PersonEndPoint person = of.createPersonEndPoint();
> person.setFirstName(of.createPersonEndPointFirstName("Bob"));
>
> Seems strange. Am I doing something wrong?
>
> Many Thanks,
>
> Anthony


-- 
Glen Mazza
Application Integration Division
Talend (http://www.talend.com/ai)
blog: http://www.jroller.com/gmazza