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
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
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:
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.
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.
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.
--
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.
-----
___________________________
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.
-----
___________________________
View this message in context: http://old.nabble.com/GroovyWS---Complex-Response-tp25471353p27338206.html
> 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.
Hi Francesco,
I don't get it. Could you post some details?
Regards.
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.
--
View this message in context: http://old.nabble.com/GroovyWS---Complex-Response-tp25471353p28242290.html
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.
--
PGP KeyID: 1024D/69B00854 subkeys.pgp.net
--
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.