[groovy-user] GroovyWS - Complex Response

95 views
Skip to first unread message

nico2280

unread,
Sep 16, 2009, 8:28:01 AM9/16/09
to us...@groovy.codehaus.org

Hi,

I'm trying to use groovyWS, but I don't know how to catch the response type
wich is more complex than I used to see ... usually my response is just a
string. With my code below, the result is just the first string ... how can
I make for having all the response's elements ?

Thanks by advance

<element name="checkVatResponse">
<complexType>
<sequence>
<element name="countryCode" type="xsd:string"/>
<element name="vatNumber" type="xsd:string"/>
<element name="requestDate" type="xsd:date"/>
<element name="valid" type="xsd:boolean"/>
<element name="name" type="xsd:string"/>
<element name="address" type="xsd:string"/>
</sequence>
</complexType>
</element>

here is the wsdl file :
http://ec.europa.eu/taxation_customs/vies/api/checkVatPort?wsdl

And here is my code :

//

import groovyx.net.ws.WSClient

def proxy = new
WSClient("http://ec.europa.eu/taxation_customs/vies/api/checkVatPort?wsdl",
this.class.classLoader)
proxy.initialize()

def result = proxy.checkVat("BE","65655");

println result

//
--
View this message in context: http://www.nabble.com/GroovyWS---Complex-Response-tp25471353p25471353.html
Sent from the groovy - user mailing list archive at Nabble.com.


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

http://xircles.codehaus.org/manage_email


nico2280

unread,
Sep 16, 2009, 9:09:45 AM9/16/09
to us...@groovy.codehaus.org

I've tried this, but, I've got an error

import groovyx.net.ws.WSClient

def proxy = new
WSClient("http://ec.europa.eu/taxation_customs/vies/api/checkVatPort?wsdl",
this.class.classLoader)
proxy.initialize()

def checkVat =
proxy.create("eu.europa.ec.taxud.vies.services.checkvat.types.CheckVat")

checkVat.countryCode = "LU"
checkVat.vatNumber = "21405308"

def resp = proxy.checkVat(checkVat);

println resp.countryCode
println resp.vatNumber
println resp.requestDate
println resp.valid
println resp.name
println resp.address

// error
16 sept. 2009 15:07:59 org.apache.cxf.phase.PhaseInterceptorChain
doIntercept
INFO: Interceptor has thrown exception, unwinding now Marshalling Error:
Instance of "eu.europa.ec.taxud.vies.services.c
heckvat.types.CheckVat" is substituting "java.lang.String", but
"eu.europa.ec.taxud.vies.services.checkvat.types.CheckVa
t" is bound to an anonymous type.
16 sept. 2009 15:07:59 groovyx.net.ws.AbstractCXFWSClient invokeMethod
GRAVE: Could not invoke method.
org.apache.cxf.interceptor.Fault: Marshalling Error: Instance of
"eu.europa.ec.taxud.vies.services.checkvat.types.CheckV
at" is substituting "java.lang.String", but
"eu.europa.ec.taxud.vies.services.checkvat.types.CheckVat" is bound to an an
onymous type.
at
org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:159)
at
org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:169)
at
org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.jav
a:104)
at
org.apache.cxf.interceptor.BareOutInterceptor.handleMessage(BareOutInterceptor.java:68)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:226)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:469)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:299)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:251)
at
groovyx.net.ws.AbstractCXFWSClient.invokeMethod(AbstractCXFWSClient.java:93)
at
org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at test3.run(test3.groovy:11)
at
groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256)
at groovy.lang.GroovyShell.run(GroovyShell.java:218)
at groovy.lang.GroovyShell.run(GroovyShell.java:147)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:493)
at groovy.ui.GroovyMain.run(GroovyMain.java:308)
at groovy.ui.GroovyMain.process(GroovyMain.java:294)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:111)
at groovy.ui.GroovyMain.main(GroovyMain.java:92)
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
org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108)
at
org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130)
Caused by: javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.SAXException2: Instance of
"eu.europa.ec.taxud.vies.services.checkvat.types.CheckVat" is substituting
"j
ava.lang.String", but
"eu.europa.ec.taxud.vies.services.checkvat.types.CheckVat" is bound to an
anonymous type.]
at
com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:328)
at
com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:254)
at
javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:75)
at
org.apache.cxf.jaxb.JAXBEncoderDecoder.writeObject(JAXBEncoderDecoder.java:441)
at
org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:138)
... 27 more
Caused by: com.sun.istack.SAXException2: Instance of
"eu.europa.ec.taxud.vies.services.checkvat.types.CheckVat" is subst
ituting "java.lang.String", but
"eu.europa.ec.taxud.vies.services.checkvat.types.CheckVat" is bound to an
anonymous type
.
at
com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:244)
at
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:659)
at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:151)
at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:185)
at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanInfoImpl.java:305)
at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:312)
at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:71)
at
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:490)
at
com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:325)
... 31 more
Caught: java.lang.NullPointerException: Cannot get property 'countryCode' on
null object
at test3.run(test3.groovy:13)
--
View this message in context: http://www.nabble.com/GroovyWS---Complex-Response-tp25471353p25472066.html

