You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Michael Ryan <Mi...@stellent.com> on 2005/01/19 02:30:46 UTC

FW: How to set the marshalled type for anyType?

OK, I'll provide a bit more info to see if that helps elicit some
assistance.  We are using Axis 1.2RC2.  We are only using Axis on the
client side.

We are using anyType to allow us to pass any object type to our server
app.  We need to use the XSD types, and several types defined by our
WSDL.  The WSDL segment that declares this is:

  <complexType name="Option">
  <sequence>
   <element name="name" type="xsd:string" minOccurs="1" maxOccurs="1"
nillable="true"/>
   <element name="value" type="xsd:anyType" minOccurs="1" maxOccurs="1"
nillable="true"/>
  </sequence>
 </complexType>

When run through Wsdl2Java, it produces a class named Option.java (see
below for src).


Now, when the value field in the Option class is actually a
java.lang.Boolean, this field gets serialized as a soapenc:boolean, as
opposed to a xsd:boolean.  This causes interop issues.  I know there
have been other issues similar to this in the past; I reported one of
them about 2 years ago, and it was finally fixed for complex types in
the 1.2 RC releases, but apparently, similar things still happen in
other circumstances.  This did work fine in the original 1.0RC1, which
has only recently upgraded from (finally).  The same thing happens when
using other native types, such as int, long, string, etc...  here is a
snippet of the SOAP generated:
            <item xsi:type="ns1:Option">
               <name xsi:type="xsd:string">noSourceFormatting</name>
               <value xsi:type="soapenc:boolean">true</value>
            </item>

Here's my questions:
1.  What is the correct behavior?  Is this a bug?  I believe that
classes such as Boolean, String, Integer, should always be serialized
using the XSD types.  There seems to be some belief that if an element
is nillable, it needs to use the soapenc types, but I don't see why that
is.  Obviously, if the value field in the Option class has a
java.lang.Boolean, it is not nill.

2.  Is there a way to control this?  Is there a property that can be set
to control this?  Can I write custom (de)serializers to properly handle
types such as java.lang.Boolean?    Is there a method/class that I can
modify to change this behavior?  I'm more than willing to modify the
behavior of Axis to do this, and see what other repurcussions the change
has, but I don't know where to start inside the code.

Thanks for any help and/or commiseration with this issue,
Mike Ryan



Option.java src:
/**
 * Option.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis 1.2RC2 Nov 16, 2004 (12:19:44 EST) WSDL2Java
emitter.
 */

package samurai.ws.axis.transform;

public class Option  implements java.io.Serializable {
    private java.lang.String name;
    private java.lang.Object value;

    public Option() {
    }

    public Option(
           java.lang.String name,
           java.lang.Object value) {
           this.name = name;
           this.value = value;
    }


    /**
     * Gets the name value for this Option.
     * 
     * @return name
     */
    public java.lang.String getName() {
        return name;
    }


    /**
     * Sets the name value for this Option.
     * 
     * @param name
     */
    public void setName(java.lang.String name) {
        this.name = name;
    }


    /**
     * Gets the value value for this Option.
     * 
     * @return value
     */
    public java.lang.Object getValue() {
        return value;
    }


    /**
     * Sets the value value for this Option.
     * 
     * @param value
     */
    public void setValue(java.lang.Object value) {
        this.value = value;
    }

    private java.lang.Object __equalsCalc = null;
    public synchronized boolean equals(java.lang.Object obj) {
        if (!(obj instanceof Option)) return false;
        Option other = (Option) obj;
        if (obj == null) return false;
        if (this == obj) return true;
        if (__equalsCalc != null) {
            return (__equalsCalc == obj);
        }
        __equalsCalc = obj;
        boolean _equals;
        _equals = true && 
            ((this.name==null && other.getName()==null) || 
             (this.name!=null &&
              this.name.equals(other.getName()))) &&
            ((this.value==null && other.getValue()==null) || 
             (this.value!=null &&
              this.value.equals(other.getValue())));
        __equalsCalc = null;
        return _equals;
    }

    private boolean __hashCodeCalc = false;
    public synchronized int hashCode() {
        if (__hashCodeCalc) {
            return 0;
        }
        __hashCodeCalc = true;
        int _hashCode = 1;
        if (getName() != null) {
            _hashCode += getName().hashCode();
        }
        if (getValue() != null) {
            _hashCode += getValue().hashCode();
        }
        __hashCodeCalc = false;
        return _hashCode;
    }

    // Type metadata
    private static org.apache.axis.description.TypeDesc typeDesc =
        new org.apache.axis.description.TypeDesc(Option.class, true);

    static {
        typeDesc.setXmlType(new
javax.xml.namespace.QName("http://www.outsideinsdk.com/transformation_se
rver/transform/1/0/", "Option"));
        org.apache.axis.description.ElementDesc elemField = new
org.apache.axis.description.ElementDesc();
        elemField.setFieldName("name");
        elemField.setXmlName(new javax.xml.namespace.QName("", "name"));
        elemField.setXmlType(new
javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",
"string"));
        elemField.setMinOccurs(0);
        typeDesc.addFieldDesc(elemField);
        elemField = new org.apache.axis.description.ElementDesc();
        elemField.setFieldName("value");
        elemField.setXmlName(new javax.xml.namespace.QName("",
"value"));
        elemField.setXmlType(new
javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",
"anyType"));
        elemField.setMinOccurs(0);
        typeDesc.addFieldDesc(elemField);
    }

