3 Replies Latest reply on Nov 21, 2005 8:38 AM by aloubyansky

    Marshalling elements with minOccurs=

    ivanneto

      Although JBoss respects the attribute nillable="true", it seems to ignore
      minOccurs="0" when maxOccurs="1" (or is omited, which is the same). For
      example, supose I have the folowing element defined in my XSD file:

      <xsd:complexType name="CoordinationContextType">
       <xsd:sequence>
       <xsd:element name="CoordinationType" type="xsd:string" minOccurs="0" />
       </xsd:sequence>
      </xsd:complexType>
      


      The Java counterpart:

      public class CoordinationContextType {
      
       private String coordinationType;
      
       public CoordinationContextType() {
       }
      
       public CoordinationContextType(String coordinationType) {
       this.coordinationType = coordinationType;
       }
      
       public String getCoordinationType() {
       return coordinationType;
       }
      
       public void setCoordinationType(String type) {
       coordinationType = type;
       }
      }
      


      As the "CoordinationType" element has a minOccurs="0" attribute, it should be
      possible to omit such element. So the following Java object instance is valid:

      // ctx.coordinationType is null!
      CoordinationContextType ctx = new CoordinationContextType();
      


      And should be marshalled as (the coordinationType element is omited):

      <ns:CoordinationContextType />
      


      But when this happens JBoss XB raises an exception:

      va.rmi.RemoteException: Call invocation failed: Could not transmit message; nested exception is:
       javax.xml.soap.SOAPException: Could not transmit message
       at org.jboss.ws.jaxrpc.CallImpl.invokeInternal(CallImpl.java:661)
       at org.jboss.ws.jaxrpc.CallImpl.invoke(CallImpl.java:399)
       at org.jboss.ws.jaxrpc.CallProxy.invoke(CallProxy.java:115)
       at $Proxy1.createCoordinationContext(Unknown Source)
       at org.jboss.test.ws.jbwsxxx.UnitTestCase.testMinOccurs(UnitTestCase.java:39)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at junit.framework.TestCase.runTest(TestCase.java:154)
       at junit.framework.TestCase.runBare(TestCase.java:127)
       at junit.framework.TestResult$1.protect(TestResult.java:106)
       at junit.framework.TestResult.runProtected(TestResult.java:124)
       at junit.framework.TestResult.run(TestResult.java:109)
       at junit.framework.TestCase.run(TestCase.java:118)
       at junit.framework.TestSuite.runTest(TestSuite.java:208)
       at junit.framework.TestSuite.run(TestSuite.java:203)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
      Caused by: javax.xml.soap.SOAPException: Could not transmit message
       at org.jboss.ws.soap.SOAPConnectionImpl.call(SOAPConnectionImpl.java:138)
       at org.jboss.ws.jaxrpc.CallImpl.invokeInternal(CallImpl.java:640)
       ... 19 more
      Caused by: org.jboss.xb.binding.JBossXBRuntimeException: Failed to marshal {http://test.ws.jboss.org/fakewscoor}CoordinationType: Java value is null but the element is not nillable.
       at org.jboss.xb.binding.XercesXsMarshaller.writeNillable(XercesXsMarshaller.java:1019)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalElement(XercesXsMarshaller.java:350)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalParticle(XercesXsMarshaller.java:707)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalModelGroupSequence(XercesXsMarshaller.java:883)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalModelGroup(XercesXsMarshaller.java:838)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalParticle(XercesXsMarshaller.java:662)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalComplexType(XercesXsMarshaller.java:623)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalElementType(XercesXsMarshaller.java:373)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalElement(XercesXsMarshaller.java:346)
       at org.jboss.xb.binding.XercesXsMarshaller.marshallInternal(XercesXsMarshaller.java:249)
       at org.jboss.xb.binding.XercesXsMarshaller.marshal(XercesXsMarshaller.java:196)
       at org.jboss.ws.jaxb.JAXBMarshallerImpl.marshal(JAXBMarshallerImpl.java:157)
       at org.jboss.ws.jaxrpc.encoding.JAXBSerializer.serialize(JAXBSerializer.java:99)
       at org.jboss.ws.soap.SOAPContentElement.getXMLFragment(SOAPContentElement.java:167)
       at org.jboss.ws.soap.SOAPContentElement.expandToDOM(SOAPContentElement.java:701)
       at org.jboss.ws.soap.SOAPContentElement.getChildNodes(SOAPContentElement.java:618)
       at org.jboss.util.xml.DOMWriter.printInternal(DOMWriter.java:166)
       at org.jboss.util.xml.DOMWriter.printInternal(DOMWriter.java:225)
       at org.jboss.util.xml.DOMWriter.printInternal(DOMWriter.java:225)
       at org.jboss.util.xml.DOMWriter.print(DOMWriter.java:144)
       at org.jboss.util.xml.DOMWriter.printNode(DOMWriter.java:93)
       at org.jboss.ws.soap.SOAPConnectionImpl.call(SOAPConnectionImpl.java:120)
       ... 20 more
      


      If an element that has minOccurs="0" in the XSD has a null value in the Java
      counterpart, it should be omited from the generated SOAP message, shouldn't
      it? It seems that JBoss XB just verifies if the element is nillable, and
      ignores minOccurs="0".

      May I open a Jira Issue for this?