Forum Discussion

JHoreczky's avatar
JHoreczky
Contributor
13 years ago

class cast exception mystery in SoapUI Pro 4.5.0

Hello SmartBear support team,

I am trying to cast an object in a Groovy script when the following exception occurs:

Tue Jul 10 23:44:44 MDT 2012:ERROR:org.codehaus.groovy.runtime.typehandling.GroovyCastException


The object to be cast and the from Class type and to Class type are all identical. Why does the exception happen then?


Thanks,

Joseph H.


Below is the full stack trace:

Cannot cast object 'com.aaa.togw.services.loopqual.clientsharedobjects.TogwLoopQualTierRespDto@15651e7'
with class 'com.aaa.togw.services.loopqual.clientsharedobjects.TogwLoopQualTierRespDto'
to class 'com.aaa.togw.services.loopqual.clientsharedobjects.TogwLoopQualTierRespDto'

at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:331)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:599)
at Script31.run(Script31.groovy:17)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:96)
at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SourceFile:89)
at com.eviware.soapui.eventhandlers.support.DefaultSoapUIScript.invoke(SourceFile:47)
at com.eviware.soapui.eventhandlers.support.DefaultSoapUIEventHandler.invoke(SourceFile:29)
at com.eviware.soapui.eventhandlers.support.AbstractEventHandlerMetaData.invokeHandlers(SourceFile:73)
at com.eviware.soapui.eventhandlers.support.AbstractEventHandlerMetaData.invokeHandlers(SourceFile:49)
at com.eviware.soapui.eventhandlers.impl.EventHandlersRequestFilter.afterRequest(SourceFile:28)
at com.eviware.soapui.impl.wsdl.submit.transports.http.HttpClientRequestTransport.sendRequest(HttpClientRequestTransport.java:307)
at com.eviware.soapui.impl.wsdl.WsdlSubmit.run(WsdlSubmit.java:123)

3 Replies

  • if( context.httpResponse.responseContent == null ) {
    log.info "returning on null"
    return
    }

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def classpathHacker = new com.eviware.soapui.support.ClasspathHacker ()
    def path = groovyUtils.getProjectPath()
    def myfile = new java.io.File(path + "/LoopQualification-1.0.6.jar")
    classpathHacker.addFile( myfile )
    import com.aaa.togw.services.loopqual.clientsharedobjects.TogwLoopQualTierRespDto;

    // bytes starting at magic number make up the object in rawResponseData
    def magicNumber = 171
    def len = context.httpResponse.rawResponseData.size()
    def byte[] ba = context.httpResponse.rawResponseData[magicNumber..(len-1)]

    def ByteArrayInputStream bis = new ByteArrayInputStream(ba);
    def ObjectInputStream ois = new ObjectInputStream(bis)

    /// the following line is causing the class cast exception
    def TogwLoopQualTierRespDto dtoObj = (TogwLoopQualTierRespDto)ois.readObject();
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    hmm.. perhaps they were loaded by different classloaders!? try putting your extension library in the soapui\lib folder instead of bin\ext - does that make a difference?

    regards,

    /Ole
    SmartBear Software
  • Yes. It was a class loading issue. Thanks for the hint, it's working now!