Roshan Dawrani

unread,
Sep 16, 2009, 2:30:15 PM9/16/09
to us...@groovy.codehaus.org
Does this webservice call work from Java? Do you have any non-GroovyWS implementation where you are able to invoke this service successfully?

Dennis Bayer

unread,
Sep 17, 2009, 2:23:55 AM9/17/09
to us...@groovy.codehaus.org
Hi Nico,
this issue is related to a wrapped/unwrapped call. The way of invoking
the method should be cofigurable (memo for me: write Guillaume) ;)).

Sometimes you have to pass each member. :/ For these cases the error is
always like yours below.

Please try this:
def checkVat0 =
proxy.create("eu.europa.ec.taxud.vies.services.checkvat.types.CheckVat")
checkVat0.countryCode = "LU" //<string>
checkVat0.vatNumber = "21405308" //<string>

def result = proxy.checkVat(checkVat0.countryCode, checkVat0.vatNumber)

This results in (converted into a map) :
0={result=LU}, 1={result=21405308}, 2={SIXTY=null,
LEAP_YEAR_DEFAULT=null, FIELD_NAME=null, SECOND=null,
second=-2147483648, DECIMAL_ONE=null, orig_minute=null,
MILLISECOND=null, TWENTY_FOUR=null, YEAR=null, FOUR=null, TIMEZONE=null,
DECIMAL_ZERO=null, TWELVE=null, orig_fracSeconds=null, daysInMonth=null,
minute=-2147483648, DECIMAL_SIXTY=null, timezone=-2147483648, DAY=null,
orig_eon=null, BILLION=null, HOUR=null, serialVersionUID=null,
year=2009, MONTH=null, eon=null, orig_day=null, orig_month=null,
hour=-2147483648, MAX_FIELD_VALUE=null, orig_second=null,
orig_hour=null, orig_timezone=null, fractionalSecond=null,
PURE_GREGORIAN_CHANGE=null, HUNDRED=null, orig_year=null, month=9,
MINUTE=null, FOUR_HUNDRED=null, MIN_FIELD_VALUE=null, day=17},
3={result=true}, 4={result=---}, 5={result=---}}

Regards,
Dennis.


nico2280 schrieb:

nico2280

unread,
Sep 17, 2009, 3:50:57 AM9/17/09
to us...@groovy.codehaus.org

Thanks you Dennis and Roshan :)
--
View this message in context: http://www.nabble.com/GroovyWS---Complex-Response-tp25471353p25486717.html

Sent from the groovy - user mailing list archive at Nabble.com.

nico2280

unread,
Sep 17, 2009, 4:04:16 AM9/17/09
to us...@groovy.codehaus.org

Just another question,
how do you convert the result in a Map ?
When I use your code Denis, my result.class is a java.lang.String.

Thanks again.
--
View this message in context: http://www.nabble.com/GroovyWS---Complex-Response-tp25471353p25486884.html


Sent from the groovy - user mailing list archive at Nabble.com.

Dennis Bayer

unread,
Sep 17, 2009, 5:07:23 AM9/17/09
to us...@groovy.codehaus.org
nico2280 schrieb:

> Just another question,
> how do you convert the result in a Map ?

I'm using the reflection mechanism of groovy and a recursive method. ;)
(and I just found a bug because of your service - thx.)

> When I use your code Denis, my result.class is a java.lang.String.

The wsdl says:
<element name="checkVatResponse">
<complexType>
<sequence>
<element name="countryCode" type="xsd:string"/>
<element name="vatNumber" type="xsd:string"/>
<element name="requestDate" type="xsd:date"/>
<element name="valid" type="xsd:boolean"/>
<element name="name" type="xsd:string"/>
<element name="address" type="xsd:string"/>
</sequence>
</complexType>
</element>

The webservice call should return an object of this type. Debugging the
result shows that there is an object-array containing each member stated
above. :/
The current implementation returns only the first element of an array.
This should be _countryCode_ which leads to your string result.

