Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

[groovy-user] How do I set the value of a WSDL restricted simple type

Bilal Sheikh

2008-08-12

Replies: Find Java Web Hosting

Author LoginPost Reply
Hi,

I'm new to Groovy and Grails.  I'm trying to write code that consumes a web service (using GroovyWS).  However, some of the WSDL complex types contain simple types with restrictions based on enumerations, and I get a GroovyCastException when trying to set the value of the simple type.

Here is a short example of what I'm running into:
-------WSDL-------------
<complexType name="Foo">
  <sequence>
    <element name="fooColor" type="tns:FooColor" nillable="false"/>
    <element name="bar" type="xsd:int"/>
    <element name="fooName" type="xsd:string"/>
  </sequence>
</complexType>

<simpleType name="FooColor">
  <restriction base="xsd:string">
    <enumeration value="Red"/>
    <enumeration value="Black"/>
  </restriction>
</simpleType>
-------/WSDL-------------

-------Groovy-------------
def proxy = new WSClient("https://fooserver/fooBarService?WSDL", this.class.classLoader)
def myFoo= proxy .create("com.fooBarDef.Foo")
myFoo.fooColor = "Red"      <----------  causes exception
-------/Groovy-------------

This is the exception from the above code:
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'Red' with class 'java.lang.String' to class 'com.fooBarDef.Foo'

I would greatly appreciate any help in resolving this.

Thanks!
Bilal
©2008 gg3721.com - Jax Systems, LLC, U.S.A.