    /**
     * Return type metadata object
     */
    public static org.apache.axis.description.TypeDesc getTypeDesc() {
        return typeDesc;
    }

    /**
     * Get Custom Serializer
     */
    public static org.apache.axis.encoding.Serializer getSerializer(
           java.lang.String mechType, 
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) {
        return 
          new  org.apache.axis.encoding.ser.BeanSerializer(
            _javaType, _xmlType, typeDesc);
    }

    /**
     * Get Custom Deserializer
     */
    public static org.apache.axis.encoding.Deserializer getDeserializer(
           java.lang.String mechType, 
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) {
        return 
          new  org.apache.axis.encoding.ser.BeanDeserializer(
            _javaType, _xmlType, typeDesc);
    }

}

>  -----Original Message-----
> From: 	Michael Ryan [mailto:Michael.Ryan@stellent.com] 
> Sent:	Monday, January 17, 2005 11:05 AM
> To:	axis-user@ws.apache.org
> Subject:	How to set the marshalled type for anyType?
> 
> Hello-
> 
> I have a service that has a parameter that is defined as anyType.
> When this parameter is passed a java Boolean, it is serialized as a
> "soapenc:boolean".  In order to interoperate with another SOAP impl, I
> would like to have this serialized as an "xsd:boolean".  How do I
> configure Axis to do this?
> 
> Thanks,
> Mike Ryan

Re: FW: How to set the marshalled type for anyType?

Posted by jayachandra <ja...@gmail.com>.
Do you have the latest code? Try with the latest sources from CVS. It
should be working fine.

Jayachandra

