Menu

#11 ClassCastException in SoapSerializationEnvelope.getResult

open
nobody
ksoap (16)
5
2015-02-15
2004-10-02
Anonymous
No

When in SoapSerializationEnvelope.bodyIn is stored
SoapFault, after calling
SoapSerializationEnvelope.getResult it throws
ClassCastException:

public Object getResult() {
--HERE--> KvmSerializable ks = (KvmSerializable) bodyIn;
return ks.getPropertyCount() == 0 ? null :
ks.getProperty(0);
}

That's because the SoapFault isn't subclass of
KvmSerializable...

Bye,
Petr
mr_peta@volny.cz

Discussion

  • Simon Vogl

    Simon Vogl - 2005-06-21

    Logged In: YES
    user_id=948541

    Hi guys,
    We stumbled over the same problem -- not only do Faults
    trigger this behavior, also operations that return primitive
    types, like a Boolean.

    Second, the behavior of getResult is suboptimal when an
    array is returned: getResult returns only the first(!) entry.
    May I suggest the following patch:
    public Object getResult() {
    if (bodyIn instanceof KvmSerializable) {
    KvmSerializable ks = (KvmSerializable) bodyIn;
    if (ks.getPropertyCount() == 0) return null;

    ks.getProperty(0)
    }
    }

     
  • Simon Vogl

    Simon Vogl - 2005-06-21

    Logged In: YES
    user_id=948541

    ... sorry - submitted in the midst of writing...
    here|s the complete code:

    public Object getResult() {
    if (bodyIn instanceof KvmSerializable) {
    KvmSerializable ks = (KvmSerializable) bodyIn;
    if (ks.getPropertyCount() == 0) return null;
    return (ks.getPropertyCount() == 1) ks.getProperty(0) : ks;
    } else
    return bodyIn;
    }

     
  • James Seigel

    James Seigel - 2006-02-13

    Logged In: YES
    user_id=1282699

    Thank you sir.. Please keep in touch over at the new home
    for ksoap2 at ksoap2.sourceforge.net or
    sourceforge.net/projects/ksoap2

    Cheers
    James.

     

Log in to post a comment.