jwagenleitner / groovy-wslite

Lightweight SOAP and REST webservice clients for Groovy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting Character reference "&# Exception

facundofarias opened this issue · comments

Hello there.
First of all, we would like to say that we love this library, and we are using it a lot, so many thanks!

Now, the issue we are having is that in some SOAP message, it seems to be some kind of issue with encoding mostly, so we are getting:

Caused by: wslite.soap.SOAPMessageParseException: Character reference "&# Exception
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:202)
    at wslite.soap.SOAPClient.buildSOAPResponse(SOAPClient.groovy:95)
    at wslite.soap.SOAPClient.this$2$buildSOAPResponse(SOAPClient.groovy)
    at wslite.soap.SOAPClient$this$2$buildSOAPResponse$6.callCurrent(Unknown Source)
    at wslite.soap.SOAPClient.send(SOAPClient.groovy:66)
    at cyf.soap.EnhancedSOAPClient.super$2$send(EnhancedSOAPClient.groovy)
    at sun.reflect.GeneratedMethodAccessor545.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1086)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:128)
    at cyf.soap.EnhancedSOAPClient$_send_closure3.doCall(EnhancedSOAPClient.groovy:67)
    at cyf.soap.EnhancedSOAPClient$_send_closure3.doCall(EnhancedSOAPClient.groovy)
    at sun.reflect.GeneratedMethodAccessor543.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:910)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)

I will try to build a test case, so you can understand better what it is happening. That said, is there a way to "escape" the SOAP messages before it is processed by wslite? (Or, perhaps you think a better way to solve this). Just to clarify, the SOAP Message it is from an external provider, and we cannot fix it there.

Thanks!

Is that the full stacktrace? I'd expect to see a longer stack trace with a "caused by" part.

The real exception is likely in the groovy XmlSlurper, and most likely it is because the XML returned by your web service is invalid.

Where you catch the SOAPMessageParseException, add a line logging the text-content of the HTTP response:

} catch (SOAPClient e) {
    println e.response.contentAsString
}

Hi @boekhold, here you have the full stack trace:

Caused by: wslite.soap.SOAPMessageParseException: Character reference "&#
at sun.reflect.GeneratedConstructorAccessor195.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:80)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:271)
at wslite.soap.SOAPClient.buildSOAPResponse(SOAPClient.groovy:95)
at wslite.soap.SOAPClient.this$2$buildSOAPResponse(SOAPClient.groovy)
at sun.reflect.GeneratedMethodAccessor572.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:174)
at wslite.soap.SOAPClient.send(SOAPClient.groovy:66)
at cyf.soap.EnhancedSOAPClient.super$2$send(EnhancedSOAPClient.groovy)
at sun.reflect.GeneratedMethodAccessor517.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:271)
at wslite.soap.SOAPClient.buildSOAPResponse(SOAPClient.groovy:95)
at wslite.soap.SOAPClient.this$2$buildSOAPResponse(SOAPClient.groovy)
at sun.reflect.GeneratedMethodAccessor572.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:174)
at wslite.soap.SOAPClient.send(SOAPClient.groovy:66)
at cyf.soap.EnhancedSOAPClient.super$2$send(EnhancedSOAPClient.groovy)
at sun.reflect.GeneratedMethodAccessor517.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1210)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:132)
at cyf.soap.EnhancedSOAPClient$_send_closure3.doCall(EnhancedSOAPClient.groovy:67)
at cyf.soap.EnhancedSOAPClient$_send_closure3.doCall(EnhancedSOAPClient.groovy)
at sun.reflect.GeneratedMethodAccessor515.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1019)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at cyf.soap.EnhancedSOAPClient.retry(EnhancedSOAPClient.groovy:82)
... 29 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 1156; Character reference "&#
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1239)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at groovy.util.XmlSlurper.parse(XmlSlurper.java:207)
at groovy.util.XmlSlurper.parse(XmlSlurper.java:260)
at groovy.util.XmlSlurper.parseText(XmlSlurper.java:286)
at groovy.util.XmlSlurper$parseText.call(Unknown Source)
at wslite.soap.SOAPClient.parseEnvelope(SOAPClient.groovy:101)
at wslite.soap.SOAPClient.this$2$parseEnvelope(SOAPClient.groovy)
at sun.reflect.GeneratedMethodAccessor574.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
at wslite.soap.SOAPClient.buildSOAPResponse(SOAPClient.groovy:89)
... 57 more

I will add the log line as you said, and will let you know.
Thanks!