On Tue, 18 Jan 2005 19:30:46 -0600, Michael Ryan
<Mi...@stellent.com> wrote:
> 
> 
> OK, I'll provide a bit more info to see if that helps elicit some
> assistance.  We are using Axis 1.2RC2.  We are only using Axis on the client
> side.
> 
> We are using anyType to allow us to pass any object type to our server app. 
> We need to use the XSD types, and several types defined by our WSDL.  The
> WSDL segment that declares this is:
> 
>   <complexType name="Option"> 
>   <sequence> 
>    <element name="name" type="xsd:string" minOccurs="1" maxOccurs="1"
> nillable="true"/> 
>    <element name="value" type="xsd:anyType" minOccurs="1" maxOccurs="1"
> nillable="true"/> 
>   </sequence> 
>  </complexType> 
> 
> When run through Wsdl2Java, it produces a class named Option.java (see below
> for src). 
> 
> 
> Now, when the value field in the Option class is actually a
> java.lang.Boolean, this field gets serialized as a soapenc:boolean, as
> opposed to a xsd:boolean.  This causes interop issues.  I know there have
> been other issues similar to this in the past; I reported one of them about
> 2 years ago, and it was finally fixed for complex types in the 1.2 RC
> releases, but apparently, similar things still happen in other
> circumstances.  This did work fine in the original 1.0RC1, which has only
> recently upgraded from (finally).  The same thing happens when using other
> native types, such as int, long, string, etc…  here is a snippet of the SOAP
> generated:
> 
>             <item xsi:type="ns1:Option"> 
>                <name xsi:type="xsd:string">noSourceFormatting</name> 
>                <value xsi:type="soapenc:boolean">true</value> 
>             </item> 
> 
> Here's my questions: 
> 1.  What is the correct behavior?  Is this a bug?  I believe that classes
> such as Boolean, String, Integer, should always be serialized using the XSD
> types.  There seems to be some belief that if an element is nillable, it
> needs to use the soapenc types, but I don't see why that is.  Obviously, if
> the value field in the Option class has a java.lang.Boolean, it is not nill.
> 
> 2.  Is there a way to control this?  Is there a property that can be set to
> control this?  Can I write custom (de)serializers to properly handle types
> such as java.lang.Boolean?    Is there a method/class that I can modify to
> change this behavior?  I'm more than willing to modify the behavior of Axis
> to do this, and see what other repurcussions the change has, but I don't
> know where to start inside the code.
> 
> Thanks for any help and/or commiseration with this issue, 
> Mike Ryan 
> 
> 
> 
> Option.java src: 
> /** 
>  * Option.java 
>  * 
>  * This file was auto-generated from WSDL 
>  * by the Apache Axis 1.2RC2 Nov 16, 2004 (12:19:44 EST) WSDL2Java emitter. 
>  */ 
> 
> package samurai.ws.axis.transform; 
> 
> public class Option  implements java.io.Serializable { 
>     private java.lang.String name; 
>     private java.lang.Object value; 
> 
>     public Option() { 
>     } 
> 
>     public Option( 
>            java.lang.String name, 
>            java.lang.Object value) { 
>            this.name = name; 
>            this.value = value; 
>     } 
> 
> 
>     /** 
>      * Gets the name value for this Option. 
>      * 
>      * @return name 
>      */ 
>     public java.lang.String getName() { 
>         return name; 
>     } 
> 
> 
>     /** 
>      * Sets the name value for this Option. 
>      * 
>      * @param name 
>      */ 
>     public void setName(java.lang.String name) { 
>         this.name = name; 
>     } 
> 
> 
>     /** 
>      * Gets the value value for this Option. 
>      * 
>      * @return value 
>      */ 
>     public java.lang.Object getValue() { 
>         return value; 
>     } 
> 
> 
>     /** 
>      * Sets the value value for this Option. 
>      * 
>      * @param value 
>      */ 
>     public void setValue(java.lang.Object value) { 
>         this.value = value; 
>     } 
> 
>     private java.lang.Object __equalsCalc = null; 
>     public synchronized boolean equals(java.lang.Object obj) { 
>         if (!(obj instanceof Option)) return false; 
>         Option other = (Option) obj; 
>         if (obj == null) return false; 
>         if (this == obj) return true; 
>         if (__equalsCalc != null) { 
>             return (__equalsCalc == obj); 
>         } 
>         __equalsCalc = obj; 
>         boolean _equals; 
>         _equals = true && 
>             ((this.name==null && other.getName()==null) || 
>              (this.name!=null && 
>               this.name.equals(other.getName()))) && 
>             ((this.value==null && other.getValue()==null) || 
>              (this.value!=null && 
>               this.value.equals(other.getValue()))); 
>         __equalsCalc = null; 
>         return _equals; 
>     } 
> 
>     private boolean __hashCodeCalc = false; 
>     public synchronized int hashCode() { 
>         if (__hashCodeCalc) { 
>             return 0; 
>         } 
>         __hashCodeCalc = true; 
>         int _hashCode = 1; 
>         if (getName() != null) { 
>             _hashCode += getName().hashCode(); 
>         } 
>         if (getValue() != null) { 
>             _hashCode += getValue().hashCode(); 
>         } 
>         __hashCodeCalc = false; 
>         return _hashCode; 
>     } 
> 
>     // Type metadata 
>     private static org.apache.axis.description.TypeDesc typeDesc = 
>         new org.apache.axis.description.TypeDesc(Option.class, true); 
> 
>     static { 
>         typeDesc.setXmlType(new
> javax.xml.namespace.QName("http://www.outsideinsdk.com/transformation_server/transform/1/0/",
> "Option"));
> 
>         org.apache.axis.description.ElementDesc elemField = new
> org.apache.axis.description.ElementDesc(); 
>         elemField.setFieldName("name"); 
>         elemField.setXmlName(new javax.xml.namespace.QName("", "name")); 
>         elemField.setXmlType(new
> javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string")); 
>         elemField.setMinOccurs(0); 
>         typeDesc.addFieldDesc(elemField); 
>         elemField = new org.apache.axis.description.ElementDesc(); 
>         elemField.setFieldName("value"); 
>         elemField.setXmlName(new javax.xml.namespace.QName("", "value")); 
>         elemField.setXmlType(new
> javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "anyType")); 
>         elemField.setMinOccurs(0); 
>         typeDesc.addFieldDesc(elemField); 
>     } 
> 
>     /** 
>      * Return type metadata object 
>      */ 
>     public static org.apache.axis.description.TypeDesc getTypeDesc() { 
>         return typeDesc; 
>     } 
> 
>     /** 
>      * Get Custom Serializer 
>      */ 
>     public static org.apache.axis.encoding.Serializer getSerializer( 
>            java.lang.String mechType, 
>            java.lang.Class _javaType,  
>            javax.xml.namespace.QName _xmlType) { 
>         return 
>           new  org.apache.axis.encoding.ser.BeanSerializer( 
>             _javaType, _xmlType, typeDesc); 
>     } 
> 
>     /** 
>      * Get Custom Deserializer 
>      */ 
>     public static org.apache.axis.encoding.Deserializer getDeserializer( 
>            java.lang.String mechType, 
>            java.lang.Class _javaType,  
>            javax.xml.namespace.QName _xmlType) { 
>         return 
>           new  org.apache.axis.encoding.ser.BeanDeserializer( 
>             _javaType, _xmlType, typeDesc); 
>     } 
> 
> 
> } 
> 
>  -----Original Message----- 
> From:   Michael Ryan [mailto:Michael.Ryan@stellent.com] 
> Sent:   Monday, January 17, 2005 11:05 AM 
> To:     axis-user@ws.apache.org 
> Subject:        How to set the marshalled type for anyType? 
> 
> Hello- 
> 
> I have a service that has a parameter that is defined as anyType.  When this
> parameter is passed a java Boolean, it is serialized as a "soapenc:boolean".
>  In order to interoperate with another SOAP impl, I would like to have this
> serialized as an "xsd:boolean".  How do I configure Axis to do this?
> 
> Thanks, 
> Mike Ryan 


-- 
-- Jaya