JAX-WS controlling occurrence constraints in schema -- how to?

K

Karl Uppiano

When developing a Java-first web service, not been able to find any
annotation that will control minOccurs and maxOccurs in the generated web
service schema. As far as I can tell, JAX-WS sets minOccurs="1" for elements
that map to Java primitives, and minOccurs="0" for class instance
references, on the assumption that a Java primitive is not nillable, whereas
an instance reference is. Does anybody know if there is any more
fine-grained way to control occurrence constraints?
 
S

sasuke

When developing a Java-first web service, not been able to find any
annotation that will control minOccurs and maxOccurs in the generated web
service schema. As far as I can tell, JAX-WS sets minOccurs="1" for elements
that map to Java primitives, and minOccurs="0" for class instance
references, on the assumption that a Java primitive is not nillable, whereas
an instance reference is. Does anybody know if there is any more
fine-grained way to control occurrence constraints?

AFAIK, the minOccurs and maxOccurs attributes form part of your schema
definition [defined using XML Schema Definition (XSD)] and not your
Web Service contract.

Regarding the comment about primitives, I think you are a bit off the
mark. A good read might be:
< http://www.ibm.com/developerworks/webservices/library/ws-tip-null.html< http://www.dimuthu.org/blog/2008/08/18/xml-schema-nillabletrue-vs-minoccurs0
The way these kinds of services are usually designed are:
- You define your input and output value objects using a XSD.
Something like: http://pastie.org/518345 The XSD specification offers
constructs to control occurrence constraints.
- Pass it to a JAXB compiler which would generate Java classes for
your schema
- Create a web service contract using the JAX-WS annotations.
- The method input and output parameters can now be your new generated
classes which contain all the information required for unmarshalling
XML to create JAXB value objects from the WS request and marshalling
Java objects to XML when sending the WS response.
- Generate a WSDL from it and create an implementation class for the
WS contract.
- Publish your WS implementation using a framework/WS stack of your
choice. Please look into the documentation of the concerned tools for
more details.

../sasuke
 
K

Karl Uppiano

sasuke said:
When developing a Java-first web service, not been able to find any
annotation that will control minOccurs and maxOccurs in the generated web
service schema. As far as I can tell, JAX-WS sets minOccurs="1" for
elements
that map to Java primitives, and minOccurs="0" for class instance
references, on the assumption that a Java primitive is not nillable,
whereas
an instance reference is. Does anybody know if there is any more
fine-grained way to control occurrence constraints?

AFAIK, the minOccurs and maxOccurs attributes form part of your schema
definition [defined using XML Schema Definition (XSD)] and not your
Web Service contract.

The schema definition of the web service data types is part of the web
service contract by my definition.

I am merely describing what I have observed as the behavior of JAX-WS, and
trying to make some sense of why some elements have minOccurs="1" and some
don't.
The way these kinds of services are usually designed are:
- You define your input and output value objects using a XSD.
Something like: http://pastie.org/518345 The XSD specification offers
constructs to control occurrence constraints.
- Pass it to a JAXB compiler which would generate Java classes for
your schema
- Create a web service contract using the JAX-WS annotations.
- The method input and output parameters can now be your new generated
classes which contain all the information required for unmarshalling
XML to create JAXB value objects from the WS request and marshalling
Java objects to XML when sending the WS response.
- Generate a WSDL from it and create an implementation class for the
WS contract.
- Publish your WS implementation using a framework/WS stack of your
choice. Please look into the documentation of the concerned tools for
more details.

You are describing the "contract first" design method, which begs the issue.
I am asking about the "Java first" design method, and I am asking if anyone
knows if there are annotations that allow finer grained control over
occurrence constraints.
 
J

j4jackycheng

Hi Karl,

Happened to read your post "jax-ws controlling occurrence".

I'm facing exactly the same problem as you, just wonder did you find
any solution to control the minOccurs or maxOccurs yet?

Also, do you know how to "override" the WSDL file auto generated by
weblogic workshop (i'm using 10.3) ?
One way i had tried is to extract the EAR file -> then extract the WAR
file -> then manaully change the WSDL file -> then zip up those file
again to a EAR file.

While this works for me, but it includes tons of manually work.

I really appreciate if you could share your solution with us.

Thanks a lot Karl.

Cheers,
Jacky
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top