Chris Dunphy | 9 May 22:45
Picon

[groovy-user] GroovyWS: setting a string property through WSClient broken?

Hello,

I am trying to use GroovyWS to send a simple bean over the network in a
fashion similar to the BookService example.  However, I seem to run into
trouble if I try to set a string property on a bean object from the
WSClient side.

I can see the MessageBean object in my WSDL:

*** WSDL portion ***

<xsd:schema attributeFormDefault="qualified"
elementFormDefault="qualified"
targetNamespace="http://to.messagechomper.chris.dunphy">
  <xsd:complexType name="MessageBean">
    <xsd:sequence>
      <xsd:element minOccurs="0" name="id" type="xsd:long"/>
      <xsd:element minOccurs="0" name="message" nillable="true"
type="xsd:string"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>

Here is the bean object on the server side:

*** MessageBean.groovy ***

package dunphy.chris.messagechomper.to

class MessageBean {
    String message
    long id
}

*** MessageBean.aegis.xml (same package as MessageBean class) ***

<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns:sample="http://to.messagechomper.chris.dunphy">
  <mapping name="sample:MessageBean">
    <property name="metaClass" ignore="true"/>
  </mapping>
</mappings>

Here is the web service I am exposing on the server (MessageQueue is
just a singleton wrapped around a priority queue so I can access the
messages the server recieves in other classes):

*** MessageChomper.groovy ****

package dunphy.chris.messagechomper

import dunphy.chris.messagechomper.to.MessageBean

class MessageChomperService {

    private queue = MessageQueue.getInstance()

    MessageBean item

    public offer(MessageBean message) {
        queue.offer(message)
    }

}

On the client side I am trying to do this....

*** Main.groovy ***

package dunphy.chris.messagesender

import groovyx.net.ws.WSClient

class Main {
	static void main(args) {
	
		println "Creating web proxy"
		def proxy = 
			new
WSClient("http://localhost:9000/MessageChomperService?wsdl",
				Main.class.classLoader)
		
		// This is our message message
		def bean =
proxy.create("dunphy.chris.messagechomper.to.MessageBean")
		
		// Set the properties
		bean.id = 123
		bean.message = 'Hello World'
		
		// Add the message message to the queue
		proxy.offer(bean)
		println "Message sent!"
	
	}
}

If I comment out the setting of the message... I can send the bean with
the id field populated ok.  That works.  However, as soon as I try to
set the String property I get this:

Creating web proxy
May 9, 2008 2:36:04 PM
org.apache.cxf.endpoint.dynamic.DynamicClientFactory outp
utDebug
INFO: Created classes: dunphy.chris.messagechomper.GetItem,
dunphy.chris.message
chomper.GetItemResponse, dunphy.chris.messagechomper.ObjectFactory,
dunphy.chris
.messagechomper.Offer, dunphy.chris.messagechomper.OfferResponse,
dunphy.chris.m
essagechomper.SetItem, dunphy.chris.messagechomper.SetItemResponse,
dunphy.chris
.messagechomper.to.MessageBean,
dunphy.chris.messagechomper.to.ObjectFactory
BindingInfo = org.apache.cxf.binding.soap.model.SoapBindingInfo <at> 538974
o = SOAPBinding ({http://schemas.xmlsoap.org/wsdl/soap/}binding):
required=null
transportURI=http://schemas.xmlsoap.org/soap/http
style=document
Exception in thread "main"
org.codehaus.groovy.runtime.typehandling.GroovyCastEx
ception: Cannot cast object 'Hello World' with class 'java.lang.String'
to class
 'javax.xml.bind.JAXBElement'
        at
org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.ca
stToType(DefaultTypeTransformation.java:340)
        at
groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:1986)
        at
groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2582)
        at
org.codehaus.groovy.runtime.InvokerHelper.setProperty(InvokerHelper.j
ava:200)
        at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setProperty(ScriptB
ytecodeAdapter.java:503)
        at dunphy.chris.messagesender.Main.main(Main.groovy:16)

Is there a workaround for this?  Is this a bug, or am I doing something
wrong?

Another weird thing, to get the MessageBean to show up in the proper
packaged namespace I actually have to add it as a property of
MessageBeanService, if I just have the MessageBean as part of the
offer() method signature it won't use my package namespace.  Any idea
why?

I am pretty close to getting this message PoC going, just a few hurdles
like this to go.

Thanks,

Chris Dunphy
==========================================================
Software Developer, Enterprise Management 
chris.dunphy@...
<mailto:chris.dunphy@...> 
Shaw Cable Systems G.P.
Suite 800, 630 - 3rd SW
Calgary, Alberta T2P 4L4
Phone (403)750-7417 Fax (403)234-6295
==========================================================
"Always do right. This will gratify some people, 
and astonish the rest." --Mark Twain
==========================================================

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Gmane