2 Replies Latest reply on Mar 28, 2007 1:05 PM by jason.greene

    Unmarshalling and binding issues

    magnus.ahlander

      I'm using JAXWS 1.2 and I am trying to generate a web service client from a wsdl, it works but I have a couple of minor issues:

      1) Unmarshalling does not find a needed class

      Inside of my wsdl I have the following type:

      ...
      <s:complexType name="ItemValue">
       <s:sequence>
       <s:element minOccurs="0" maxOccurs="1" name="DiagnosticInfo" type="s:string"/>
       <s:element minOccurs="0" maxOccurs="1" name="Value"/>
       </s:sequence>
       <s:attribute name="ItemName" type="s:string"/>
      </s:complexType>
      ...

      wsconsume generates the following java class file

      import javax.xml.bind.annotation.*;
      
      @XmlAccessorType(XmlAccessType.FIELD)
      @XmlType(name = "ItemValue", propOrder = {
       "value"
      })
      public class ItemValue {
      
       @XmlElement(name = "Value")
       protected Object value;
       @XmlAttribute(name = "ItemName")
       protected String itemName;
      
       //... getters and setters
      }

      Everything works fine if "value" is a java type, for instance float

      <ItemValue xmlns='http://opcfoundation.org/webservices/XMLDA/1.0/' ItemName='Channel1.Device1.ComulativeElectric'>
       <Value xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='xsd:float'>6428.76806640625</Value>
      </ItemValue>

      However, if value is of some other generated type, in my case ArrayOfUnsignedInt, this class is not visible to the JAXBContent used at unmarshalling and the value is left unmarshalled (DOM element).

      What is the proper way to provide JAXBContent with the extra class needed for unmarshalling?
      I believe somewhere I would need to put something like:

      JAXBContext jaxbContext = JAXBContext.newInstance(ItemValue.class, ArrayOfUnsignedInt.class);

      Or is there some annotation that could be added to class ItemValue which would provide JAXB with the necessary information for unmarshalling? Or could I somehow modify the wsdl (created by a third party)?

      2) Modifying binding

      The received SOAP message contains a 64-bit value marked as 'xsd:float'

      <ItemValue xmlns='http://opcfoundation.org/webservices/XMLDA/1.0/' ItemName='Channel1.Device1.ComulativeElectric'>
       <Value xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='xsd:float'>6428.76806640625</Value>
      </ItemValue>

      JAXB (correctly) unmarshals this value to 6428.768 (java.lang.Float).

      What is the easiest way to override this binding (to say java.lang.Double) in a web service client?

      Regards,

      Magnus

        • 1. Re: Unmarshalling and binding issues
          magnus.ahlander

          Regarding my first question, the answer was provided to me on the java.net jaxb 2.0 and jax-ws 2.0 forum: JAX-WS does not support type substitution in cases where Java types are used at runtime that are not directly or indirectly referenced by the SEI. More details on:

          http://weblogs.java.net/blog/kohlert/archive/2006/10/jaxws_and_type.html

          In this blog entry it is said that JAX-WS 2.1 solves the issue through a new annotation @XmlSeeAlso, which is used to provide the JAXBContext with classes needed at unmarshalling.

          What are the plans for incorporating JAX-WS 2.1 in JBossWS? Is there any other solution, which could be applied using JBossWS 1.2?

          Regarding my other question I am still looking for a hint. How can I unmarshal a double value which is incorrectly tagged as 'xsd:float' in the SOAP reponse?

          Regards,
          Magnus

          • 2. Re: Unmarshalling and binding issues
            jason.greene

            Yes this is a limitation. The only workaround you could do right now is to create a dummy method that had all known subtypes in it's signature.

            In order to support XmlSeeAlso we just need to upgrade to JAXB 2.1. I have created a request for this for the 2.0 release. Until then you could try doing this yourself. Although I should warn you that while it should be compatible we have not done thorough testing on it.

            http://jira.jboss.com/jira/browse/JBWS-1591

            -Jason