If you create your own ws-client by extending WSClient.java, you could
use this workaround. This workaround was discussed earlier in this
mailing list (it doesn't work out always).

/* (non-Javadoc)
* @see
groovyx.net.ws.AbstractCXFWSClient#parseResponse(java.lang.Object[])
*/
@Override
protected Object parseResponse(Object[] response)
{
if (response.length == 1)
{
return response[0];
}

return new ArrayList<Object>(Arrays.asList(response));
}

Regards.

>
> Thanks again.

nico2280

unread,
Sep 17, 2009, 5:21:20 AM9/17/09
to us...@groovy.codehaus.org

Okay ...
I'm checking it.

Thanks for your time.
--
View this message in context: http://www.nabble.com/GroovyWS---Complex-Response-tp25471353p25487870.html


Sent from the groovy - user mailing list archive at Nabble.com.

chatura

unread,
Dec 3, 2009, 1:44:18 AM12/3/09
to us...@groovy.codehaus.org

Hi Dennis ,
Thks very much, u save work what i already plane with groovyws.

Chatura.

--
View this message in context: http://old.nabble.com/GroovyWS---Complex-Response-tp25471353p26621693.html


Sent from the groovy - user mailing list archive at Nabble.com.

Antony Stubbs

unread,
Jan 27, 2010, 5:10:44 AM1/27/10
to us...@groovy.codehaus.org

Is this still the case? I'm getting the same error, but with a much bigger
object :(


-----
___________________________

http://stubbisms.wordpress.com http://stubbisms.wordpress.com
--
View this message in context: http://old.nabble.com/GroovyWS---Complex-Response-tp25471353p27335627.html


Sent from the groovy - user mailing list archive at Nabble.com.

Antony Stubbs

unread,
Jan 27, 2010, 7:25:01 AM1/27/10
to us...@groovy.codehaus.org

jira'd - GMOD-125


-----
___________________________

View this message in context: http://old.nabble.com/GroovyWS---Complex-Response-tp25471353p27338206.html

Francesco Cavola

unread,
Apr 8, 2010, 7:04:01 AM4/8/10
to us...@groovy.codehaus.org

Denis, I have the same problem. The result is not a map, but a String.
Is it a bug? I have to recompile some classes on server side?
This problem may be very common, it is not strange for you?
Thank you

> return new ArrayList(Arrays.asList(response));


> }
>
> Regards.
>
>>
>> Thanks again.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
>
>

--
View this message in context: http://old.nabble.com/GroovyWS---Complex-Response-tp25471353p28176971.html


Sent from the groovy - user mailing list archive at Nabble.com.

Dennis Bayer

unread,
Apr 12, 2010, 2:41:01 AM4/12/10
to us...@groovy.codehaus.org
Am 08.04.2010 13:04, schrieb Francesco Cavola:
>
> Denis, I have the same problem. The result is not a map, but a String.
> Is it a bug? I have to recompile some classes on server side?
> This problem may be very common, it is not strange for you?
> Thank you

Hi Francesco,
I don't get it. Could you post some details?

Regards.

Francesco Cavola

unread,
Apr 12, 2010, 6:36:53 AM4/12/10
to us...@groovy.codehaus.org

This is my code:

import groovyx.net.ws.WSClient

def proxy = new
WSClient("http://ec.europa.eu/taxation_customs/vies/api/checkVatPort?wsdl",
this.class.classLoader)
proxy.initialize()

def checkVat =
proxy.create("eu.europa.ec.taxud.vies.services.checkvat.types.CheckVat")

checkVat.countryCode = "LU"
checkVat.vatNumber = "21405308"

def resp = proxy.checkVat(checkVat);
print resp

The result (resp) is a String ("LU"), not a map, like the wdsl declare....

--
View this message in context: http://old.nabble.com/GroovyWS---Complex-Response-tp25471353p28216041.html


Sent from the groovy - user mailing list archive at Nabble.com.

Francesco Cavola

unread,
Apr 14, 2010, 9:03:24 AM4/14/10
to us...@groovy.codehaus.org

Dennis Bayer

unread,
Apr 15, 2010, 7:05:43 AM4/15/10
to us...@groovy.codehaus.org
Am 14.04.2010 15:03, schrieb Francesco Cavola:
>
> Sorry the url of wdsl is
> http://ec.europa.eu/taxation_customs/vies/services/checkVatService.wsdl

Hi Francesco,
I debugged the given service and cxf returns:
[LU, 21405308, 2010-04-15+02:00, true, null, null]

As I stated below GroovyWS contains a bug returning just the first
element of an array (return response[0];). The solution provided at the
end of the mail should be a workaround for you as long as there ain't no
bugfix.

Nevertheless the return value should be an object rather than an array,
I guess. Perhaps someone on the cxf list can answer this?!


Regards,
Dennis.

tog

unread,
Apr 15, 2010, 8:15:26 AM4/15/10
to us...@groovy.codehaus.org
Hi there
I am working on this, I should provide a fix today, tomorrow at the latest.
Best Regards
Guillaume

--
PGP KeyID: 1024D/69B00854 subkeys.pgp.net

http://cheztog.blogspot.com

Francesco Cavola

unread,
Apr 15, 2010, 8:25:17 AM4/15/10
to us...@groovy.codehaus.org

Thanks to Dennis and Guillaume

--
View this message in context: http://old.nabble.com/GroovyWS---Complex-Response-tp25471353p28254593.html


Sent from the groovy - user mailing list archive at Nabble.com.

Reply all
Reply to author
Forward
0 new messages